@@ -265,13 +265,6 @@ func (r *gitRepo) findRef(hash string) (ref string, ok bool) {
265
265
return "" , false
266
266
}
267
267
268
- func unshallow (gitDir string ) []string {
269
- if _ , err := os .Stat (filepath .Join (gitDir , "shallow" )); err == nil {
270
- return []string {"--unshallow" }
271
- }
272
- return []string {}
273
- }
274
-
275
268
// minHashDigits is the minimum number of digits to require
276
269
// before accepting a hex digit sequence as potentially identifying
277
270
// a specific commit in a git repo. (Of course, users can always
@@ -421,29 +414,27 @@ func (r *gitRepo) stat(rev string) (*RevInfo, error) {
421
414
// fetchRefsLocked requires that r.mu remain locked for the duration of the call.
422
415
func (r * gitRepo ) fetchRefsLocked () error {
423
416
if r .fetchLevel < fetchAll {
424
- if err := r .fetchUnshallow ("refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
417
+ // NOTE: To work around a bug affecting Git clients up to at least 2.23.0
418
+ // (2019-08-16), we must first expand the set of local refs, and only then
419
+ // unshallow the repository as a separate fetch operation. (See
420
+ // golang.org/issue/34266 and
421
+ // https://github.com/git/git/blob/4c86140027f4a0d2caaa3ab4bd8bfc5ce3c11c8a/transport.c#L1303-L1309.)
422
+
423
+ if _ , err := Run (r .dir , "git" , "fetch" , "-f" , r .remote , "refs/heads/*:refs/heads/*" , "refs/tags/*:refs/tags/*" ); err != nil {
425
424
return err
426
425
}
426
+
427
+ if _ , err := os .Stat (filepath .Join (r .dir , "shallow" )); err == nil {
428
+ if _ , err := Run (r .dir , "git" , "fetch" , "--unshallow" , "-f" , r .remote ); err != nil {
429
+ return err
430
+ }
431
+ }
432
+
427
433
r .fetchLevel = fetchAll
428
434
}
429
435
return nil
430
436
}
431
437
432
- func (r * gitRepo ) fetchUnshallow (refSpecs ... string ) error {
433
- // To work around a protocol version 2 bug that breaks --unshallow,
434
- // add -c protocol.version=0.
435
- // TODO(rsc): The bug is believed to be server-side, meaning only
436
- // on Google's Git servers. Once the servers are fixed, drop the
437
- // protocol.version=0. See Google-internal bug b/110495752.
438
- var protoFlag []string
439
- unshallowFlag := unshallow (r .dir )
440
- if len (unshallowFlag ) > 0 {
441
- protoFlag = []string {"-c" , "protocol.version=0" }
442
- }
443
- _ , err := Run (r .dir , "git" , protoFlag , "fetch" , unshallowFlag , "-f" , r .remote , refSpecs )
444
- return err
445
- }
446
-
447
438
// statLocal returns a RevInfo describing rev in the local git repository.
448
439
// It uses version as info.Version.
449
440
func (r * gitRepo ) statLocal (version , rev string ) (* RevInfo , error ) {
@@ -563,39 +554,10 @@ func (r *gitRepo) ReadFileRevs(revs []string, file string, maxSize int64) (map[s
563
554
}
564
555
defer unlock ()
565
556
566
- var refs []string
567
- var protoFlag []string
568
- var unshallowFlag []string
569
- for _ , tag := range redo {
570
- refs = append (refs , "refs/tags/" + tag + ":refs/tags/" + tag )
571
- }
572
- if len (refs ) > 1 {
573
- unshallowFlag = unshallow (r .dir )
574
- if len (unshallowFlag ) > 0 {
575
- // To work around a protocol version 2 bug that breaks --unshallow,
576
- // add -c protocol.version=0.
577
- // TODO(rsc): The bug is believed to be server-side, meaning only
578
- // on Google's Git servers. Once the servers are fixed, drop the
579
- // protocol.version=0. See Google-internal bug b/110495752.
580
- protoFlag = []string {"-c" , "protocol.version=0" }
581
- }
582
- }
583
- if _ , err := Run (r .dir , "git" , protoFlag , "fetch" , unshallowFlag , "-f" , r .remote , refs ); err != nil {
557
+ if err := r .fetchRefsLocked (); err != nil {
584
558
return nil , err
585
559
}
586
560
587
- // TODO(bcmills): after the 1.11 freeze, replace the block above with:
588
- // if r.fetchLevel <= fetchSome {
589
- // r.fetchLevel = fetchSome
590
- // var refs []string
591
- // for _, tag := range redo {
592
- // refs = append(refs, "refs/tags/"+tag+":refs/tags/"+tag)
593
- // }
594
- // if _, err := Run(r.dir, "git", "fetch", "--update-shallow", "-f", r.remote, refs); err != nil {
595
- // return nil, err
596
- // }
597
- // }
598
-
599
561
if _ , err := r .readFileRevs (redo , file , files ); err != nil {
600
562
return nil , err
601
563
}
0 commit comments