forked from p85947160/gitea
Update the wiki repository remote origin while update the mirror repository's Clone From URL (#12053)
* update the wiki repository remote origin #12050 * wikiRemoteURL is under repo_module * export WikiRemoteURL func * remove redundant space and empty line Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
c5b08f6d5a
commit
9fc9c1de98
|
@ -27,9 +27,9 @@ import (
|
||||||
*/
|
*/
|
||||||
var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
|
var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
|
||||||
|
|
||||||
// wikiRemoteURL returns accessible repository URL for wiki if exists.
|
// WikiRemoteURL returns accessible repository URL for wiki if exists.
|
||||||
// Otherwise, it returns an empty string.
|
// Otherwise, it returns an empty string.
|
||||||
func wikiRemoteURL(remote string) string {
|
func WikiRemoteURL(remote string) string {
|
||||||
remote = strings.TrimSuffix(remote, ".git")
|
remote = strings.TrimSuffix(remote, ".git")
|
||||||
for _, suffix := range commonWikiURLSuffixes {
|
for _, suffix := range commonWikiURLSuffixes {
|
||||||
wikiURL := remote + suffix
|
wikiURL := remote + suffix
|
||||||
|
@ -71,7 +71,7 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
|
||||||
|
|
||||||
if opts.Wiki {
|
if opts.Wiki {
|
||||||
wikiPath := models.WikiPath(u.Name, opts.RepoName)
|
wikiPath := models.WikiPath(u.Name, opts.RepoName)
|
||||||
wikiRemotePath := wikiRemoteURL(opts.CloneAddr)
|
wikiRemotePath := WikiRemoteURL(opts.CloneAddr)
|
||||||
if len(wikiRemotePath) > 0 {
|
if len(wikiRemotePath) > 0 {
|
||||||
if err := os.RemoveAll(wikiPath); err != nil {
|
if err := os.RemoveAll(wikiPath); err != nil {
|
||||||
return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
|
return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)
|
||||||
|
|
|
@ -100,7 +100,25 @@ func SaveAddress(m *models.Mirror, addr string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath)
|
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
|
||||||
return err
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if m.Repo.HasWiki() {
|
||||||
|
wikiPath := m.Repo.WikiPath()
|
||||||
|
wikiRemotePath := repo_module.WikiRemoteURL(addr)
|
||||||
|
// Remove old origin of wiki
|
||||||
|
_, err := git.NewCommand("remote", "rm", "origin").RunInDir(wikiPath)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", wikiRemotePath).RunInDir(wikiPath)
|
||||||
|
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// gitShortEmptySha Git short empty SHA
|
// gitShortEmptySha Git short empty SHA
|
||||||
|
|
Loading…
Reference in New Issue