@@ -36,10 +36,6 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
36
36
}
37
37
}
38
38
39
- if len (opts .DefaultBranch ) == 0 {
40
- opts .DefaultBranch = setting .Repository .DefaultBranch
41
- }
42
-
43
39
repo := & repo_model.Repository {
44
40
OwnerID : u .ID ,
45
41
Owner : u ,
@@ -80,8 +76,8 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
80
76
return fmt .Errorf ("getRepositoryByID: %w" , err )
81
77
}
82
78
83
- if err := adoptRepository (ctx , repoPath , doer , repo , opts .DefaultBranch ); err != nil {
84
- return fmt .Errorf ("createDelegateHooks : %w" , err )
79
+ if err := adoptRepository (ctx , repoPath , repo , opts .DefaultBranch ); err != nil {
80
+ return fmt .Errorf ("adoptRepository : %w" , err )
85
81
}
86
82
87
83
if err := repo_module .CheckDaemonExportOK (ctx , repo ); err != nil {
@@ -111,7 +107,7 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
111
107
return repo , nil
112
108
}
113
109
114
- func adoptRepository (ctx context.Context , repoPath string , u * user_model. User , repo * repo_model.Repository , defaultBranch string ) (err error ) {
110
+ func adoptRepository (ctx context.Context , repoPath string , repo * repo_model.Repository , defaultBranch string ) (err error ) {
115
111
isExist , err := util .IsExist (repoPath )
116
112
if err != nil {
117
113
log .Error ("Unable to check if %s exists. Error: %v" , repoPath , err )
@@ -143,6 +139,21 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
143
139
}
144
140
}
145
141
142
+ // Don't bother looking this repo in the context it won't be there
143
+ gitRepo , err := gitrepo .OpenRepository (ctx , repo )
144
+ if err != nil {
145
+ return fmt .Errorf ("openRepository: %w" , err )
146
+ }
147
+ defer gitRepo .Close ()
148
+
149
+ if _ , err = repo_module .SyncRepoBranchesWithRepo (ctx , repo , gitRepo , 0 ); err != nil {
150
+ return fmt .Errorf ("SyncRepoBranchesWithRepo: %w" , err )
151
+ }
152
+
153
+ if err = repo_module .SyncReleasesWithTags (ctx , repo , gitRepo ); err != nil {
154
+ return fmt .Errorf ("SyncReleasesWithTags: %w" , err )
155
+ }
156
+
146
157
branches , _ := git_model .FindBranchNames (ctx , git_model.FindBranchOptions {
147
158
RepoID : repo .ID ,
148
159
ListOptions : db .ListOptionsAll ,
@@ -183,26 +194,10 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
183
194
return fmt .Errorf ("setDefaultBranch: %w" , err )
184
195
}
185
196
}
186
-
187
197
if err = repo_module .UpdateRepository (ctx , repo , false ); err != nil {
188
198
return fmt .Errorf ("updateRepository: %w" , err )
189
199
}
190
200
191
- // Don't bother looking this repo in the context it won't be there
192
- gitRepo , err := gitrepo .OpenRepository (ctx , repo )
193
- if err != nil {
194
- return fmt .Errorf ("openRepository: %w" , err )
195
- }
196
- defer gitRepo .Close ()
197
-
198
- if _ , err = repo_module .SyncRepoBranchesWithRepo (ctx , repo , gitRepo , 0 ); err != nil {
199
- return fmt .Errorf ("SyncRepoBranches: %w" , err )
200
- }
201
-
202
- if err = repo_module .SyncReleasesWithTags (ctx , repo , gitRepo ); err != nil {
203
- return fmt .Errorf ("SyncReleasesWithTags: %w" , err )
204
- }
205
-
206
201
return nil
207
202
}
208
203
0 commit comments