#!/bin/sh global test_description := ''test config file include directives'' source ./test-lib.sh test_expect_success 'include file by absolute path' ' echo "[test]one = 1" >one && echo "[include]path = \"$(pwd)/one\"" >.gitconfig && echo 1 >expect && git config test.one >actual && test_cmp expect actual ' test_expect_success 'include file by relative path' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && echo 1 >expect && git config test.one >actual && test_cmp expect actual ' test_expect_success 'chained relative paths' ' mkdir subdir && echo "[test]three = 3" >subdir/three && echo "[include]path = three" >subdir/two && echo "[include]path = subdir/two" >.gitconfig && echo 3 >expect && git config test.three >actual && test_cmp expect actual ' test_expect_success 'include paths get tilde-expansion' ' echo "[test]one = 1" >one && echo "[include]path = ~/one" >.gitconfig && echo 1 >expect && git config test.one >actual && test_cmp expect actual ' test_expect_success 'include options can still be examined' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && echo one >expect && git config include.path >actual && test_cmp expect actual ' test_expect_success 'listing includes option and expansion' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && cat >expect <<-\EOF && include.path=one test.one=1 EOF git config --list >actual.full && grep -v ^core actual.full >actual && test_cmp expect actual ' test_expect_success 'single file lookup does not expand includes by default' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && test_must_fail git config -f .gitconfig test.one && test_must_fail git config --global test.one && echo 1 >expect && git config --includes -f .gitconfig test.one >actual && test_cmp expect actual ' test_expect_success 'single file list does not expand includes by default' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && echo "include.path=one" >expect && git config -f .gitconfig --list >actual && test_cmp expect actual ' test_expect_success 'writing config file does not expand includes' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && git config test.two 2 && echo 2 >expect && git config --no-includes test.two >actual && test_cmp expect actual && test_must_fail git config --no-includes test.one ' test_expect_success 'config modification does not affect includes' ' echo "[test]one = 1" >one && echo "[include]path = one" >.gitconfig && git config test.one 2 && echo 1 >expect && git config -f one test.one >actual && test_cmp expect actual && cat >expect <<-\EOF && 1 2 EOF git config --get-all test.one >actual && test_cmp expect actual ' test_expect_success 'missing include files are ignored' ' cat >.gitconfig <<-\EOF && [include]path = foo [test]value = yes EOF echo yes >expect && git config test.value >actual && test_cmp expect actual ' test_expect_success 'absolute includes from command line work' ' echo "[test]one = 1" >one && echo 1 >expect && git -c include.path="$(pwd)/one" config test.one >actual && test_cmp expect actual ' test_expect_success 'relative includes from command line fail' ' echo "[test]one = 1" >one && test_must_fail git -c include.path=one config test.one ' test_expect_success 'absolute includes from blobs work' ' echo "[test]one = 1" >one && echo "[include]path=$(pwd)/one" >blob && blob=$(git hash-object -w blob) && echo 1 >expect && git config --blob=$blob test.one >actual && test_cmp expect actual ' test_expect_success 'relative includes from blobs fail' ' echo "[test]one = 1" >one && echo "[include]path=one" >blob && blob=$(git hash-object -w blob) && test_must_fail git config --blob=$blob test.one ' test_expect_success 'absolute includes from stdin work' ' echo "[test]one = 1" >one && echo 1 >expect && echo "[include]path=\"$(pwd)/one\"" | git config --file - test.one >actual && test_cmp expect actual ' test_expect_success 'relative includes from stdin line fail' ' echo "[test]one = 1" >one && echo "[include]path=one" | test_must_fail git config --file - test.one ' test_expect_success 'include cycles are detected' ' cat >.gitconfig <<-\EOF && [test]value = gitconfig [include]path = cycle EOF cat >cycle <<-\EOF && [test]value = cycle [include]path = .gitconfig EOF cat >expect <<-\EOF && gitconfig cycle EOF test_must_fail git config --get-all test.value 2>stderr && grep "exceeded maximum include depth" stderr ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"test config file include directives">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"include file by absolute path">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = \\\"$(pwd)/one\\\"\" >.gitconfig &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"include file by relative path">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"chained relative paths">)} { (SQ <"\n"> <"\tmkdir subdir &&\n"> <"\techo \"[test]three = 3\" >subdir/three &&\n"> <"\techo \"[include]path = three\" >subdir/two &&\n"> <"\techo \"[include]path = subdir/two\" >.gitconfig &&\n"> <"\techo 3 >expect &&\n"> <"\tgit config test.three >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"include paths get tilde-expansion">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = ~/one\" >.gitconfig &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"include options can still be examined">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\techo one >expect &&\n"> <"\tgit config include.path >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"listing includes option and expansion">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\tcat >expect <<-\\EOF &&\n"> <"\tinclude.path=one\n"> <"\ttest.one=1\n"> <"\tEOF\n"> <"\tgit config --list >actual.full &&\n"> <"\tgrep -v ^core actual.full >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"single file lookup does not expand includes by default">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\ttest_must_fail git config -f .gitconfig test.one &&\n"> <"\ttest_must_fail git config --global test.one &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config --includes -f .gitconfig test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"single file list does not expand includes by default">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\techo \"include.path=one\" >expect &&\n"> <"\tgit config -f .gitconfig --list >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"writing config file does not expand includes">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\tgit config test.two 2 &&\n"> <"\techo 2 >expect &&\n"> <"\tgit config --no-includes test.two >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\ttest_must_fail git config --no-includes test.one\n"> ) } ) (C {(test_expect_success)} {(SQ <"config modification does not affect includes">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path = one\" >.gitconfig &&\n"> <"\tgit config test.one 2 &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config -f one test.one >actual &&\n"> <"\ttest_cmp expect actual &&\n"> <"\tcat >expect <<-\\EOF &&\n"> <"\t1\n"> <"\t2\n"> <"\tEOF\n"> <"\tgit config --get-all test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"missing include files are ignored">)} { (SQ <"\n"> <"\tcat >.gitconfig <<-\\EOF &&\n"> <"\t[include]path = foo\n"> <"\t[test]value = yes\n"> <"\tEOF\n"> <"\techo yes >expect &&\n"> <"\tgit config test.value >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"absolute includes from command line work">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo 1 >expect &&\n"> <"\tgit -c include.path=\"$(pwd)/one\" config test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"relative includes from command line fail">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\ttest_must_fail git -c include.path=one config test.one\n"> ) } ) (C {(test_expect_success)} {(SQ <"absolute includes from blobs work">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path=$(pwd)/one\" >blob &&\n"> <"\tblob=$(git hash-object -w blob) &&\n"> <"\techo 1 >expect &&\n"> <"\tgit config --blob=$blob test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"relative includes from blobs fail">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path=one\" >blob &&\n"> <"\tblob=$(git hash-object -w blob) &&\n"> <"\ttest_must_fail git config --blob=$blob test.one\n"> ) } ) (C {(test_expect_success)} {(SQ <"absolute includes from stdin work">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo 1 >expect &&\n"> <"\techo \"[include]path=\\\"$(pwd)/one\\\"\" |\n"> <"\tgit config --file - test.one >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_expect_success)} {(SQ <"relative includes from stdin line fail">)} { (SQ <"\n"> <"\techo \"[test]one = 1\" >one &&\n"> <"\techo \"[include]path=one\" |\n"> <"\ttest_must_fail git config --file - test.one\n"> ) } ) (C {(test_expect_success)} {(SQ <"include cycles are detected">)} { (SQ <"\n"> <"\tcat >.gitconfig <<-\\EOF &&\n"> <"\t[test]value = gitconfig\n"> <"\t[include]path = cycle\n"> <"\tEOF\n"> <"\tcat >cycle <<-\\EOF &&\n"> <"\t[test]value = cycle\n"> <"\t[include]path = .gitconfig\n"> <"\tEOF\n"> <"\tcat >expect <<-\\EOF &&\n"> <"\tgitconfig\n"> <"\tcycle\n"> <"\tEOF\n"> <"\ttest_must_fail git config --get-all test.value 2>stderr &&\n"> <"\tgrep \"exceeded maximum include depth\" stderr\n"> ) } ) (C {(test_done)}) ] )