Imported Upstream version 2.10.0
[platform/upstream/git.git] / t / t7411-submodule-config.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2014 Heiko Voigt
4 #
5
6 test_description='Test submodules config cache infrastructure
7
8 This test verifies that parsing .gitmodules configurations directly
9 from the database and from the worktree works.
10 '
11
12 TEST_NO_CREATE_REPO=1
13 . ./test-lib.sh
14
15 test_expect_success 'submodule config cache setup' '
16         mkdir submodule &&
17         (cd submodule &&
18                 git init &&
19                 echo a >a &&
20                 git add . &&
21                 git commit -ma
22         ) &&
23         mkdir super &&
24         (cd super &&
25                 git init &&
26                 git submodule add ../submodule &&
27                 git submodule add ../submodule a &&
28                 git commit -m "add as submodule and as a" &&
29                 git mv a b &&
30                 git commit -m "move a to b"
31         )
32 '
33
34 cat >super/expect <<EOF
35 Submodule name: 'a' for path 'a'
36 Submodule name: 'a' for path 'b'
37 Submodule name: 'submodule' for path 'submodule'
38 Submodule name: 'submodule' for path 'submodule'
39 EOF
40
41 test_expect_success 'test parsing and lookup of submodule config by path' '
42         (cd super &&
43                 test-submodule-config \
44                         HEAD^ a \
45                         HEAD b \
46                         HEAD^ submodule \
47                         HEAD submodule \
48                                 >actual &&
49                 test_cmp expect actual
50         )
51 '
52
53 test_expect_success 'test parsing and lookup of submodule config by name' '
54         (cd super &&
55                 test-submodule-config --name \
56                         HEAD^ a \
57                         HEAD a \
58                         HEAD^ submodule \
59                         HEAD submodule \
60                                 >actual &&
61                 test_cmp expect actual
62         )
63 '
64
65 cat >super/expect_error <<EOF
66 Submodule name: 'a' for path 'b'
67 Submodule name: 'submodule' for path 'submodule'
68 EOF
69
70 test_expect_success 'error in one submodule config lets continue' '
71         (cd super &&
72                 cp .gitmodules .gitmodules.bak &&
73                 echo "  value = \"" >>.gitmodules &&
74                 git add .gitmodules &&
75                 mv .gitmodules.bak .gitmodules &&
76                 git commit -m "add error" &&
77                 test-submodule-config \
78                         HEAD b \
79                         HEAD submodule \
80                                 >actual &&
81                 test_cmp expect_error actual
82         )
83 '
84
85 test_expect_success 'error message contains blob reference' '
86         (cd super &&
87                 sha1=$(git rev-parse HEAD) &&
88                 test-submodule-config \
89                         HEAD b \
90                         HEAD submodule \
91                                 2>actual_err &&
92                 test_i18ngrep "submodule-blob $sha1:.gitmodules" actual_err >/dev/null
93         )
94 '
95
96 cat >super/expect_url <<EOF
97 Submodule url: 'git@somewhere.else.net:a.git' for path 'b'
98 Submodule url: 'git@somewhere.else.net:submodule.git' for path 'submodule'
99 EOF
100
101 cat >super/expect_local_path <<EOF
102 Submodule name: 'a' for path 'c'
103 Submodule name: 'submodule' for path 'submodule'
104 EOF
105
106 test_expect_success 'reading of local configuration' '
107         (cd super &&
108                 old_a=$(git config submodule.a.url) &&
109                 old_submodule=$(git config submodule.submodule.url) &&
110                 git config submodule.a.url git@somewhere.else.net:a.git &&
111                 git config submodule.submodule.url git@somewhere.else.net:submodule.git &&
112                 test-submodule-config --url \
113                         "" b \
114                         "" submodule \
115                                 >actual &&
116                 test_cmp expect_url actual &&
117                 git config submodule.a.path c &&
118                 test-submodule-config \
119                         "" c \
120                         "" submodule \
121                                 >actual &&
122                 test_cmp expect_local_path actual &&
123                 git config submodule.a.url $old_a &&
124                 git config submodule.submodule.url $old_submodule &&
125                 git config --unset submodule.a.path c
126         )
127 '
128
129 cat >super/expect_fetchrecurse_die.err <<EOF
130 fatal: bad submodule.submodule.fetchrecursesubmodules argument: blabla
131 EOF
132
133 test_expect_success 'local error in fetchrecursesubmodule dies early' '
134         (cd super &&
135                 git config submodule.submodule.fetchrecursesubmodules blabla &&
136                 test_must_fail test-submodule-config \
137                         "" b \
138                         "" submodule \
139                                 >actual.out 2>actual.err &&
140                 touch expect_fetchrecurse_die.out &&
141                 test_cmp expect_fetchrecurse_die.out actual.out  &&
142                 test_cmp expect_fetchrecurse_die.err actual.err  &&
143                 git config --unset submodule.submodule.fetchrecursesubmodules
144         )
145 '
146
147 test_expect_success 'error in history in fetchrecursesubmodule lets continue' '
148         (cd super &&
149                 git config -f .gitmodules \
150                         submodule.submodule.fetchrecursesubmodules blabla &&
151                 git add .gitmodules &&
152                 git config --unset -f .gitmodules \
153                         submodule.submodule.fetchrecursesubmodules &&
154                 git commit -m "add error in fetchrecursesubmodules" &&
155                 test-submodule-config \
156                         HEAD b \
157                         HEAD submodule \
158                                 >actual &&
159                 test_cmp expect_error actual  &&
160                 git reset --hard HEAD^
161         )
162 '
163
164 test_done