@@ -25,6 +25,54 @@ import (
25
25
"code.gitea.io/gitea/modules/util"
26
26
)
27
27
28
+ func cloneWiki (ctx context.Context , u * user_model.User , opts migration.MigrateOptions , migrateTimeout time.Duration ) (string , error ) {
29
+ wikiPath := repo_model .WikiPath (u .Name , opts .RepoName )
30
+ wikiRemotePath := repo_module .WikiRemoteURL (ctx , opts .CloneAddr )
31
+ if wikiRemotePath == "" {
32
+ return "" , nil
33
+ }
34
+
35
+ if err := util .RemoveAll (wikiPath ); err != nil {
36
+ return "" , fmt .Errorf ("failed to remove existingi wiki dir %q, err: %w" , wikiPath , err )
37
+ }
38
+
39
+ cleanIncompleteWikiPath := func () {
40
+ if err := util .RemoveAll (wikiPath ); err != nil {
41
+ log .Error ("Failed to remove incomplete wiki dir %q, err: %v" , wikiPath , err )
42
+ }
43
+ }
44
+ if err := git .Clone (ctx , wikiRemotePath , wikiPath , git.CloneRepoOptions {
45
+ Mirror : true ,
46
+ Quiet : true ,
47
+ Timeout : migrateTimeout ,
48
+ SkipTLSVerify : setting .Migrations .SkipTLSVerify ,
49
+ }); err != nil {
50
+ log .Error ("Clone wiki failed, err: %v" , err )
51
+ cleanIncompleteWikiPath ()
52
+ return "" , err
53
+ }
54
+
55
+ if err := git .WriteCommitGraph (ctx , wikiPath ); err != nil {
56
+ cleanIncompleteWikiPath ()
57
+ return "" , err
58
+ }
59
+
60
+ wikiRepo , err := git .OpenRepository (ctx , wikiPath )
61
+ if err != nil {
62
+ cleanIncompleteWikiPath ()
63
+ return "" , fmt .Errorf ("failed to open wiki repo %q, err: %w" , wikiPath , err )
64
+ }
65
+ defer wikiRepo .Close ()
66
+
67
+ defaultBranch , err := wikiRepo .GetDefaultBranch ()
68
+ if err != nil {
69
+ cleanIncompleteWikiPath ()
70
+ return "" , fmt .Errorf ("failed to get wiki repo defaul brach for %q, err: %w" , wikiPath , err )
71
+ }
72
+
73
+ return defaultBranch , nil
74
+ }
75
+
28
76
// MigrateRepositoryGitData starts migrating git related data after created migrating repository
29
77
func MigrateRepositoryGitData (ctx context.Context , u * user_model.User ,
30
78
repo * repo_model.Repository , opts migration.MigrateOptions ,
@@ -44,59 +92,39 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
44
92
45
93
migrateTimeout := time .Duration (setting .Git .Timeout .Migrate ) * time .Second
46
94
47
- var err error
48
- if err = util .RemoveAll (repoPath ); err != nil {
49
- return repo , fmt .Errorf ("Failed to remove %s: %w" , repoPath , err )
95
+ if err := util .RemoveAll (repoPath ); err != nil {
96
+ return repo , fmt .Errorf ("failed to remove existing repo dir %q, err: %w" , repoPath , err )
50
97
}
51
98
52
- if err = git .Clone (ctx , opts .CloneAddr , repoPath , git.CloneRepoOptions {
99
+ if err : = git .Clone (ctx , opts .CloneAddr , repoPath , git.CloneRepoOptions {
53
100
Mirror : true ,
54
101
Quiet : true ,
55
102
Timeout : migrateTimeout ,
56
103
SkipTLSVerify : setting .Migrations .SkipTLSVerify ,
57
104
}); err != nil {
58
105
if errors .Is (err , context .DeadlineExceeded ) {
59
- return repo , fmt .Errorf ("Clone timed out. Consider increasing [git.timeout] MIGRATE in app.ini. Underlying Error : %w" , err )
106
+ return repo , fmt .Errorf ("clone timed out, consider increasing [git.timeout] MIGRATE in app.ini, underlying err : %w" , err )
60
107
}
61
- return repo , fmt .Errorf ("Clone : %w" , err )
108
+ return repo , fmt .Errorf ("clone error : %w" , err )
62
109
}
63
110
64
111
if err := git .WriteCommitGraph (ctx , repoPath ); err != nil {
65
112
return repo , err
66
113
}
67
114
68
115
if opts .Wiki {
69
- wikiPath := repo_model .WikiPath (u .Name , opts .RepoName )
70
- wikiRemotePath := repo_module .WikiRemoteURL (ctx , opts .CloneAddr )
71
- if len (wikiRemotePath ) > 0 {
72
- if err := util .RemoveAll (wikiPath ); err != nil {
73
- return repo , fmt .Errorf ("Failed to remove %s: %w" , wikiPath , err )
74
- }
75
-
76
- if err := git .Clone (ctx , wikiRemotePath , wikiPath , git.CloneRepoOptions {
77
- Mirror : true ,
78
- Quiet : true ,
79
- Timeout : migrateTimeout ,
80
- Branch : "master" ,
81
- SkipTLSVerify : setting .Migrations .SkipTLSVerify ,
82
- }); err != nil {
83
- log .Warn ("Clone wiki: %v" , err )
84
- if err := util .RemoveAll (wikiPath ); err != nil {
85
- return repo , fmt .Errorf ("Failed to remove %s: %w" , wikiPath , err )
86
- }
87
- } else {
88
- if err := git .WriteCommitGraph (ctx , wikiPath ); err != nil {
89
- return repo , err
90
- }
91
- }
116
+ if defaultWikiBranch , err := cloneWiki (ctx , u , opts , migrateTimeout ); err != nil {
117
+ return repo , fmt .Errorf ("clone wiki error: %w" , err )
118
+ } else {
119
+ repo .DefaultWikiBranch = defaultWikiBranch
92
120
}
93
121
}
94
122
95
123
if repo .OwnerID == u .ID {
96
124
repo .Owner = u
97
125
}
98
126
99
- if err = repo_module .CheckDaemonExportOK (ctx , repo ); err != nil {
127
+ if err : = repo_module .CheckDaemonExportOK (ctx , repo ); err != nil {
100
128
return repo , fmt .Errorf ("checkDaemonExportOK: %w" , err )
101
129
}
102
130
0 commit comments