3 # Copyright (c) 2014 Heiko Voigt
6 test_description
='Test submodules config cache infrastructure
8 This test verifies that parsing .gitmodules configurations directly
9 from the database and from the worktree works.
15 test_expect_success
'submodule config cache setup' '
26 git submodule add ../submodule &&
27 git submodule add ../submodule a &&
28 git commit -m "add as submodule and as a" &&
30 git commit -m "move a to b"
34 test_expect_success
'configuration parsing with error' '
35 test_when_finished "rm -rf repo" &&
36 test_create_repo repo &&
37 cat >repo/.gitmodules <<-\EOF &&
44 test_must_fail test-tool submodule-config "" s 2>actual &&
45 test_i18ngrep "bad config" actual
49 cat >super
/expect
<<EOF
50 Submodule name: 'a' for path 'a'
51 Submodule name: 'a' for path 'b'
52 Submodule name: 'submodule' for path 'submodule'
53 Submodule name: 'submodule' for path 'submodule'
56 test_expect_success
'test parsing and lookup of submodule config by path' '
58 test-tool submodule-config \
64 test_cmp expect actual
68 test_expect_success
'test parsing and lookup of submodule config by name' '
70 test-tool submodule-config --name \
76 test_cmp expect actual
80 cat >super
/expect_error
<<EOF
81 Submodule name: 'a' for path 'b'
82 Submodule name: 'submodule' for path 'submodule'
85 test_expect_success
'error in history of one submodule config lets continue, stderr message contains blob ref' '
86 ORIG=$(git -C super rev-parse HEAD) &&
87 test_when_finished "git -C super reset --hard $ORIG" &&
89 cp .gitmodules .gitmodules.bak &&
90 echo " value = \"" >>.gitmodules &&
91 git add .gitmodules &&
92 mv .gitmodules.bak .gitmodules &&
93 git commit -m "add error" &&
94 sha1=$(git rev-parse HEAD) &&
95 test-tool submodule-config \
100 test_cmp expect_error actual &&
101 test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
105 test_expect_success
'using different treeishs works' '
109 tree=$(git rev-parse HEAD^{tree}) &&
110 commit=$(git rev-parse HEAD^{commit}) &&
111 test-tool submodule-config $commit b >expect &&
112 test-tool submodule-config $tree b >actual.1 &&
113 test-tool submodule-config new_tag b >actual.2 &&
114 test_cmp expect actual.1 &&
115 test_cmp expect actual.2
119 test_expect_success
'error in history in fetchrecursesubmodule lets continue' '
120 ORIG=$(git -C super rev-parse HEAD) &&
121 test_when_finished "git -C super reset --hard $ORIG" &&
123 git config -f .gitmodules \
124 submodule.submodule.fetchrecursesubmodules blabla &&
125 git add .gitmodules &&
126 git config --unset -f .gitmodules \
127 submodule.submodule.fetchrecursesubmodules &&
128 git commit -m "add error in fetchrecursesubmodules" &&
129 test-tool submodule-config \
133 test_cmp expect_error actual
137 test_expect_success
'reading submodules config with "submodule--helper config"' '
139 echo "../submodule" >expect &&
140 git submodule--helper config submodule.submodule.url >actual &&
141 test_cmp expect actual
145 test_expect_success
'writing submodules config with "submodule--helper config"' '
147 echo "new_url" >expect &&
148 git submodule--helper config submodule.submodule.url "new_url" &&
149 git submodule--helper config submodule.submodule.url >actual &&
150 test_cmp expect actual
154 test_expect_success
'overwriting unstaged submodules config with "submodule--helper config"' '
155 test_when_finished "git -C super checkout .gitmodules" &&
157 echo "newer_url" >expect &&
158 git submodule--helper config submodule.submodule.url "newer_url" &&
159 git submodule--helper config submodule.submodule.url >actual &&
160 test_cmp expect actual