396
test_must_fail nongit git --git-dir=nonexistent config get foo.bar
397
'
398
399
+# worktree: conditional include tests
400
+
401
+test_expect_success 'conditional include, worktree bare repo' '
402
+ git init --bare wt-bare &&
403
+ (
404
+ cd wt-bare &&
405
+ echo "[includeIf \"worktree:/\"]path=bar-bare" >>config &&
406
+ echo "[test]wtbare=1" >bar-bare &&
407
+ test_must_fail git config test.wtbare
408
+ )
409
+'
410
+
411
+test_expect_success 'conditional include, worktree multiple worktrees' '
412
+ git init wt-multi &&
413
+ (
414
+ cd wt-multi &&
415
+ test_commit initial &&
416
+ git worktree add -b linked-branch ../wt-linked HEAD &&
417
+ git worktree add -b prefix-branch ../wt-prefix/linked HEAD
418
+ ) &&
419
+ wt_main="$(cd wt-multi && pwd)" &&
420
+ wt_linked="$(cd wt-linked && pwd)" &&
421
+ wt_prefix_parent="$(cd wt-prefix && pwd)" &&
422
+ cat >>wt-multi/.git/config <<-EOF &&
423
+ [includeIf "worktree:$wt_main"]
424
+ path = main-config
425
+ [includeIf "worktree:$wt_linked"]
426
+ path = linked-config
427
+ [includeIf "worktree:$wt_prefix_parent/"]
428
+ path = prefix-config
429
+ EOF
430
+ echo "[test]mainvar=main" >wt-multi/.git/main-config &&
431
+ echo "[test]linkedvar=linked" >wt-multi/.git/linked-config &&
432
+ echo "[test]prefixvar=prefix" >wt-multi/.git/prefix-config &&
433
+ echo main >expect &&
434
+ git -C wt-multi config test.mainvar >actual &&
435
+ test_cmp expect actual &&
436
+ test_must_fail git -C wt-multi config test.linkedvar &&
437
+ test_must_fail git -C wt-multi config test.prefixvar &&
438
+ echo linked >expect &&
439
+ git -C wt-linked config test.linkedvar >actual &&
440
+ test_cmp expect actual &&
441
+ test_must_fail git -C wt-linked config test.mainvar &&
442
+ test_must_fail git -C wt-linked config test.prefixvar &&
443
+ echo prefix >expect &&
444
+ git -C wt-prefix/linked config test.prefixvar >actual &&
445
+ test_cmp expect actual &&
446
+ test_must_fail git -C wt-prefix/linked config test.mainvar &&
447
+ test_must_fail git -C wt-prefix/linked config test.linkedvar
448
+'
449
+
450
+test_expect_success SYMLINKS 'conditional include, worktree resolves symlinks' '
451
+ mkdir real-wt &&
452
+ ln -s real-wt link-wt &&
453
+ git init link-wt/repo &&
454
+ (
455
+ cd link-wt/repo &&
456
+ # repo->worktree resolves symlinks, so use real path in pattern
457
+ echo "[includeIf \"worktree:**/real-wt/repo\"]path=bar-link" >>.git/config &&
458
+ echo "[test]wtlink=2" >.git/bar-link &&
459
+ echo 2 >expect &&
460
+ git config test.wtlink >actual &&
461
+ test_cmp expect actual
462
+ )
463
+'
464
+
465
+test_expect_success !CASE_INSENSITIVE_FS 'conditional include, worktree, case sensitive' '
466
+ git init wt-case &&
467
+ (
468
+ cd wt-case &&
469
+ test_commit initial &&
470
+ wt_path="$(pwd)" &&
471
+ wt_upper=$(echo "$wt_path" | tr a-z A-Z) &&
472
+ echo "[includeIf \"worktree:$wt_upper\"]path=case-inc" >>.git/config &&
473
+ echo "[test]wtcase=1" >.git/case-inc &&
474
+ test_must_fail git config test.wtcase
475
+ )
476
+'
477
+
478
+test_expect_success 'conditional include, worktree, icase' '
479
+ git init wt-icase &&
480
+ (
481
+ cd wt-icase &&
482
+ test_commit initial &&
483
+ wt_path="$(pwd)" &&
484
+ wt_upper=$(echo "$wt_path" | tr a-z A-Z) &&
485
+ echo "[includeIf \"worktree/i:$wt_upper\"]path=icase-inc" >>.git/config &&
486
+ echo "[test]wticase=1" >.git/icase-inc &&
487
+ echo 1 >expect &&
488
+ git config test.wticase >actual &&
489
+ test_cmp expect actual
490
+ )
491
+'
492
+
493
+# The "worktree" condition cannot match during early config reading
494
+# because the repository object is not yet fully initialized and
495
+# repo_get_work_tree() returns NULL.
496
+test_expect_success 'conditional include, worktree does not match in early config' '
497
+ git init wt-early &&
498
+ (
499
+ cd wt-early &&
500
+ test_commit initial &&
501
+ wt_path="$(pwd)" &&
502
+ echo "[includeIf \"worktree:$wt_path\"]path=early-inc" >>.git/config &&
503
+ echo "[test]wtearly=1" >.git/early-inc &&
504
+ test-tool config read_early_config test.wtearly >actual &&
505
+ test_must_be_empty actual
506
+ )
507
+'
508
+
509
+# Use a loose pattern so the "present in non-worktree cases" check works
510
+# for Unix-style absolute paths and Windows paths like D:/a/git/...
511
+test_expect_success 'conditional include, worktree without repository' '
512
+ test_when_finished "rm -f .gitconfig config.inc" &&
513
+ git config set -f .gitconfig "includeIf.worktree:**.path" config.inc &&
514
+ git config set -f config.inc foo.bar baz &&
515
+ git config get foo.bar &&
516
+ test_must_fail nongit git config get foo.bar
517
+'
518
+
519
+test_expect_success 'conditional include, worktree without repository but explicit nonexistent Git directory' '
520
+ test_when_finished "rm -f .gitconfig config.inc" &&
521
+ git config set -f .gitconfig "includeIf.worktree:**.path" config.inc &&
522
+ git config set -f config.inc foo.bar baz &&
523
+ git config get foo.bar &&
524
+ test_must_fail nongit git --git-dir=nonexistent config get foo.bar
525
+'
526
+
527
test_done