grep: change non-ASCII -i test to stop using --debug
[gitweb.git] / t / t1305-config-include.sh
index 9ba2ba11c3cac88154dbb2d522b43adf98a8dee7..933915ec06ec725f7cf6a9ed3e251f6ff2390f76 100755 (executable)
@@ -3,6 +3,16 @@
 test_description='test config file include directives'
 . ./test-lib.sh
 
+# Force setup_explicit_git_dir() to run until the end. This is needed
+# by some tests to make sure real_path() is called on $GIT_DIR. The
+# caller needs to make sure git commands are run from a subdirectory
+# though or real_path() will not be called.
+force_setup_explicit_git_dir() {
+    GIT_DIR="$(pwd)/.git"
+    GIT_WORK_TREE="$(pwd)"
+    export GIT_DIR GIT_WORK_TREE
+}
+
 test_expect_success 'include file by absolute path' '
        echo "[test]one = 1" >one &&
        echo "[include]path = \"$(pwd)/one\"" >.gitconfig &&
@@ -102,7 +112,7 @@ test_expect_success 'config modification does not affect includes' '
 
 test_expect_success 'missing include files are ignored' '
        cat >.gitconfig <<-\EOF &&
-       [include]path = foo
+       [include]path = non-existent
        [test]value = yes
        EOF
        echo yes >expect &&
@@ -152,6 +162,117 @@ test_expect_success 'relative includes from stdin line fail' '
        test_must_fail git config --file - test.one
 '
 
+test_expect_success 'conditional include, both unanchored' '
+       git init foo &&
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir:foo/\"]path=bar" >>.git/config &&
+               echo "[test]one=1" >.git/bar &&
+               echo 1 >expect &&
+               git config test.one >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'conditional include, $HOME expansion' '
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config &&
+               echo "[test]two=2" >.git/bar2 &&
+               echo 2 >expect &&
+               git config test.two >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'conditional include, full pattern' '
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir:**/foo/**\"]path=bar3" >>.git/config &&
+               echo "[test]three=3" >.git/bar3 &&
+               echo 3 >expect &&
+               git config test.three >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'conditional include, relative path' '
+       echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >>.gitconfig &&
+       echo "[test]four=4" >bar4 &&
+       (
+               cd foo &&
+               echo 4 >expect &&
+               git config test.four >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'conditional include, both unanchored, icase' '
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir/i:FOO/\"]path=bar5" >>.git/config &&
+               echo "[test]five=5" >.git/bar5 &&
+               echo 5 >expect &&
+               git config test.five >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success 'conditional include, early config reading' '
+       (
+               cd foo &&
+               echo "[includeIf \"gitdir:foo/\"]path=bar6" >>.git/config &&
+               echo "[test]six=6" >.git/bar6 &&
+               echo 6 >expect &&
+               test-config read_early_config test.six >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success SYMLINKS 'conditional include, set up symlinked $HOME' '
+       mkdir real-home &&
+       ln -s real-home home &&
+       (
+               HOME="$TRASH_DIRECTORY/home" &&
+               export HOME &&
+               cd "$HOME" &&
+
+               git init foo &&
+               cd foo &&
+               mkdir sub
+       )
+'
+
+test_expect_success SYMLINKS 'conditional include, $HOME expansion with symlinks' '
+       (
+               HOME="$TRASH_DIRECTORY/home" &&
+               export HOME &&
+               cd "$HOME"/foo &&
+
+               echo "[includeIf \"gitdir:~/foo/\"]path=bar2" >>.git/config &&
+               echo "[test]two=2" >.git/bar2 &&
+               echo 2 >expect &&
+               force_setup_explicit_git_dir &&
+               git -C sub config test.two >actual &&
+               test_cmp expect actual
+       )
+'
+
+test_expect_success SYMLINKS 'conditional include, relative path with symlinks' '
+       echo "[includeIf \"gitdir:./foo/.git\"]path=bar4" >home/.gitconfig &&
+       echo "[test]four=4" >home/bar4 &&
+       (
+               HOME="$TRASH_DIRECTORY/home" &&
+               export HOME &&
+               cd "$HOME"/foo &&
+
+               echo 4 >expect &&
+               force_setup_explicit_git_dir &&
+               git -C sub config test.four >actual &&
+               test_cmp expect actual
+       )
+'
+
 test_expect_success 'include cycles are detected' '
        cat >.gitconfig <<-\EOF &&
        [test]value = gitconfig