1#!/bin/sh
2#
3# Copyright (c) 2014 Heiko Voigt
4#
56
test_description='Test submodules config cache infrastructure
78
This test verifies that parsing .gitmodules configurations directly
9from the database and from the worktree works.
10'
1112
TEST_NO_CREATE_REPO=1
13. ./test-lib.sh
1415
test_expect_success 'submodule config cache setup' '
16mkdir submodule &&
17(cd submodule &&
18git init &&
19echo a >a &&
20git add . &&
21git commit -ma
22) &&
23mkdir super &&
24(cd super &&
25git init &&
26git submodule add ../submodule &&
27git submodule add ../submodule a &&
28git commit -m "add as submodule and as a" &&
29git mv a b &&
30git commit -m "move a to b"
31)
32'
3334
test_expect_success 'configuration parsing with error' '
35test_when_finished "rm -rf repo" &&
36test_create_repo repo &&
37cat >repo/.gitmodules <<-\EOF &&
38[submodule "s"]
39path
40ignore
41EOF
42(
43cd repo &&
44test_must_fail test-tool submodule-config "" s 2>actual &&
45test_i18ngrep "bad config" actual
46)
47'
4849
cat >super/expect <<EOF
50Submodule name: 'a' for path 'a'
51Submodule name: 'a' for path 'b'
52Submodule name: 'submodule' for path 'submodule'
53Submodule name: 'submodule' for path 'submodule'
54EOF
5556
test_expect_success 'test parsing and lookup of submodule config by path' '
57(cd super &&
58test-tool submodule-config \
59HEAD^ a \
60HEAD b \
61HEAD^ submodule \
62HEAD submodule \
63>actual &&
64test_cmp expect actual
65)
66'
6768
test_expect_success 'test parsing and lookup of submodule config by name' '
69(cd super &&
70test-tool submodule-config --name \
71HEAD^ a \
72HEAD a \
73HEAD^ submodule \
74HEAD submodule \
75>actual &&
76test_cmp expect actual
77)
78'
7980
cat >super/expect_error <<EOF
81Submodule name: 'a' for path 'b'
82Submodule name: 'submodule' for path 'submodule'
83EOF
8485
test_expect_success 'error in history of one submodule config lets continue, stderr message contains blob ref' '
86ORIG=$(git -C super rev-parse HEAD) &&
87test_when_finished "git -C super reset --hard $ORIG" &&
88(cd super &&
89cp .gitmodules .gitmodules.bak &&
90echo " value = \"" >>.gitmodules &&
91git add .gitmodules &&
92mv .gitmodules.bak .gitmodules &&
93git commit -m "add error" &&
94sha1=$(git rev-parse HEAD) &&
95test-tool submodule-config \
96HEAD b \
97HEAD submodule \
98>actual \
992>actual_stderr &&
100test_cmp expect_error actual &&
101test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_stderr >/dev/null
102)
103'
104105
test_expect_success 'using different treeishs works' '
106(
107cd super &&
108git tag new_tag &&
109tree=$(git rev-parse HEAD^{tree}) &&
110commit=$(git rev-parse HEAD^{commit}) &&
111test-tool submodule-config $commit b >expect &&
112test-tool submodule-config $tree b >actual.1 &&
113test-tool submodule-config new_tag b >actual.2 &&
114test_cmp expect actual.1 &&
115test_cmp expect actual.2
116)
117'
118119
test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
120ORIG=$(git -C super rev-parse HEAD) &&
121test_when_finished "git -C super reset --hard $ORIG" &&
122(cd super &&
123git config -f .gitmodules \
124submodule.submodule.fetchrecursesubmodules blabla &&
125git add .gitmodules &&
126git config --unset -f .gitmodules \
127submodule.submodule.fetchrecursesubmodules &&
128git commit -m "add error in fetchrecursesubmodules" &&
129test-tool submodule-config \
130HEAD b \
131HEAD submodule \
132>actual &&
133test_cmp expect_error actual
134)
135'
136137
test_expect_success 'reading submodules config with "submodule--helper config"' '
138(cd super &&
139echo "../submodule" >expect &&
140git submodule--helper config submodule.submodule.url >actual &&
141test_cmp expect actual
142)
143'
144145
test_expect_success 'writing submodules config with "submodule--helper config"' '
146(cd super &&
147echo "new_url" >expect &&
148git submodule--helper config submodule.submodule.url "new_url" &&
149git submodule--helper config submodule.submodule.url >actual &&
150test_cmp expect actual
151)
152'
153154
test_expect_success 'overwriting unstaged submodules config with "submodule--helper config"' '
155test_when_finished "git -C super checkout .gitmodules" &&
156(cd super &&
157echo "newer_url" >expect &&
158git submodule--helper config submodule.submodule.url "newer_url" &&
159git submodule--helper config submodule.submodule.url >actual &&
160test_cmp expect actual
161)
162'
163164
test_done