]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7416-submodule-dash-url.sh
fsck: convert gitmodules url to URL passed to curl
[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 'create submodule with protected dash in url' '
7 git init upstream &&
8 git -C upstream commit --allow-empty -m base &&
9 mv upstream ./-upstream &&
10 git submodule add ./-upstream sub &&
11 git add sub .gitmodules &&
12 git commit -m submodule
13 '
14
15 test_expect_success 'clone can recurse submodule' '
16 test_when_finished "rm -rf dst" &&
17 git clone --recurse-submodules . dst &&
18 echo base >expect &&
19 git -C dst/sub log -1 --format=%s >actual &&
20 test_cmp expect actual
21 '
22
23 test_expect_success 'fsck accepts protected dash' '
24 test_when_finished "rm -rf dst" &&
25 git init --bare dst &&
26 git -C dst config transfer.fsckObjects true &&
27 git push dst HEAD
28 '
29
30 test_expect_success 'remove ./ protection from .gitmodules url' '
31 perl -i -pe "s{\./}{}" .gitmodules &&
32 git commit -am "drop protection"
33 '
34
35 test_expect_success 'clone rejects unprotected dash' '
36 test_when_finished "rm -rf dst" &&
37 test_must_fail git clone --recurse-submodules . dst 2>err &&
38 test_i18ngrep ignoring err
39 '
40
41 test_expect_success 'fsck rejects unprotected dash' '
42 test_when_finished "rm -rf dst" &&
43 git init --bare dst &&
44 git -C dst config transfer.fsckObjects true &&
45 test_must_fail git push dst HEAD 2>err &&
46 grep gitmodulesUrl err
47 '
48
49 test_expect_success 'trailing backslash is handled correctly' '
50 git init testmodule &&
51 test_commit -C testmodule c &&
52 git submodule add ./testmodule &&
53 : ensure that the name ends in a double backslash &&
54 sed -e "s|\\(submodule \"testmodule\\)\"|\\1\\\\\\\\\"|" \
55 -e "s|url = .*|url = \" --should-not-be-an-option\"|" \
56 <.gitmodules >.new &&
57 mv .new .gitmodules &&
58 git commit -am "Add testmodule" &&
59 test_must_fail git clone --verbose --recurse-submodules . dolly 2>err &&
60 test_i18ngrep ! "unknown option" err
61 '
62
63 test_expect_success 'fsck permits embedded newline with unrecognized scheme' '
64 git checkout --orphan newscheme &&
65 cat >.gitmodules <<-\EOF &&
66 [submodule "foo"]
67 url = "data://acjbkd%0akajfdickajkd"
68 EOF
69 git add .gitmodules &&
70 git commit -m "gitmodules with unrecognized scheme" &&
71 test_when_finished "rm -rf dst" &&
72 git init --bare dst &&
73 git -C dst config transfer.fsckObjects true &&
74 git push dst HEAD
75 '
76
77 test_expect_success 'fsck rejects embedded newline in url' '
78 # create an orphan branch to avoid existing .gitmodules objects
79 git checkout --orphan newline &&
80 cat >.gitmodules <<-\EOF &&
81 [submodule "foo"]
82 url = "https://one.example.com?%0ahost=two.example.com/foo.git"
83 EOF
84 git add .gitmodules &&
85 git commit -m "gitmodules with newline" &&
86 test_when_finished "rm -rf dst" &&
87 git init --bare dst &&
88 git -C dst config transfer.fsckObjects true &&
89 test_must_fail git push dst HEAD 2>err &&
90 grep gitmodulesUrl err
91 '
92
93 test_expect_success 'fsck rejects embedded newline in relative url' '
94 git checkout --orphan relative-newline &&
95 cat >.gitmodules <<-\EOF &&
96 [submodule "foo"]
97 url = "./%0ahost=two.example.com/foo.git"
98 EOF
99 git add .gitmodules &&
100 git commit -m "relative url with newline" &&
101 test_when_finished "rm -rf dst" &&
102 git init --bare dst &&
103 git -C dst config transfer.fsckObjects true &&
104 test_must_fail git push dst HEAD 2>err &&
105 grep gitmodulesUrl err
106 '
107
108 test_done