t / t1305-config-include.shon commit config: correct file reading order in read_early_config() (e145a0b)
   1#!/bin/sh
   2
   3test_description='test config file include directives'
   4. ./test-lib.sh
   5
   6test_expect_success 'include file by absolute path' '
   7        echo "[test]one = 1" >one &&
   8        echo "[include]path = \"$(pwd)/one\"" >.gitconfig &&
   9        echo 1 >expect &&
  10        git config test.one >actual &&
  11        test_cmp expect actual
  12'
  13
  14test_expect_success 'include file by relative path' '
  15        echo "[test]one = 1" >one &&
  16        echo "[include]path = one" >.gitconfig &&
  17        echo 1 >expect &&
  18        git config test.one >actual &&
  19        test_cmp expect actual
  20'
  21
  22test_expect_success 'chained relative paths' '
  23        mkdir subdir &&
  24        echo "[test]three = 3" >subdir/three &&
  25        echo "[include]path = three" >subdir/two &&
  26        echo "[include]path = subdir/two" >.gitconfig &&
  27        echo 3 >expect &&
  28        git config test.three >actual &&
  29        test_cmp expect actual
  30'
  31
  32test_expect_success 'include paths get tilde-expansion' '
  33        echo "[test]one = 1" >one &&
  34        echo "[include]path = ~/one" >.gitconfig &&
  35        echo 1 >expect &&
  36        git config test.one >actual &&
  37        test_cmp expect actual
  38'
  39
  40test_expect_success 'include options can still be examined' '
  41        echo "[test]one = 1" >one &&
  42        echo "[include]path = one" >.gitconfig &&
  43        echo one >expect &&
  44        git config include.path >actual &&
  45        test_cmp expect actual
  46'
  47
  48test_expect_success 'listing includes option and expansion' '
  49        echo "[test]one = 1" >one &&
  50        echo "[include]path = one" >.gitconfig &&
  51        cat >expect <<-\EOF &&
  52        include.path=one
  53        test.one=1
  54        EOF
  55        git config --list >actual.full &&
  56        grep -v ^core actual.full >actual &&
  57        test_cmp expect actual
  58'
  59
  60test_expect_success 'single file lookup does not expand includes by default' '
  61        echo "[test]one = 1" >one &&
  62        echo "[include]path = one" >.gitconfig &&
  63        test_must_fail git config -f .gitconfig test.one &&
  64        test_must_fail git config --global test.one &&
  65        echo 1 >expect &&
  66        git config --includes -f .gitconfig test.one >actual &&
  67        test_cmp expect actual
  68'
  69
  70test_expect_success 'single file list does not expand includes by default' '
  71        echo "[test]one = 1" >one &&
  72        echo "[include]path = one" >.gitconfig &&
  73        echo "include.path=one" >expect &&
  74        git config -f .gitconfig --list >actual &&
  75        test_cmp expect actual
  76'
  77
  78test_expect_success 'writing config file does not expand includes' '
  79        echo "[test]one = 1" >one &&
  80        echo "[include]path = one" >.gitconfig &&
  81        git config test.two 2 &&
  82        echo 2 >expect &&
  83        git config --no-includes test.two >actual &&
  84        test_cmp expect actual &&
  85        test_must_fail git config --no-includes test.one
  86'
  87
  88test_expect_success 'config modification does not affect includes' '
  89        echo "[test]one = 1" >one &&
  90        echo "[include]path = one" >.gitconfig &&
  91        git config test.one 2 &&
  92        echo 1 >expect &&
  93        git config -f one test.one >actual &&
  94        test_cmp expect actual &&
  95        cat >expect <<-\EOF &&
  96        1
  97        2
  98        EOF
  99        git config --get-all test.one >actual &&
 100        test_cmp expect actual
 101'
 102
 103test_expect_success 'missing include files are ignored' '
 104        cat >.gitconfig <<-\EOF &&
 105        [include]path = non-existent
 106        [test]value = yes
 107        EOF
 108        echo yes >expect &&
 109        git config test.value >actual &&
 110        test_cmp expect actual
 111'
 112
 113test_expect_success 'absolute includes from command line work' '
 114        echo "[test]one = 1" >one &&
 115        echo 1 >expect &&
 116        git -c include.path="$(pwd)/one" config test.one >actual &&
 117        test_cmp expect actual
 118'
 119
 120test_expect_success 'relative includes from command line fail' '
 121        echo "[test]one = 1" >one &&
 122        test_must_fail git -c include.path=one config test.one
 123'
 124
 125test_expect_success 'absolute includes from blobs work' '
 126        echo "[test]one = 1" >one &&
 127        echo "[include]path=$(pwd)/one" >blob &&
 128        blob=$(git hash-object -w blob) &&
 129        echo 1 >expect &&
 130        git config --blob=$blob test.one >actual &&
 131        test_cmp expect actual
 132'
 133
 134test_expect_success 'relative includes from blobs fail' '
 135        echo "[test]one = 1" >one &&
 136        echo "[include]path=one" >blob &&
 137        blob=$(git hash-object -w blob) &&
 138        test_must_fail git config --blob=$blob test.one
 139'
 140
 141test_expect_success 'absolute includes from stdin work' '
 142        echo "[test]one = 1" >one &&
 143        echo 1 >expect &&
 144        echo "[include]path=\"$(pwd)/one\"" |
 145        git config --file - test.one >actual &&
 146        test_cmp expect actual
 147'
 148
 149test_expect_success 'relative includes from stdin line fail' '
 150        echo "[test]one = 1" >one &&
 151        echo "[include]path=one" |
 152        test_must_fail git config --file - test.one
 153'
 154
 155test_expect_success 'conditional include, both unanchored' '
 156        git init foo &&
 157        (
 158                cd foo &&
 159                echo "[includeIf \"gitdir:foo/\"]path=bar" >>.git/config &&
 160                echo "[test]one=1" >.git/bar &&
 161                echo 1 >expect &&
 162                git config test.one >actual &&
 163                test_cmp expect actual
 164        )
 165'
 166
 167test_expect_success 'conditional include, $HOME expansion' '
 168        (
 169                cd foo &&
 170                echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config &&
 171                echo "[test]two=2" >.git/bar2 &&
 172                echo 2 >expect &&
 173                git config test.two >actual &&
 174                test_cmp expect actual
 175        )
 176'
 177
 178test_expect_success 'conditional include, full pattern' '
 179        (
 180                cd foo &&
 181                echo "[includeIf \"gitdir:**/foo/**\"]path=bar3" >>.git/config &&
 182                echo "[test]three=3" >.git/bar3 &&
 183                echo 3 >expect &&
 184                git config test.three >actual &&
 185                test_cmp expect actual
 186        )
 187'
 188
 189test_expect_success 'conditional include, relative path' '
 190        echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >>.gitconfig &&
 191        echo "[test]four=4" >bar4 &&
 192        (
 193                cd foo &&
 194                echo 4 >expect &&
 195                git config test.four >actual &&
 196                test_cmp expect actual
 197        )
 198'
 199
 200test_expect_success 'conditional include, both unanchored, icase' '
 201        (
 202                cd foo &&
 203                echo "[includeIf \"gitdir/i:FOO/\"]path=bar5" >>.git/config &&
 204                echo "[test]five=5" >.git/bar5 &&
 205                echo 5 >expect &&
 206                git config test.five >actual &&
 207                test_cmp expect actual
 208        )
 209'
 210
 211test_expect_success 'conditional include, early config reading' '
 212        (
 213                cd foo &&
 214                echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config &&
 215                echo "[test]six=6" >.git/bar6 &&
 216                echo 6 >expect &&
 217                test-config read_early_config test.six >actual &&
 218                test_cmp expect actual
 219        )
 220'
 221
 222test_expect_success 'include cycles are detected' '
 223        cat >.gitconfig <<-\EOF &&
 224        [test]value = gitconfig
 225        [include]path = cycle
 226        EOF
 227        cat >cycle <<-\EOF &&
 228        [test]value = cycle
 229        [include]path = .gitconfig
 230        EOF
 231        cat >expect <<-\EOF &&
 232        gitconfig
 233        cycle
 234        EOF
 235        test_must_fail git config --get-all test.value 2>stderr &&
 236        grep "exceeded maximum include depth" stderr
 237'
 238
 239test_done