@@ -277,6 +277,242 @@ func TestRefSelections(t *testing.T) {
277
277
}
278
278
}
279
279
280
+ func TestRefgroups (t * testing.T ) {
281
+ t .Parallel ()
282
+
283
+ references := []string {
284
+ "refs/changes/20/884120/1" ,
285
+ "refs/changes/45/12345/42" ,
286
+ "refs/fo" ,
287
+ "refs/foo" ,
288
+ "refs/heads/foo" ,
289
+ "refs/heads/main" ,
290
+ "refs/notes/discussion" ,
291
+ "refs/notes/tests/build" ,
292
+ "refs/notes/tests/default" ,
293
+ "refs/pull/1/head" ,
294
+ "refs/pull/1/merge" ,
295
+ "refs/pull/123/head" ,
296
+ "refs/pull/1234/head" ,
297
+ "refs/remotes/origin/master" ,
298
+ "refs/remotes/upstream/foo" ,
299
+ "refs/remotes/upstream/master" ,
300
+ "refs/stash" ,
301
+ "refs/tags/foolish" ,
302
+ "refs/tags/other" ,
303
+ "refs/tags/release-1" ,
304
+ "refs/tags/release-2" ,
305
+ }
306
+
307
+ // Create a test repo with one orphan commit per refname:
308
+ repo := testutils .NewTestRepo (t , true , "refgroups" )
309
+ defer repo .Remove (t )
310
+
311
+ for _ , refname := range references {
312
+ repo .CreateReferencedOrphan (t , refname )
313
+ }
314
+
315
+ executable , err := exec .LookPath ("bin/git-sizer" )
316
+ require .NoError (t , err )
317
+ executable , err = filepath .Abs (executable )
318
+ require .NoError (t , err )
319
+
320
+ for _ , p := range []struct {
321
+ name string
322
+ args []string
323
+ config []git.ConfigEntry
324
+ stdout string
325
+ stderr string
326
+ }{
327
+ {
328
+ name : "no arguments" ,
329
+ stdout : `
330
+ | * References | | |
331
+ | * Count | 21 | |
332
+ | * Branches | 2 | |
333
+ | * Tags | 4 | |
334
+ | * Remote-tracking refs | 3 | |
335
+ | * Pull request refs | 4 | |
336
+ | * Changeset refs | 2 | |
337
+ | * Git notes | 3 | |
338
+ | * Git stash | 1 | |
339
+ | * Other | 2 | |
340
+ | | | |
341
+ ` [1 :],
342
+ stderr : `
343
+ References (included references marked with '+'):
344
+ + refs/changes/20/884120/1
345
+ + refs/changes/45/12345/42
346
+ + refs/fo
347
+ + refs/foo
348
+ + refs/heads/foo
349
+ + refs/heads/main
350
+ + refs/notes/discussion
351
+ + refs/notes/tests/build
352
+ + refs/notes/tests/default
353
+ + refs/pull/1/head
354
+ + refs/pull/1/merge
355
+ + refs/pull/123/head
356
+ + refs/pull/1234/head
357
+ + refs/remotes/origin/master
358
+ + refs/remotes/upstream/foo
359
+ + refs/remotes/upstream/master
360
+ + refs/stash
361
+ + refs/tags/foolish
362
+ + refs/tags/other
363
+ + refs/tags/release-1
364
+ + refs/tags/release-2
365
+ ` [1 :],
366
+ },
367
+ {
368
+ name : "nested-groups" ,
369
+ config : []git.ConfigEntry {
370
+ // Note that refgroup "misc" is defined implicitly.
371
+
372
+ {"refgroup.misc.foo.includeRegexp" , ".*foo.*" },
373
+
374
+ {"refgroup.misc.foo.oatend.includeRegexp" , ".*o" },
375
+
376
+ {"refgroup.misc.foo.bogus.include" , "bogus" },
377
+
378
+ {"refgroup.tags.releases.name" , "Releases" },
379
+ {"refgroup.tags.releases.includeRegexp" , "refs/tags/release-.*" },
380
+ },
381
+ stdout : `
382
+ | * References | | |
383
+ | * Count | 21 | |
384
+ | * Branches | 2 | |
385
+ | * Tags | 4 | |
386
+ | * Releases | 2 | |
387
+ | * Other | 2 | |
388
+ | * Remote-tracking refs | 3 | |
389
+ | * Pull request refs | 4 | |
390
+ | * Changeset refs | 2 | |
391
+ | * Git notes | 3 | |
392
+ | * Git stash | 1 | |
393
+ | * misc | 4 | |
394
+ | * foo | 4 | |
395
+ | * oatend | 3 | |
396
+ | * Other | 1 | |
397
+ | * Other | 1 | |
398
+ | | | |
399
+ ` [1 :],
400
+ },
401
+ {
402
+ name : "include-refgroups" ,
403
+ args : []
string {
"--include=@branches" ,
"[email protected] " ,
"--include=@oatend" },
404
+ config : []git.ConfigEntry {
405
+ {"refgroup.oatend.includeRegexp" , ".*o" },
406
+
407
+ {"refgroup.tags.releases.name" , "Releases" },
408
+ {"refgroup.tags.releases.includeRegexp" , "refs/tags/release-.*" },
409
+ },
410
+ stdout : `
411
+ | * References | | |
412
+ | * Count | 21 | |
413
+ | * Branches | 2 | |
414
+ | * Tags | 2 | |
415
+ | * Releases | 2 | |
416
+ | * Remote-tracking refs | 1 | |
417
+ | * oatend | 4 | |
418
+ | * Ignored | 14 | |
419
+ | | | |
420
+ ` [1 :],
421
+ stderr : `
422
+ References (included references marked with '+'):
423
+ refs/changes/20/884120/1
424
+ refs/changes/45/12345/42
425
+ + refs/fo
426
+ + refs/foo
427
+ + refs/heads/foo
428
+ + refs/heads/main
429
+ refs/notes/discussion
430
+ refs/notes/tests/build
431
+ refs/notes/tests/default
432
+ refs/pull/1/head
433
+ refs/pull/1/merge
434
+ refs/pull/123/head
435
+ refs/pull/1234/head
436
+ refs/remotes/origin/master
437
+ + refs/remotes/upstream/foo
438
+ refs/remotes/upstream/master
439
+ refs/stash
440
+ refs/tags/foolish
441
+ refs/tags/other
442
+ + refs/tags/release-1
443
+ + refs/tags/release-2
444
+ ` [1 :],
445
+ },
446
+ {
447
+ name : "exclude-refgroup" ,
448
+ args : []string {"--exclude=@stash" , "--exclude=@notes" },
449
+ stdout : `
450
+ | * References | | |
451
+ | * Count | 21 | |
452
+ | * Branches | 2 | |
453
+ | * Tags | 4 | |
454
+ | * Remote-tracking refs | 3 | |
455
+ | * Pull request refs | 4 | |
456
+ | * Changeset refs | 2 | |
457
+ | * Other | 2 | |
458
+ | * Ignored | 4 | |
459
+ | | | |
460
+ ` [1 :],
461
+ stderr : `
462
+ References (included references marked with '+'):
463
+ + refs/changes/20/884120/1
464
+ + refs/changes/45/12345/42
465
+ + refs/fo
466
+ + refs/foo
467
+ + refs/heads/foo
468
+ + refs/heads/main
469
+ refs/notes/discussion
470
+ refs/notes/tests/build
471
+ refs/notes/tests/default
472
+ + refs/pull/1/head
473
+ + refs/pull/1/merge
474
+ + refs/pull/123/head
475
+ + refs/pull/1234/head
476
+ + refs/remotes/origin/master
477
+ + refs/remotes/upstream/foo
478
+ + refs/remotes/upstream/master
479
+ refs/stash
480
+ + refs/tags/foolish
481
+ + refs/tags/other
482
+ + refs/tags/release-1
483
+ + refs/tags/release-2
484
+ ` [1 :],
485
+ },
486
+ } {
487
+ t .Run (
488
+ p .name ,
489
+ func (t * testing.T ) {
490
+ repo := repo .Clone (t , "refgroups" )
491
+ defer repo .Remove (t )
492
+
493
+ for _ , e := range p .config {
494
+ repo .ConfigAdd (t , e .Key , e .Value )
495
+ }
496
+
497
+ args := append ([]string {"--show-refs" , "-v" , "--no-progress" }, p .args ... )
498
+ cmd := exec .Command (executable , args ... )
499
+ cmd .Dir = repo .Path
500
+ var stdout bytes.Buffer
501
+ cmd .Stdout = & stdout
502
+ var stderr bytes.Buffer
503
+ cmd .Stderr = & stderr
504
+ err := cmd .Run ()
505
+ assert .NoError (t , err )
506
+
507
+ assert .Contains (t , stdout .String (), p .stdout )
508
+ if p .stderr != "" {
509
+ assert .Equal (t , stderr .String (), p .stderr )
510
+ }
511
+ },
512
+ )
513
+ }
514
+ }
515
+
280
516
func pow (x uint64 , n int ) uint64 {
281
517
p := uint64 (1 )
282
518
for ; n > 0 ; n -- {
0 commit comments