t1305: exercise edge cases of "onbranch" includes
Add a couple more tests for "onbranch" includes for several edge cases. All tests except for the last one pass, so for the most part this change really only aims to nail down behaviour of include conditionals further. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Sep 24, 2024 at 12:05 UTC
9cc2590ab988a357ffe214ecffbe78cfac29da17
1 file changed
+40
t/t1305-config-include.sh
+40
@@ -357,4 +357,44 @@ test_expect_success 'include cycles are detected' '
357
grep "exceeded maximum include depth" stderr
358
'
359
360
+test_expect_success 'onbranch with unborn branch' '
361
+ test_when_finished "rm -rf repo" &&
362
+ git init repo &&
363
+ (
364
+ cd repo &&
365
+ git config set includeIf.onbranch:"*".path config.inc &&
366
+ git config set -f .git/config.inc foo.bar baz &&
367
+ git config get foo.bar
368
+ )
369
+'
370
+
371
+test_expect_success 'onbranch with detached HEAD' '
372
+ test_when_finished "rm -rf repo" &&
373
+ git init repo &&
374
+ (
375
+ cd repo &&
376
+ git config set "includeIf.onbranch:*.path" config.inc &&
377
+ git config set -f .git/config.inc foo.bar baz &&
378
+ test_commit initial &&
379
+ git switch --detach HEAD &&
380
+ test_must_fail git config get foo.bar
381
+ )
382
+'
383
+
384
+test_expect_success 'onbranch without repository' '
385
+ test_when_finished "rm -f .gitconfig config.inc" &&
386
+ git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc &&
387
+ git config set -f config.inc foo.bar baz &&
388
+ git config get foo.bar &&
389
+ test_must_fail nongit git config get foo.bar
390
+'
391
+
392
+test_expect_failure 'onbranch without repository but explicit nonexistent Git directory' '
393
+ test_when_finished "rm -f .gitconfig config.inc" &&
394
+ git config set -f .gitconfig "includeIf.onbranch:**.path" config.inc &&
395
+ git config set -f config.inc foo.bar baz &&
396
+ git config get foo.bar &&
397
+ test_must_fail nongit git --git-dir=nonexistent config get foo.bar
398
+'
399
+
400
test_done