mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Remove local clones & make hooks run on merge/edit/upload (#6672)
* Add options to git.Clone to make it more capable * Begin the process of removing the local copy and tidy up * Remove Wiki LocalCopy Checkouts * Remove the last LocalRepo helpers * Remove WithTemporaryFile * Enable push-hooks for these routes * Ensure tests cope with hooks Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove Repository.LocalCopyPath() * Move temporary repo to use the standard temporary path * Fix the tests Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove LocalWikiPath * Fix missing remove Signed-off-by: Andrew Thornton <art27@cantab.net> * Use AppURL for Oauth user link (#6894) * Use AppURL for Oauth user link Fix #6843 * Update oauth.go * Update oauth.go * internal/ssh: ignore env command totally (#6825) * ssh: ignore env command totally * Remove commented code Needed fix described in issue #6889 * Escape the commit message on issues update and title in telegram hook (#6901) * update sdk to latest (#6903) * improve description of branch protection (fix #6886) (#6906) The branch protection description text were not quite accurate. * Fix logging documentation (#6904) * ENABLE_MACARON_REDIRECT should be REDIRECT_MACARON_LOG * Allow DISABLE_ROUTER_LOG to be set in the [log] section * [skip ci] Updated translations via Crowdin * Move sdk structs to modules/structs (#6905) * move sdk structs to moduels/structs * fix tests * fix fmt * fix swagger * fix vendor
This commit is contained in:
parent
34eee25bd4
commit
ce8de35334
33 changed files with 1652 additions and 1417 deletions
|
@ -518,7 +518,7 @@ func (repo *Repository) DeleteWiki() error {
|
|||
}
|
||||
|
||||
func (repo *Repository) deleteWiki(e Engine) error {
|
||||
wikiPaths := []string{repo.WikiPath(), repo.LocalWikiPath()}
|
||||
wikiPaths := []string{repo.WikiPath()}
|
||||
for _, wikiPath := range wikiPaths {
|
||||
removeAllWithNotice(e, "Delete repository wiki", wikiPath)
|
||||
}
|
||||
|
@ -749,56 +749,6 @@ func (repo *Repository) DescriptionHTML() template.HTML {
|
|||
return template.HTML(markup.Sanitize(string(desc)))
|
||||
}
|
||||
|
||||
// LocalCopyPath returns the local repository copy path.
|
||||
func LocalCopyPath() string {
|
||||
if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
|
||||
return setting.Repository.Local.LocalCopyPath
|
||||
}
|
||||
return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath)
|
||||
}
|
||||
|
||||
// LocalCopyPath returns the local repository copy path for the given repo.
|
||||
func (repo *Repository) LocalCopyPath() string {
|
||||
return path.Join(LocalCopyPath(), com.ToStr(repo.ID))
|
||||
}
|
||||
|
||||
// UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.
|
||||
// It creates a new clone if local copy does not exist.
|
||||
// This function checks out target branch by default, it is safe to assume subsequent
|
||||
// operations are operating against target branch when caller has confidence for no race condition.
|
||||
func UpdateLocalCopyBranch(repoPath, localPath, branch string) error {
|
||||
if !com.IsExist(localPath) {
|
||||
if err := git.Clone(repoPath, localPath, git.CloneRepoOptions{
|
||||
Timeout: time.Duration(setting.Git.Timeout.Clone) * time.Second,
|
||||
Branch: branch,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("git clone %s: %v", branch, err)
|
||||
}
|
||||
} else {
|
||||
_, err := git.NewCommand("fetch", "origin").RunInDir(localPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git fetch origin: %v", err)
|
||||
}
|
||||
if len(branch) > 0 {
|
||||
if err := git.Checkout(localPath, git.CheckoutOptions{
|
||||
Branch: branch,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("git checkout %s: %v", branch, err)
|
||||
}
|
||||
|
||||
if err := git.ResetHEAD(localPath, true, "origin/"+branch); err != nil {
|
||||
return fmt.Errorf("git reset --hard origin/%s: %v", branch, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// UpdateLocalCopyBranch makes sure local copy of repository in given branch is up-to-date.
|
||||
func (repo *Repository) UpdateLocalCopyBranch(branch string) error {
|
||||
return UpdateLocalCopyBranch(repo.RepoPath(), repo.LocalCopyPath(), branch)
|
||||
}
|
||||
|
||||
// PatchPath returns corresponding patch file path of repository by given issue ID.
|
||||
func (repo *Repository) PatchPath(index int64) (string, error) {
|
||||
return repo.patchPath(x, index)
|
||||
|
@ -1583,12 +1533,10 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
|
|||
if err = os.Rename(RepoPath(owner.Name, repo.Name), RepoPath(newOwner.Name, repo.Name)); err != nil {
|
||||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
}
|
||||
removeAllWithNotice(sess, "Delete repository local copy", repo.LocalCopyPath())
|
||||
|
||||
// Rename remote wiki repository to new path and delete local copy.
|
||||
wikiPath := WikiPath(owner.Name, repo.Name)
|
||||
if com.IsExist(wikiPath) {
|
||||
removeAllWithNotice(sess, "Delete repository wiki local copy", repo.LocalWikiPath())
|
||||
if err = os.Rename(wikiPath, WikiPath(newOwner.Name, repo.Name)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
}
|
||||
|
@ -1633,20 +1581,11 @@ func ChangeRepositoryName(u *User, oldRepoName, newRepoName string) (err error)
|
|||
return fmt.Errorf("rename repository directory: %v", err)
|
||||
}
|
||||
|
||||
localPath := repo.LocalCopyPath()
|
||||
if com.IsExist(localPath) {
|
||||
_, err := git.NewCommand("remote", "set-url", "origin", newRepoPath).RunInDir(localPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("git remote set-url origin %s: %v", newRepoPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
wikiPath := repo.WikiPath()
|
||||
if com.IsExist(wikiPath) {
|
||||
if err = os.Rename(wikiPath, WikiPath(u.Name, newRepoName)); err != nil {
|
||||
return fmt.Errorf("rename repository wiki: %v", err)
|
||||
}
|
||||
RemoveAllWithNotice("Delete repository wiki local copy", repo.LocalWikiPath())
|
||||
}
|
||||
|
||||
sess := x.NewSession()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue