1#!/bin/sh
   2test_description="config file in multi worktree"
   4. ./test-lib.sh
   6test_expect_success 'setup' '
   8        test_commit start
   9'
  10test_expect_success 'config --worktree in single worktree' '
  12        git config --worktree foo.bar true &&
  13        test_cmp_config true foo.bar
  14'
  15test_expect_success 'add worktrees' '
  17        git worktree add wt1 &&
  18        git worktree add wt2
  19'
  20test_expect_success 'config --worktree without extension' '
  22        test_must_fail git config --worktree foo.bar false
  23'
  24test_expect_success 'enable worktreeConfig extension' '
  26        git config extensions.worktreeConfig true &&
  27        test_cmp_config true extensions.worktreeConfig
  28'
  29test_expect_success 'config is shared as before' '
  31        git config this.is shared &&
  32        test_cmp_config shared this.is &&
  33        test_cmp_config -C wt1 shared this.is &&
  34        test_cmp_config -C wt2 shared this.is
  35'
  36test_expect_success 'config is shared (set from another worktree)' '
  38        git -C wt1 config that.is also-shared &&
  39        test_cmp_config also-shared that.is &&
  40        test_cmp_config -C wt1 also-shared that.is &&
  41        test_cmp_config -C wt2 also-shared that.is
  42'
  43test_expect_success 'config private to main worktree' '
  45        git config --worktree this.is for-main &&
  46        test_cmp_config for-main this.is &&
  47        test_cmp_config -C wt1 shared this.is &&
  48        test_cmp_config -C wt2 shared this.is
  49'
  50test_expect_success 'config private to linked worktree' '
  52        git -C wt1 config --worktree this.is for-wt1 &&
  53        test_cmp_config for-main this.is &&
  54        test_cmp_config -C wt1 for-wt1 this.is &&
  55        test_cmp_config -C wt2 shared this.is
  56'
  57test_expect_success 'core.bare no longer for main only' '
  59        test_config core.bare true &&
  60        test "$(git rev-parse --is-bare-repository)" = true &&
  61        test "$(git -C wt1 rev-parse --is-bare-repository)" = true &&
  62        test "$(git -C wt2 rev-parse --is-bare-repository)" = true
  63'
  64test_expect_success 'per-worktree core.bare is picked up' '
  66        git -C wt1 config --worktree core.bare true &&
  67        test "$(git rev-parse --is-bare-repository)" = false &&
  68        test "$(git -C wt1 rev-parse --is-bare-repository)" = true &&
  69        test "$(git -C wt2 rev-parse --is-bare-repository)" = false
  70'
  71test_expect_success 'config.worktree no longer read without extension' '
  73        git config --unset extensions.worktreeConfig &&
  74        test_cmp_config shared this.is &&
  75        test_cmp_config -C wt1 shared this.is &&
  76        test_cmp_config -C wt2 shared this.is
  77'
  78test_done