@@ -26,6 +26,14 @@ func TestExec(t *testing.T) {
26
26
assert .NoErrorf (t , err , "command failed; output: %#v" , string (output ))
27
27
}
28
28
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
+
29
37
func gitCommand (t * testing.T , repoPath string , args ... string ) * exec.Cmd {
30
38
t .Helper ()
31
39
@@ -118,16 +126,13 @@ func addAuthorInfo(cmd *exec.Cmd, timestamp *time.Time) {
118
126
119
127
func newGitBomb (
120
128
t * testing.T , path string , depth , breadth int , body string ,
121
- ) ( repo * git. Repository ) {
129
+ ) {
122
130
t .Helper ()
123
131
124
132
cmd := exec .Command ("git" , "init" , "--bare" , path )
125
133
err := cmd .Run ()
126
134
require .NoError (t , err )
127
135
128
- repo , err = git .NewRepository (path )
129
- require .NoError (t , err )
130
-
131
136
oid := createObject (t , path , "blob" , func (w io.Writer ) error {
132
137
_ , err := io .WriteString (w , body )
133
138
return err
@@ -171,8 +176,6 @@ func newGitBomb(
171
176
172
177
err = updateRef (t , path , "refs/heads/master" , oid )
173
178
require .NoError (t , err )
174
-
175
- return repo
176
179
}
177
180
178
181
func pow (x uint64 , n int ) uint64 {
@@ -193,10 +196,10 @@ func TestBomb(t *testing.T) {
193
196
os .RemoveAll (path )
194
197
}()
195
198
196
- repo := newGitBomb (t , path , 10 , 10 , "boom!\n " )
199
+ newGitBomb (t , path , 10 , 10 , "boom!\n " )
197
200
198
201
h , err := sizes .ScanRepositoryUsingGraph (
199
- repo , git .AllReferencesFilter , sizes .NameStyleFull , false ,
202
+ newRepository ( t , path ) , git .AllReferencesFilter , sizes .NameStyleFull , false ,
200
203
)
201
204
require .NoError (t , err )
202
205
@@ -252,8 +255,6 @@ func TestTaggedTags(t *testing.T) {
252
255
253
256
cmd := exec .Command ("git" , "init" , path )
254
257
require .NoError (t , cmd .Run (), "initializing repo" )
255
- repo , err := git .NewRepository (path )
256
- require .NoError (t , err , "initializing Repository object" )
257
258
258
259
timestamp := time .Unix (1112911993 , 0 )
259
260
@@ -276,7 +277,7 @@ func TestTaggedTags(t *testing.T) {
276
277
require .NoError (t , cmd .Run (), "creating tag 3" )
277
278
278
279
h , err := sizes .ScanRepositoryUsingGraph (
279
- repo , git .AllReferencesFilter , sizes .NameStyleNone , false ,
280
+ newRepository ( t , path ) , git .AllReferencesFilter , sizes .NameStyleNone , false ,
280
281
)
281
282
require .NoError (t , err , "scanning repository" )
282
283
assert .Equal (t , counts .Count32 (3 ), h .MaxTagDepth , "tag depth" )
@@ -302,10 +303,9 @@ func TestFromSubdir(t *testing.T) {
302
303
addAuthorInfo (cmd , & timestamp )
303
304
require .NoError (t , cmd .Run (), "creating commit" )
304
305
305
- repo2 , err := git .NewRepository (filepath .Join (path , "subdir" ))
306
- require .NoError (t , err , "creating Repository object in subdirectory" )
307
306
h , err := sizes .ScanRepositoryUsingGraph (
308
- repo2 , git .AllReferencesFilter , sizes .NameStyleNone , false ,
307
+ newRepository (t , filepath .Join (path , "subdir" )),
308
+ git .AllReferencesFilter , sizes .NameStyleNone , false ,
309
309
)
310
310
require .NoError (t , err , "scanning repository" )
311
311
assert .Equal (t , counts .Count32 (2 ), h .MaxPathDepth , "max path depth" )
@@ -336,8 +336,7 @@ func TestSubmodule(t *testing.T) {
336
336
mainPath := filepath .Join (path , "main" )
337
337
cmd = exec .Command ("git" , "init" , mainPath )
338
338
require .NoError (t , cmd .Run (), "initializing main repo" )
339
- mainRepo , err := git .NewRepository (mainPath )
340
- require .NoError (t , err , "initializing main Repository object" )
339
+
341
340
addFile (t , mainPath , "mainfile.txt" , "Hello, main!\n " )
342
341
343
342
cmd = gitCommand (t , mainPath , "commit" , "-m" , "main initial" )
@@ -355,18 +354,17 @@ func TestSubmodule(t *testing.T) {
355
354
356
355
// Analyze the main repo:
357
356
h , err := sizes .ScanRepositoryUsingGraph (
358
- mainRepo , git .AllReferencesFilter , sizes .NameStyleNone , false ,
357
+ newRepository ( t , mainPath ) , git .AllReferencesFilter , sizes .NameStyleNone , false ,
359
358
)
360
359
require .NoError (t , err , "scanning repository" )
361
360
assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
362
361
assert .Equal (t , counts .Count32 (2 ), h .MaxExpandedBlobCount , "max expanded blob count" )
363
362
assert .Equal (t , counts .Count32 (1 ), h .MaxExpandedSubmoduleCount , "max expanded submodule count" )
364
363
365
364
// Analyze the submodule:
366
- submRepo2 , err := git .NewRepository (filepath .Join (mainPath , "sub" ))
367
- require .NoError (t , err , "creating Repository object in submodule" )
368
365
h , err = sizes .ScanRepositoryUsingGraph (
369
- submRepo2 , git .AllReferencesFilter , sizes .NameStyleNone , false ,
366
+ newRepository (t , filepath .Join (mainPath , "sub" )),
367
+ git .AllReferencesFilter , sizes .NameStyleNone , false ,
370
368
)
371
369
require .NoError (t , err , "scanning repository" )
372
370
assert .Equal (t , counts .Count32 (2 ), h .UniqueBlobCount , "unique blob count" )
0 commit comments