Skip to content

Commit 9fc9c1d

Browse files
yisilianglafrikstechknowlogick
authored
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>
1 parent c5b08f6 commit 9fc9c1d

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

modules/repository/repo.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
*/
2828
var commonWikiURLSuffixes = []string{".wiki.git", ".git/wiki"}
2929

30-
// wikiRemoteURL returns accessible repository URL for wiki if exists.
30+
// WikiRemoteURL returns accessible repository URL for wiki if exists.
3131
// Otherwise, it returns an empty string.
32-
func wikiRemoteURL(remote string) string {
32+
func WikiRemoteURL(remote string) string {
3333
remote = strings.TrimSuffix(remote, ".git")
3434
for _, suffix := range commonWikiURLSuffixes {
3535
wikiURL := remote + suffix
@@ -71,7 +71,7 @@ func MigrateRepositoryGitData(doer, u *models.User, repo *models.Repository, opt
7171

7272
if opts.Wiki {
7373
wikiPath := models.WikiPath(u.Name, opts.RepoName)
74-
wikiRemotePath := wikiRemoteURL(opts.CloneAddr)
74+
wikiRemotePath := WikiRemoteURL(opts.CloneAddr)
7575
if len(wikiRemotePath) > 0 {
7676
if err := os.RemoveAll(wikiPath); err != nil {
7777
return repo, fmt.Errorf("Failed to remove %s: %v", wikiPath, err)

services/mirror/mirror.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,25 @@ func SaveAddress(m *models.Mirror, addr string) error {
100100
}
101101

102102
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", addr).RunInDir(repoPath)
103-
return err
103+
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
104+
return err
105+
}
106+
107+
if m.Repo.HasWiki() {
108+
wikiPath := m.Repo.WikiPath()
109+
wikiRemotePath := repo_module.WikiRemoteURL(addr)
110+
// Remove old origin of wiki
111+
_, err := git.NewCommand("remote", "rm", "origin").RunInDir(wikiPath)
112+
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
113+
return err
114+
}
115+
116+
_, err = git.NewCommand("remote", "add", "origin", "--mirror=fetch", wikiRemotePath).RunInDir(wikiPath)
117+
if err != nil && !strings.HasPrefix(err.Error(), "exit status 128 - fatal: No such remote ") {
118+
return err
119+
}
120+
}
121+
return nil
104122
}
105123

106124
// gitShortEmptySha Git short empty SHA

0 commit comments

Comments
 (0)