@@ -184,33 +184,37 @@ func (c *CheckoutBranch) Checkout(ctx context.Context, path, url string, opts *g
184
184
185
185
return buildCommit (cc , "refs/heads/" + c .Branch ), nil
186
186
} else {
187
- repo , err := git2go .Clone (url , path , & git2go.CloneOptions {
188
- FetchOptions : git2go.FetchOptions {
189
- DownloadTags : git2go .DownloadTagsNone ,
190
- RemoteCallbacks : RemoteCallbacks (ctx , opts ),
191
- ProxyOptions : git2go.ProxyOptions {Type : git2go .ProxyTypeAuto },
192
- },
193
- CheckoutOptions : git2go.CheckoutOptions {
194
- Strategy : git2go .CheckoutForce ,
195
- },
196
- CheckoutBranch : c .Branch ,
197
- })
198
- if err != nil {
199
- return nil , fmt .Errorf ("unable to clone '%s': %w" , managed .EffectiveURL (url ), gitutil .LibGit2Error (err ))
200
- }
201
- defer repo .Free ()
202
- head , err := repo .Head ()
203
- if err != nil {
204
- return nil , fmt .Errorf ("git resolve HEAD error: %w" , err )
205
- }
206
- defer head .Free ()
207
- cc , err := repo .LookupCommit (head .Target ())
208
- if err != nil {
209
- return nil , fmt .Errorf ("failed to lookup HEAD commit '%s' for branch '%s': %w" , head .Target (), c .Branch , err )
210
- }
211
- defer cc .Free ()
212
- return buildCommit (cc , "refs/heads/" + c .Branch ), nil
187
+ return c .checkoutUnmanaged (ctx , path , url , opts )
188
+ }
189
+ }
190
+
191
+ func (c * CheckoutBranch ) checkoutUnmanaged (ctx context.Context , path , url string , opts * git.AuthOptions ) (_ * git.Commit , err error ) {
192
+ repo , err := git2go .Clone (url , path , & git2go.CloneOptions {
193
+ FetchOptions : git2go.FetchOptions {
194
+ DownloadTags : git2go .DownloadTagsNone ,
195
+ RemoteCallbacks : RemoteCallbacks (ctx , opts ),
196
+ ProxyOptions : git2go.ProxyOptions {Type : git2go .ProxyTypeAuto },
197
+ },
198
+ CheckoutOptions : git2go.CheckoutOptions {
199
+ Strategy : git2go .CheckoutForce ,
200
+ },
201
+ CheckoutBranch : c .Branch ,
202
+ })
203
+ if err != nil {
204
+ return nil , fmt .Errorf ("unable to clone '%s': %w" , managed .EffectiveURL (url ), gitutil .LibGit2Error (err ))
205
+ }
206
+ defer repo .Free ()
207
+ head , err := repo .Head ()
208
+ if err != nil {
209
+ return nil , fmt .Errorf ("git resolve HEAD error: %w" , err )
210
+ }
211
+ defer head .Free ()
212
+ cc , err := repo .LookupCommit (head .Target ())
213
+ if err != nil {
214
+ return nil , fmt .Errorf ("failed to lookup HEAD commit '%s' for branch '%s': %w" , head .Target (), c .Branch , err )
213
215
}
216
+ defer cc .Free ()
217
+ return buildCommit (cc , "refs/heads/" + c .Branch ), nil
214
218
}
215
219
216
220
type CheckoutTag struct {
@@ -305,26 +309,30 @@ func (c *CheckoutTag) Checkout(ctx context.Context, path, url string, opts *git.
305
309
defer cc .Free ()
306
310
return buildCommit (cc , "refs/tags/" + c .Tag ), nil
307
311
} else {
308
- repo , err := git2go .Clone (url , path , & git2go.CloneOptions {
309
- FetchOptions : git2go.FetchOptions {
310
- DownloadTags : git2go .DownloadTagsAll ,
311
- RemoteCallbacks : RemoteCallbacks (ctx , opts ),
312
- ProxyOptions : git2go.ProxyOptions {Type : git2go .ProxyTypeAuto },
313
- },
314
- })
315
- if err != nil {
316
- return nil , fmt .Errorf ("unable to clone '%s': %w" , managed .EffectiveURL (url ), gitutil .LibGit2Error (err ))
317
- }
318
- defer repo .Free ()
319
- cc , err := checkoutDetachedDwim (repo , c .Tag )
320
- if err != nil {
321
- return nil , err
322
- }
323
- defer cc .Free ()
324
- return buildCommit (cc , "refs/tags/" + c .Tag ), nil
312
+ return c .checkoutUnmanaged (ctx , path , url , opts )
325
313
}
326
314
}
327
315
316
+ func (c * CheckoutTag ) checkoutUnmanaged (ctx context.Context , path , url string , opts * git.AuthOptions ) (_ * git.Commit , err error ) {
317
+ repo , err := git2go .Clone (url , path , & git2go.CloneOptions {
318
+ FetchOptions : git2go.FetchOptions {
319
+ DownloadTags : git2go .DownloadTagsAll ,
320
+ RemoteCallbacks : RemoteCallbacks (ctx , opts ),
321
+ ProxyOptions : git2go.ProxyOptions {Type : git2go .ProxyTypeAuto },
322
+ },
323
+ })
324
+ if err != nil {
325
+ return nil , fmt .Errorf ("unable to clone '%s': %w" , managed .EffectiveURL (url ), gitutil .LibGit2Error (err ))
326
+ }
327
+ defer repo .Free ()
328
+ cc , err := checkoutDetachedDwim (repo , c .Tag )
329
+ if err != nil {
330
+ return nil , err
331
+ }
332
+ defer cc .Free ()
333
+ return buildCommit (cc , "refs/tags/" + c .Tag ), nil
334
+ }
335
+
328
336
type CheckoutCommit struct {
329
337
Commit string
330
338
}
0 commit comments