@@ -241,13 +241,6 @@ func (r *gitRepo) findRef(hash string) (ref string, ok bool) {
241
241
return "" , false
242
242
}
243
243
244
- func unshallow (gitDir string ) []string {
245
- if _ , err := os .Stat (filepath .Join (gitDir , "shallow" )); err == nil {
246
- return []string {"--unshallow" }
247
- }
248
- return []string {}
249
- }
250
-
251
244
// minHashDigits is the minimum number of digits to require
252
245
// before accepting a hex digit sequence as potentially identifying
253
246
// a specific commit in a git repo. (Of course, users can always
@@ -397,29 +390,27 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
397
390
// fetchRefsLocked requires that r.mu remain locked for the duration of the call.
398
391
func (r * gitRepo ) fetchRefsLocked () error {
399
392
if r .fetchLevel < fetchAll {
400
- if err := r .fetchUnshallow ("refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
393
+ // NOTE: To work around a bug affecting Git clients up to at least 2.23.0
394
+ // (2019-08-16), we must first expand the set of local refs, and only then
395
+ // unshallow the repository as a separate fetch operation. (See
396
+ // golang.org/issue/34266 and
397
+ // https://github.com/git/git/blob/4c86140027f4a0d2caaa3ab4bd8bfc5ce3c11c8a/transport.c#L1303-L1309.)
398
+
399
+ if _ , err := Run (r .dir , "git" , "fetch" , "-f" , r .remote , "refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
401
400
return err
402
401
}
402
+
403
+ if _ , err := os .Stat (filepath .Join (r .dir , "shallow" )); err == nil {
404
+ if _ , err := Run (r .dir , "git" , "fetch" , "--unshallow" , "-f" , r .remote ); err != nil {
405
+ return err
406
+ }
407
+ }
408
+
403
409
r .fetchLevel = fetchAll
404
410
}
405
411
return nil
406
412
}
407
413
408
- func (r * gitRepo ) fetchUnshallow (refSpecs ... string ) error {
409
- // To work around a protocol version 2 bug that breaks --unshallow,
410
- // add -c protocol.version=0.
411
- // TODO(rsc): The bug is believed to be server-side, meaning only
412
- // on Google's Git servers. Once the servers are fixed, drop the
413
- // protocol.version=0. See Google-internal bug b/110495752.
414
- var protoFlag []string
415
- unshallowFlag := unshallow (r .dir )
416
- if len (unshallowFlag ) > 0 {
417
- protoFlag = []string {"-c" , "protocol.version=0" }
418
- }
419
- _ , err := Run (r .dir , "git" , protoFlag , "fetch" , unshallowFlag , "-f" , r .remote , refSpecs )
420
- return err
421
- }
422
-
423
414
// statLocal returns a RevInfo describing rev in the local git repository.
424
415
// It uses version as info.Version.
425
416
func (r * gitRepo ) statLocal (version , rev string ) (* RevInfo , error ) {
@@ -539,39 +530,10 @@ func (r *gitRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[s
539
530
}
540
531
defer unlock ()
541
532
542
- var refs []string
543
- var protoFlag []string
544
- var unshallowFlag []string
545
- for _ , tag := range redo {
546
- refs = append (refs , "refs/tags/" + tag + ":refs/tags/" + tag )
547
- }
548
- if len (refs ) > 1 {
549
- unshallowFlag = unshallow (r .dir )
550
- if len (unshallowFlag ) > 0 {
551
- // To work around a protocol version 2 bug that breaks --unshallow,
552
- // add -c protocol.version=0.
553
- // TODO(rsc): The bug is believed to be server-side, meaning only
554
- // on Google's Git servers. Once the servers are fixed, drop the
555
- // protocol.version=0. See Google-internal bug b/110495752.
556
- protoFlag = []string {"-c" , "protocol.version=0" }
557
- }
558
- }
559
- if _ , err := Run (r .dir , "git" , protoFlag , "fetch" , unshallowFlag , "-f" , r .remote , refs ); err != nil {
533
+ if err := r .fetchRefsLocked (); err != nil {
560
534
return nil , err
561
535
}
562
536
563
- // TODO(bcmills): after the 1.11 freeze, replace the block above with:
564
- // if r.fetchLevel <= fetchSome {
565
- // r.fetchLevel = fetchSome
566
- // var refs []string
567
- // for _, tag := range redo {
568
- // refs = append(refs, "refs/tags/"+tag+":refs/tags/"+tag)
569
- // }
570
- // if _, err := Run(r.dir, "git", "fetch", "--update-shallow", "-f", r.remote, refs); err != nil {
571
- // return nil, err
572
- // }
573
- // }
574
-
575
537
if _ , err := r .readFileRevs (redo , file , files ); err != nil {
576
538
return nil , err
577
539
}
0 commit comments