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