t / t1305-config-include.shon commit Merge branch 'cn/pull-rebase-message' (4b4ec3f)
   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 options can still be examined' '
  33        echo "[test]one = 1" >one &&
  34        echo "[include]path = one" >.gitconfig &&
  35        echo one >expect &&
  36        git config include.path >actual &&
  37        test_cmp expect actual
  38'
  39
  40test_expect_success 'listing includes option and expansion' '
  41        echo "[test]one = 1" >one &&
  42        echo "[include]path = one" >.gitconfig &&
  43        cat >expect <<-\EOF &&
  44        include.path=one
  45        test.one=1
  46        EOF
  47        git config --list >actual.full &&
  48        grep -v ^core actual.full >actual &&
  49        test_cmp expect actual
  50'
  51
  52test_expect_success 'single file lookup does not expand includes by default' '
  53        echo "[test]one = 1" >one &&
  54        echo "[include]path = one" >.gitconfig &&
  55        test_must_fail git config -f .gitconfig test.one &&
  56        test_must_fail git config --global test.one &&
  57        echo 1 >expect &&
  58        git config --includes -f .gitconfig test.one >actual &&
  59        test_cmp expect actual
  60'
  61
  62test_expect_success 'single file list does not expand includes by default' '
  63        echo "[test]one = 1" >one &&
  64        echo "[include]path = one" >.gitconfig &&
  65        echo "include.path=one" >expect &&
  66        git config -f .gitconfig --list >actual &&
  67        test_cmp expect actual
  68'
  69
  70test_expect_success 'writing config file does not expand includes' '
  71        echo "[test]one = 1" >one &&
  72        echo "[include]path = one" >.gitconfig &&
  73        git config test.two 2 &&
  74        echo 2 >expect &&
  75        git config --no-includes test.two >actual &&
  76        test_cmp expect actual &&
  77        test_must_fail git config --no-includes test.one
  78'
  79
  80test_expect_success 'config modification does not affect includes' '
  81        echo "[test]one = 1" >one &&
  82        echo "[include]path = one" >.gitconfig &&
  83        git config test.one 2 &&
  84        echo 1 >expect &&
  85        git config -f one test.one >actual &&
  86        test_cmp expect actual &&
  87        cat >expect <<-\EOF &&
  88        1
  89        2
  90        EOF
  91        git config --get-all test.one >actual &&
  92        test_cmp expect actual
  93'
  94
  95test_expect_success 'missing include files are ignored' '
  96        cat >.gitconfig <<-\EOF &&
  97        [include]path = foo
  98        [test]value = yes
  99        EOF
 100        echo yes >expect &&
 101        git config test.value >actual &&
 102        test_cmp expect actual
 103'
 104
 105test_expect_success 'absolute includes from command line work' '
 106        echo "[test]one = 1" >one &&
 107        echo 1 >expect &&
 108        git -c include.path="$PWD/one" config test.one >actual &&
 109        test_cmp expect actual
 110'
 111
 112test_expect_success 'relative includes from command line fail' '
 113        echo "[test]one = 1" >one &&
 114        test_must_fail git -c include.path=one config test.one
 115'
 116
 117test_expect_success 'include cycles are detected' '
 118        cat >.gitconfig <<-\EOF &&
 119        [test]value = gitconfig
 120        [include]path = cycle
 121        EOF
 122        cat >cycle <<-\EOF &&
 123        [test]value = cycle
 124        [include]path = .gitconfig
 125        EOF
 126        cat >expect <<-\EOF &&
 127        gitconfig
 128        cycle
 129        EOF
 130        test_must_fail git config --get-all test.value 2>stderr &&
 131        grep "exceeded maximum include depth" stderr
 132'
 133
 134test_done