Skip to content

Commit 96b50cc

Browse files
peffgitster
authored andcommitted
read-tree: add tests for confusing paths like ".." and ".git"
We should prevent nonsense paths from entering the index in the first place, as they can cause confusing results if they are ever checked out into the working tree. We already do so, but we never tested it. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4616918 commit 96b50cc

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

t/t1014-read-tree-confusing.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
test_description='check that read-tree rejects confusing paths'
4+
. ./test-lib.sh
5+
6+
test_expect_success 'create base tree' '
7+
echo content >file &&
8+
git add file &&
9+
git commit -m base &&
10+
blob=$(git rev-parse HEAD:file) &&
11+
tree=$(git rev-parse HEAD^{tree})
12+
'
13+
14+
while read path; do
15+
test_expect_success "reject $path at end of path" '
16+
printf "100644 blob %s\t%s" "$blob" "$path" >tree &&
17+
bogus=$(git mktree <tree) &&
18+
test_must_fail git read-tree $bogus
19+
'
20+
21+
test_expect_success "reject $path as subtree" '
22+
printf "040000 tree %s\t%s" "$tree" "$path" >tree &&
23+
bogus=$(git mktree <tree) &&
24+
test_must_fail git read-tree $bogus
25+
'
26+
done <<-\EOF
27+
.
28+
..
29+
.git
30+
EOF
31+
32+
test_done

0 commit comments

Comments
 (0)