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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Nov 24, 2014 at 13:37 UTC
96b50cc19003d54f5962d65597c94e2c52eb22e7
1 file changed
+32
t/t1014-read-tree-confusing.sh
new
+32
@@ -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