@@ -36,10 +36,6 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
3636 }
3737 }
3838
39- if len (opts .DefaultBranch ) == 0 {
40- opts .DefaultBranch = setting .Repository .DefaultBranch
41- }
42-
4339 repo := & repo_model.Repository {
4440 OwnerID : u .ID ,
4541 Owner : u ,
@@ -80,8 +76,8 @@ func AdoptRepository(ctx context.Context, doer, u *user_model.User, opts CreateR
8076 return fmt .Errorf ("getRepositoryByID: %w" , err )
8177 }
8278
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 )
8581 }
8682
8783 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
111107 return repo , nil
112108}
113109
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 ) {
115111 isExist , err := util .IsExist (repoPath )
116112 if err != nil {
117113 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
143139 }
144140 }
145141
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+
146157 branches , _ := git_model .FindBranchNames (ctx , git_model.FindBranchOptions {
147158 RepoID : repo .ID ,
148159 ListOptions : db .ListOptionsAll ,
@@ -183,26 +194,10 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
183194 return fmt .Errorf ("setDefaultBranch: %w" , err )
184195 }
185196 }
186-
187197 if err = repo_module .UpdateRepository (ctx , repo , false ); err != nil {
188198 return fmt .Errorf ("updateRepository: %w" , err )
189199 }
190200
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-
206201 return nil
207202}
208203
0 commit comments