@@ -127,24 +127,17 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
127127
128128 repo .IsEmpty = false
129129
130- // Don't bother looking this repo in the context it won't be there
131- gitRepo , err := gitrepo .OpenRepository (ctx , repo )
132- if err != nil {
133- return fmt .Errorf ("openRepository: %w" , err )
134- }
135- defer gitRepo .Close ()
136-
137130 if len (defaultBranch ) > 0 {
138131 repo .DefaultBranch = defaultBranch
139132
140- if err = gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
133+ if err = gitrepo .SetDefaultBranch (ctx , repo , repo .DefaultBranch ); err != nil {
141134 return fmt .Errorf ("setDefaultBranch: %w" , err )
142135 }
143136 } else {
144- repo .DefaultBranch , err = gitRepo .GetDefaultBranch ()
137+ repo .DefaultBranch , err = gitrepo .GetDefaultBranch (ctx , repo )
145138 if err != nil {
146139 repo .DefaultBranch = setting .Repository .DefaultBranch
147- if err = gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
140+ if err = gitrepo .SetDefaultBranch (ctx , repo , repo .DefaultBranch ); err != nil {
148141 return fmt .Errorf ("setDefaultBranch: %w" , err )
149142 }
150143 }
@@ -188,7 +181,7 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
188181 repo .DefaultBranch = setting .Repository .DefaultBranch
189182 }
190183
191- if err = gitRepo .SetDefaultBranch (repo .DefaultBranch ); err != nil {
184+ if err = gitrepo .SetDefaultBranch (ctx , repo , repo .DefaultBranch ); err != nil {
192185 return fmt .Errorf ("setDefaultBranch: %w" , err )
193186 }
194187 }
@@ -197,6 +190,13 @@ func adoptRepository(ctx context.Context, repoPath string, u *user_model.User, r
197190 return fmt .Errorf ("updateRepository: %w" , err )
198191 }
199192
193+ // Don't bother looking this repo in the context it won't be there
194+ gitRepo , err := gitrepo .OpenRepository (ctx , repo )
195+ if err != nil {
196+ return fmt .Errorf ("openRepository: %w" , err )
197+ }
198+ defer gitRepo .Close ()
199+
200200 if err = repo_module .SyncReleasesWithTags (ctx , repo , gitRepo ); err != nil {
201201 return fmt .Errorf ("SyncReleasesWithTags: %w" , err )
202202 }
0 commit comments