3 test_description
='check handling of .. in submodule names
5 Exercise the name-checking function on a variety of names, and then give a
6 real-world setup that confirms we catch this in practice.
10 test_expect_success
'check names' '
11 cat >expect <<-\EOF &&
16 git submodule--helper check-name >actual <<-\EOF &&
31 test_cmp expect actual
34 test_expect_success
'create innocent subrepo' '
36 git -C innocent commit --allow-empty -m foo
39 test_expect_success
'submodule add refuses invalid names' '
41 git submodule add --name ../../modules/evil "$PWD/innocent" evil
44 test_expect_success
'add evil submodule' '
45 git submodule add "$PWD/innocent" evil &&
48 cp -r .git/modules/evil modules &&
49 write_script modules/evil/hooks/post-checkout <<-\EOF &&
50 echo >&2 "RUNNING POST CHECKOUT"
53 git config -f .gitmodules submodule.evil.update checkout &&
54 git config -f .gitmodules --rename-section \
55 submodule.evil submodule.../../modules/evil &&
60 # This step seems like it shouldn't be necessary, since the payload is
61 # contained entirely in the evil submodule. But due to the vagaries of the
62 # submodule code, checking out the evil module will fail unless ".git/modules"
63 # exists. Adding another submodule (with a name that sorts before "evil") is an
64 # easy way to make sure this is the case in the victim clone.
65 test_expect_success
'add other submodule' '
66 git submodule add "$PWD/innocent" another-module &&
67 git add another-module &&
68 git commit -am another
71 test_expect_success
'clone evil superproject' '
72 git clone --recurse-submodules . victim >output 2>&1 &&
73 ! grep "RUNNING POST CHECKOUT" output
76 test_expect_success MINGW
'prevent git~1 squatting on Windows' '
84 git commit -m initial &&
86 modules="$(test_write_lines \
87 "[submodule \"b.\"]" "url = ." "path = c" \
88 "[submodule \"b\"]" "url = ." "path = d\\\\a" |
89 git hash-object -w --stdin)" &&
90 rev="$(git rev-parse --verify HEAD)" &&
91 hash="$(echo x | git hash-object -w --stdin)" &&
92 git -c core.protectNTFS=false update-index --add \
93 --cacheinfo 100644,$modules,.gitmodules \
94 --cacheinfo 160000,$rev,c \
95 --cacheinfo 160000,$rev,d\\a \
96 --cacheinfo 100644,$hash,d./a/x \
97 --cacheinfo 100644,$hash,d./a/..git &&
99 git -c core.protectNTFS=false commit -m "module" &&
100 test_must_fail git show HEAD: 2>err &&
101 test_i18ngrep backslash err
103 test_must_fail git -c core.protectNTFS=false \
104 clone --recurse-submodules squatting squatting-clone 2>err &&
105 test_i18ngrep "directory not empty" err &&
106 ! grep gitdir squatting-clone/d/a/git~2
109 test_expect_success
'git dirs of sibling submodules must not be nested' '
111 test_commit -C nested nested &&
114 cat >.gitmodules <<-EOF &&
118 [submodule "hippo/hooks"]
122 git clone . thing1 &&
123 git clone . thing2 &&
124 git add .gitmodules thing1 thing2 &&
128 test_must_fail git clone --recurse-submodules nested clone 2>err &&
129 test_i18ngrep "is inside git dir" err