@@ -26,6 +26,14 @@ func TestExec(t *testing.T) {
2626 assert .NoErrorf (t , err , "command failed; output: %#v" , string (output ))
2727}
2828
29+ func newRepository (t * testing.T , repoPath string ) * git.Repository {
30+ t .Helper ()
31+
32+ repo , err := git .NewRepository (repoPath )
33+ require .NoError (t , err )
34+ return repo
35+ }
36+
2937func gitCommand (t * testing.T , repoPath string , args ... string ) * exec.Cmd {
3038 t .Helper ()
3139
@@ -118,16 +126,13 @@ func addAuthorInfo(cmd *exec.Cmd, timestamp *time.Time) {
118126
119127func newGitBomb (
120128 t * testing.T , path string , depth , breadth int , body string ,
121- ) ( repo * git. Repository ) {
129+ ) {
122130 t .Helper ()
123131
124132 cmd := exec .Command ("git" , "init" , "--bare" , path )
125133 err := cmd .Run ()
126134 require .NoError (t , err )
127135
128- repo , err = git .NewRepository (path )
129- require .NoError (t , err )
130-
131136 oid := createObject (t , path , "blob" , func (w io.Writer ) error {
132137 _ , err := io .WriteString (w , body )
133138 return err
@@ -171,8 +176,6 @@ func newGitBomb(
171176
172177 err = updateRef (t , path , "refs/heads/master" , oid )
173178 require .NoError (t , err )
174-
175- return repo
176179}
177180
178181func pow (x uint64 , n int ) uint64 {
@@ -193,10 +196,10 @@ func TestBomb(t *testing.T) {
193196 os .RemoveAll (path )
194197 }()
195198
196- repo := newGitBomb (t , path , 10 , 10 , "boom!\n " )
199+ newGitBomb (t , path , 10 , 10 , "boom!\n " )
197200
198201 h , err := sizes .ScanRepositoryUsingGraph (
199- repo , git .AllReferencesFilter , sizes .NameStyleFull , false ,
202+ newRepository ( t , path ) , git .AllReferencesFilter , sizes .NameStyleFull , false ,
200203 )
201204 require .NoError (t , err )
202205
@@ -252,8 +255,6 @@ func TestTaggedTags(t *testing.T) {
252255
253256 cmd := exec .Command ("git" , "init" , path )
254257 require .NoError (t , cmd .Run (), "initializing repo" )
255- repo , err := git .NewRepository (path )
256- require .NoError (t , err , "initializing Repository object" )
257258
258259 timestamp := time .Unix (1112911993 , 0 )
259260
@@ -276,7 +277,7 @@ func TestTaggedTags(t *testing.T) {
276277 require .NoError (t , cmd .Run (), "creating tag 3" )
277278
278279 h , err := sizes .ScanRepositoryUsingGraph (
279- repo , git .AllReferencesFilter , sizes .NameStyleNone , false ,
280+ newRepository ( t , path ) , git .AllReferencesFilter , sizes .NameStyleNone , false ,
280281 )
281282 require .NoError (t , err , "scanning repository" )
282283 assert .Equal (t , counts .Count32 (3 ), h .MaxTagDepth , "tag depth" )
@@ -302,10 +303,9 @@ func TestFromSubdir(t *testing.T) {
302303 addAuthorInfo (cmd , & timestamp )
303304 require .NoError (t , cmd .Run (), "creating commit" )
304305
305- repo2 , err := git .NewRepository (filepath .Join (path , "subdir" ))
306- require .NoError (t , err , "creating Repository object in subdirectory" )
307306 h , err := sizes .ScanRepositoryUsingGraph (
308- repo2 , git .AllReferencesFilter , sizes .NameStyleNone , false ,
307+ newRepository (t , filepath .Join (path , "subdir" )),
308+ git .AllReferencesFilter , sizes .NameStyleNone , false ,
309309 )
310310 require .NoError (t , err , "scanning repository" )
311311 assert .Equal (t , counts .Count32 (2 ), h .MaxPathDepth , "max path depth" )
@@ -336,8 +336,7 @@ func TestSubmodule(t *testing.T) {
336336 mainPath := filepath .Join (path , "main" )
337337 cmd = exec .Command ("git" , "init" , mainPath )
338338 require .NoError (t , cmd .Run (), "initializing main repo" )
339- mainRepo , err := git .NewRepository (mainPath )
340- require .NoError (t , err , "initializing main Repository object" )
339+
341340 addFile (t , mainPath , "mainfile.txt" , "Hello, main!\n " )
342341
343342 cmd = gitCommand (t , mainPath , "commit" , "-m" , "main initial" )
@@ -355,18 +354,17 @@ func TestSubmodule(t *testing.T) {
355354
356355 // Analyze the main repo:
357356 h , err := sizes .ScanRepositoryUsingGraph (
358- mainRepo , git .AllReferencesFilter , sizes .NameStyleNone , false ,
357+ newRepository ( t , mainPath ) , git .AllReferencesFilter , sizes .NameStyleNone , false ,
359358 )
360359 require .NoError (t , err , "scanning repository" )
361360 assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
362361 assert .Equal (t , counts .Count32 (2 ), h .MaxExpandedBlobCount , "max expanded blob count" )
363362 assert .Equal (t , counts .Count32 (1 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
364363
365364 // Analyze the submodule:
366- submRepo2 , err := git .NewRepository (filepath .Join (mainPath , "sub" ))
367- require .NoError (t , err , "creating Repository object in submodule" )
368365 h , err = sizes .ScanRepositoryUsingGraph (
369- submRepo2 , git .AllReferencesFilter , sizes .NameStyleNone , false ,
366+ newRepository (t , filepath .Join (mainPath , "sub" )),
367+ git .AllReferencesFilter , sizes .NameStyleNone , false ,
370368 )
371369 require .NoError (t , err , "scanning repository" )
372370 assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
0 commit comments