@@ -558,14 +558,21 @@ func (rg refGrouper) Groups() []sizes.RefGroup {
558558func TestBomb (t * testing.T ) {
559559 t .Parallel ()
560560
561- repo := testutils .NewTestRepo (t , true , "bomb" )
562- t .Cleanup (func () { repo .Remove (t ) })
561+ ctx := context .Background ()
562+
563+ testRepo := testutils .NewTestRepo (t , true , "bomb" )
564+ t .Cleanup (func () { testRepo .Remove (t ) })
565+
566+ newGitBomb (t , testRepo , 10 , 10 , "boom!\n " )
563567
564- newGitBomb (t , repo , 10 , 10 , "boom!\n " )
568+ repo := testRepo .Repository (t )
569+
570+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
571+ require .NoError (t , err )
565572
566573 h , err := sizes .ScanRepositoryUsingGraph (
567- context . Background () , repo . Repository ( t ) ,
568- refGrouper {} , sizes .NameStyleFull , meter .NoProgressMeter ,
574+ ctx , repo ,
575+ refRoots , sizes .NameStyleFull , meter .NoProgressMeter ,
569576 )
570577 require .NoError (t , err )
571578
@@ -613,32 +620,39 @@ func TestBomb(t *testing.T) {
613620func TestTaggedTags (t * testing.T ) {
614621 t .Parallel ()
615622
616- repo := testutils .NewTestRepo (t , false , "tagged-tags" )
617- defer repo .Remove (t )
623+ ctx := context .Background ()
624+
625+ testRepo := testutils .NewTestRepo (t , false , "tagged-tags" )
626+ defer testRepo .Remove (t )
618627
619628 timestamp := time .Unix (1112911993 , 0 )
620629
621- cmd := repo .GitCommand (t , "commit" , "-m" , "initial" , "--allow-empty" )
630+ cmd := testRepo .GitCommand (t , "commit" , "-m" , "initial" , "--allow-empty" )
622631 testutils .AddAuthorInfo (cmd , & timestamp )
623632 require .NoError (t , cmd .Run (), "creating commit" )
624633
625634 // The lexicographical order of these tags is important, hence
626635 // their strange names.
627- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 1" , "tag" , "master" )
636+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 1" , "tag" , "master" )
628637 testutils .AddAuthorInfo (cmd , & timestamp )
629638 require .NoError (t , cmd .Run (), "creating tag 1" )
630639
631- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 2" , "bag" , "tag" )
640+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 2" , "bag" , "tag" )
632641 testutils .AddAuthorInfo (cmd , & timestamp )
633642 require .NoError (t , cmd .Run (), "creating tag 2" )
634643
635- cmd = repo .GitCommand (t , "tag" , "-m" , "tag 3" , "wag" , "bag" )
644+ cmd = testRepo .GitCommand (t , "tag" , "-m" , "tag 3" , "wag" , "bag" )
636645 testutils .AddAuthorInfo (cmd , & timestamp )
637646 require .NoError (t , cmd .Run (), "creating tag 3" )
638647
648+ repo := testRepo .Repository (t )
649+
650+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
651+ require .NoError (t , err )
652+
639653 h , err := sizes .ScanRepositoryUsingGraph (
640- context .Background (), repo . Repository ( t ) ,
641- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
654+ context .Background (), repo ,
655+ refRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
642656 )
643657 require .NoError (t , err , "scanning repository" )
644658 assert .Equal (t , counts .Count32 (3 ), h .MaxTagDepth , "tag depth" )
@@ -647,20 +661,27 @@ func TestTaggedTags(t *testing.T) {
647661func TestFromSubdir (t * testing.T ) {
648662 t .Parallel ()
649663
650- repo := testutils .NewTestRepo (t , false , "subdir" )
651- defer repo .Remove (t )
664+ ctx := context .Background ()
665+
666+ testRepo := testutils .NewTestRepo (t , false , "subdir" )
667+ defer testRepo .Remove (t )
652668
653669 timestamp := time .Unix (1112911993 , 0 )
654670
655- repo .AddFile (t , "subdir/file.txt" , "Hello, world!\n " )
671+ testRepo .AddFile (t , "subdir/file.txt" , "Hello, world!\n " )
656672
657- cmd := repo .GitCommand (t , "commit" , "-m" , "initial" )
673+ cmd := testRepo .GitCommand (t , "commit" , "-m" , "initial" )
658674 testutils .AddAuthorInfo (cmd , & timestamp )
659675 require .NoError (t , cmd .Run (), "creating commit" )
660676
677+ repo := testRepo .Repository (t )
678+
679+ refRoots , err := sizes .CollectReferences (ctx , repo , refGrouper {})
680+ require .NoError (t , err )
681+
661682 h , err := sizes .ScanRepositoryUsingGraph (
662- context .Background (), repo .Repository (t ),
663- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
683+ context .Background (), testRepo .Repository (t ),
684+ refRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
664685 )
665686 require .NoError (t , err , "scanning repository" )
666687 assert .Equal (t , counts .Count32 (2 ), h .MaxPathDepth , "max path depth" )
@@ -669,6 +690,8 @@ func TestFromSubdir(t *testing.T) {
669690func TestSubmodule (t * testing.T ) {
670691 t .Parallel ()
671692
693+ ctx := context .Background ()
694+
672695 tmp , err := ioutil .TempDir ("" , "submodule" )
673696 require .NoError (t , err , "creating temporary directory" )
674697
@@ -678,55 +701,66 @@ func TestSubmodule(t *testing.T) {
678701
679702 timestamp := time .Unix (1112911993 , 0 )
680703
681- submRepo := testutils.TestRepo {
704+ submTestRepo := testutils.TestRepo {
682705 Path : filepath .Join (tmp , "subm" ),
683706 }
684- submRepo .Init (t , false )
685- submRepo .AddFile (t , "submfile1.txt" , "Hello, submodule!\n " )
686- submRepo .AddFile (t , "submfile2.txt" , "Hello again, submodule!\n " )
687- submRepo .AddFile (t , "submfile3.txt" , "Hello again, submodule!\n " )
707+ submTestRepo .Init (t , false )
708+ submTestRepo .AddFile (t , "submfile1.txt" , "Hello, submodule!\n " )
709+ submTestRepo .AddFile (t , "submfile2.txt" , "Hello again, submodule!\n " )
710+ submTestRepo .AddFile (t , "submfile3.txt" , "Hello again, submodule!\n " )
688711
689- cmd := submRepo .GitCommand (t , "commit" , "-m" , "subm initial" )
712+ cmd := submTestRepo .GitCommand (t , "commit" , "-m" , "subm initial" )
690713 testutils .AddAuthorInfo (cmd , & timestamp )
691714 require .NoError (t , cmd .Run (), "creating subm commit" )
692715
693- mainRepo := testutils.TestRepo {
716+ mainTestRepo := testutils.TestRepo {
694717 Path : filepath .Join (tmp , "main" ),
695718 }
696- mainRepo .Init (t , false )
719+ mainTestRepo .Init (t , false )
697720
698- mainRepo .AddFile (t , "mainfile.txt" , "Hello, main!\n " )
721+ mainTestRepo .AddFile (t , "mainfile.txt" , "Hello, main!\n " )
699722
700- cmd = mainRepo .GitCommand (t , "commit" , "-m" , "main initial" )
723+ cmd = mainTestRepo .GitCommand (t , "commit" , "-m" , "main initial" )
701724 testutils .AddAuthorInfo (cmd , & timestamp )
702725 require .NoError (t , cmd .Run (), "creating main commit" )
703726
704727 // Make subm a submodule of main:
705- cmd = mainRepo .GitCommand (t , "-c" , "protocol.file.allow=always" , "submodule" , "add" , submRepo .Path , "sub" )
706- cmd .Dir = mainRepo .Path
728+ cmd = mainTestRepo .GitCommand (t , "-c" , "protocol.file.allow=always" , "submodule" , "add" , submTestRepo .Path , "sub" )
729+ cmd .Dir = mainTestRepo .Path
707730 require .NoError (t , cmd .Run (), "adding submodule" )
708731
709- cmd = mainRepo .GitCommand (t , "commit" , "-m" , "add submodule" )
732+ cmd = mainTestRepo .GitCommand (t , "commit" , "-m" , "add submodule" )
710733 testutils .AddAuthorInfo (cmd , & timestamp )
711734 require .NoError (t , cmd .Run (), "committing submodule to main" )
712735
736+ mainRepo := mainTestRepo .Repository (t )
737+
738+ mainRefRoots , err := sizes .CollectReferences (ctx , mainRepo , refGrouper {})
739+ require .NoError (t , err )
740+
713741 // Analyze the main repo:
714742 h , err := sizes .ScanRepositoryUsingGraph (
715- context .Background (), mainRepo .Repository (t ),
716- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
743+ context .Background (), mainTestRepo .Repository (t ),
744+ mainRefRoots , sizes .NameStyleNone , meter .NoProgressMeter ,
717745 )
718746 require .NoError (t , err , "scanning repository" )
719747 assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
720748 assert .Equal (t , counts .Count32 (2 ), h .MaxExpandedBlobCount , "max expanded blob count" )
721749 assert .Equal (t , counts .Count32 (1 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
722750
723751 // Analyze the submodule:
724- submRepo2 := testutils.TestRepo {
725- Path : filepath .Join (mainRepo .Path , "sub" ),
752+ submTestRepo2 := testutils.TestRepo {
753+ Path : filepath .Join (mainTestRepo .Path , "sub" ),
726754 }
755+
756+ submRepo2 := submTestRepo2 .Repository (t )
757+
758+ submRefRoots2 , err := sizes .CollectReferences (ctx , submRepo2 , refGrouper {})
759+ require .NoError (t , err )
760+
727761 h , err = sizes .ScanRepositoryUsingGraph (
728- context .Background (), submRepo2 . Repository ( t ) ,
729- refGrouper {} , sizes .NameStyleNone , meter .NoProgressMeter ,
762+ context .Background (), submRepo2 ,
763+ submRefRoots2 , sizes .NameStyleNone , meter .NoProgressMeter ,
730764 )
731765 require .NoError (t , err , "scanning repository" )
732766 assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
0 commit comments