]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7416-submodule-dash-url.sh
git-config: fix misworded --type=path explanation
[thirdparty/git.git] / t / t7416-submodule-dash-url.sh
1 #!/bin/sh
2
3 test_description='check handling of disallowed .gitmodule urls'
4 . ./test-lib.sh
5
6 test_expect_success 'setup' '
7 git config --global protocol.file.allow always
8 '
9
10 test_expect_success 'create submodule with protected dash in url' '
11 git init upstream &&
12 git -C upstream commit --allow-empty -m base &&
13 mv upstream ./-upstream &&
14 git submodule add ./-upstream sub &&
15 git add sub .gitmodules &&
16 git commit -m submodule
17 '
18
19 test_expect_success 'clone can recurse submodule' '
20 test_when_finished "rm -rf dst" &&
21 git clone --recurse-submodules . dst &&
22 echo base >expect &&
23 git -C dst/sub log -1 --format=%s >actual &&
24 test_cmp expect actual
25 '
26
27 test_expect_success 'fsck accepts protected dash' '
28 test_when_finished "rm -rf dst" &&
29 git init --bare dst &&
30 git -C dst config transfer.fsckObjects true &&
31 git push dst HEAD
32 '
33
34 test_expect_success 'remove ./ protection from .gitmodules url' '
35 perl -i -pe "s{\./}{}" .gitmodules &&
36 git commit -am "drop protection"
37 '
38
39 test_expect_success 'clone rejects unprotected dash' '
40 test_when_finished "rm -rf dst" &&
41 test_must_fail git clone --recurse-submodules . dst 2>err &&
42 test_i18ngrep ignoring err
43 '
44
45 test_expect_success 'fsck rejects unprotected dash' '
46 test_when_finished "rm -rf dst" &&
47 git init --bare dst &&
48 git -C dst config transfer.fsckObjects true &&
49 test_must_fail git push dst HEAD 2>err &&
50 grep gitmodulesUrl err
51 '
52
53 test_expect_success 'trailing backslash is handled correctly' '
54 git init testmodule &&
55 test_commit -C testmodule c &&
56 git submodule add ./testmodule &&
57 : ensure that the name ends in a double backslash &&
58 sed -e "s|\\(submodule \"testmodule\\)\"|\\1\\\\\\\\\"|" \
59 -e "s|url = .*|url = \" --should-not-be-an-option\"|" \
60 <.gitmodules >.new &&
61 mv .new .gitmodules &&
62 git commit -am "Add testmodule" &&
63 test_must_fail git clone --verbose --recurse-submodules . dolly 2>err &&
64 test_i18ngrep ! "unknown option" err
65 '
66
67 test_expect_success 'fsck rejects missing URL scheme' '
68 git checkout --orphan missing-scheme &&
69 cat >.gitmodules <<-\EOF &&
70 [submodule "foo"]
71 url = http::one.example.com/foo.git
72 EOF
73 git add .gitmodules &&
74 test_tick &&
75 git commit -m "gitmodules with missing URL scheme" &&
76 test_when_finished "rm -rf dst" &&
77 git init --bare dst &&
78 git -C dst config transfer.fsckObjects true &&
79 test_must_fail git push dst HEAD 2>err &&
80 grep gitmodulesUrl err
81 '
82
83 test_expect_success 'fsck rejects relative URL resolving to missing scheme' '
84 git checkout --orphan relative-missing-scheme &&
85 cat >.gitmodules <<-\EOF &&
86 [submodule "foo"]
87 url = "..\\../.\\../:one.example.com/foo.git"
88 EOF
89 git add .gitmodules &&
90 test_tick &&
91 git commit -m "gitmodules with relative URL that strips off scheme" &&
92 test_when_finished "rm -rf dst" &&
93 git init --bare dst &&
94 git -C dst config transfer.fsckObjects true &&
95 test_must_fail git push dst HEAD 2>err &&
96 grep gitmodulesUrl err
97 '
98
99 test_expect_success 'fsck rejects empty URL scheme' '
100 git checkout --orphan empty-scheme &&
101 cat >.gitmodules <<-\EOF &&
102 [submodule "foo"]
103 url = http::://one.example.com/foo.git
104 EOF
105 git add .gitmodules &&
106 test_tick &&
107 git commit -m "gitmodules with empty URL scheme" &&
108 test_when_finished "rm -rf dst" &&
109 git init --bare dst &&
110 git -C dst config transfer.fsckObjects true &&
111 test_must_fail git push dst HEAD 2>err &&
112 grep gitmodulesUrl err
113 '
114
115 test_expect_success 'fsck rejects relative URL resolving to empty scheme' '
116 git checkout --orphan relative-empty-scheme &&
117 cat >.gitmodules <<-\EOF &&
118 [submodule "foo"]
119 url = ../../../:://one.example.com/foo.git
120 EOF
121 git add .gitmodules &&
122 test_tick &&
123 git commit -m "relative gitmodules URL resolving to empty scheme" &&
124 test_when_finished "rm -rf dst" &&
125 git init --bare dst &&
126 git -C dst config transfer.fsckObjects true &&
127 test_must_fail git push dst HEAD 2>err &&
128 grep gitmodulesUrl err
129 '
130
131 test_expect_success 'fsck rejects empty hostname' '
132 git checkout --orphan empty-host &&
133 cat >.gitmodules <<-\EOF &&
134 [submodule "foo"]
135 url = http:///one.example.com/foo.git
136 EOF
137 git add .gitmodules &&
138 test_tick &&
139 git commit -m "gitmodules with extra slashes" &&
140 test_when_finished "rm -rf dst" &&
141 git init --bare dst &&
142 git -C dst config transfer.fsckObjects true &&
143 test_must_fail git push dst HEAD 2>err &&
144 grep gitmodulesUrl err
145 '
146
147 test_expect_success 'fsck rejects relative url that produced empty hostname' '
148 git checkout --orphan messy-relative &&
149 cat >.gitmodules <<-\EOF &&
150 [submodule "foo"]
151 url = ../../..//one.example.com/foo.git
152 EOF
153 git add .gitmodules &&
154 test_tick &&
155 git commit -m "gitmodules abusing relative_path" &&
156 test_when_finished "rm -rf dst" &&
157 git init --bare dst &&
158 git -C dst config transfer.fsckObjects true &&
159 test_must_fail git push dst HEAD 2>err &&
160 grep gitmodulesUrl err
161 '
162
163 test_expect_success 'fsck permits embedded newline with unrecognized scheme' '
164 git checkout --orphan newscheme &&
165 cat >.gitmodules <<-\EOF &&
166 [submodule "foo"]
167 url = "data://acjbkd%0akajfdickajkd"
168 EOF
169 git add .gitmodules &&
170 git commit -m "gitmodules with unrecognized scheme" &&
171 test_when_finished "rm -rf dst" &&
172 git init --bare dst &&
173 git -C dst config transfer.fsckObjects true &&
174 git push dst HEAD
175 '
176
177 test_expect_success 'fsck rejects embedded newline in url' '
178 # create an orphan branch to avoid existing .gitmodules objects
179 git checkout --orphan newline &&
180 cat >.gitmodules <<-\EOF &&
181 [submodule "foo"]
182 url = "https://one.example.com?%0ahost=two.example.com/foo.git"
183 EOF
184 git add .gitmodules &&
185 git commit -m "gitmodules with newline" &&
186 test_when_finished "rm -rf dst" &&
187 git init --bare dst &&
188 git -C dst config transfer.fsckObjects true &&
189 test_must_fail git push dst HEAD 2>err &&
190 grep gitmodulesUrl err
191 '
192
193 test_expect_success 'fsck rejects embedded newline in relative url' '
194 git checkout --orphan relative-newline &&
195 cat >.gitmodules <<-\EOF &&
196 [submodule "foo"]
197 url = "./%0ahost=two.example.com/foo.git"
198 EOF
199 git add .gitmodules &&
200 git commit -m "relative url with newline" &&
201 test_when_finished "rm -rf dst" &&
202 git init --bare dst &&
203 git -C dst config transfer.fsckObjects true &&
204 test_must_fail git push dst HEAD 2>err &&
205 grep gitmodulesUrl err
206 '
207
208 test_expect_success 'fsck rejects embedded newline in git url' '
209 git checkout --orphan git-newline &&
210 cat >.gitmodules <<-\EOF &&
211 [submodule "foo"]
212 url = "git://example.com:1234/repo%0a.git"
213 EOF
214 git add .gitmodules &&
215 git commit -m "git url with newline" &&
216 test_when_finished "rm -rf dst" &&
217 git init --bare dst &&
218 git -C dst config transfer.fsckObjects true &&
219 test_must_fail git push dst HEAD 2>err &&
220 grep gitmodulesUrl err
221 '
222
223 test_done