| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='check that read-tree rejects confusing paths' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'create base tree' ' |
| 8 | echo content >file && |
| 9 | git add file && |
| 10 | git commit -m base && |
| 11 | blob=$(git rev-parse HEAD:file) && |
| 12 | tree=$(git rev-parse HEAD^{tree}) |
| 13 | ' |
| 14 | |
| 15 | test_expect_success 'enable core.protectHFS for rejection tests' ' |
| 16 | git config core.protectHFS true |
| 17 | ' |
| 18 | |
| 19 | test_expect_success 'enable core.protectNTFS for rejection tests' ' |
| 20 | git config core.protectNTFS true |
| 21 | ' |
| 22 | |
| 23 | while read path pretty; do |
| 24 | : ${pretty:=$path} |
| 25 | case "$path" in |
| 26 | *SPACE) |
| 27 | path="${path%SPACE} " |
| 28 | ;; |
| 29 | esac |
| 30 | test_expect_success "reject $pretty at end of path" ' |
| 31 | printf "100644 blob %s\t%s" "$blob" "$path" >tree && |
| 32 | bogus=$(git mktree <tree) && |
| 33 | test_must_fail git read-tree $bogus |
| 34 | ' |
| 35 | |
| 36 | test_expect_success "reject $pretty as subtree" ' |
| 37 | printf "040000 tree %s\t%s" "$tree" "$path" >tree && |
| 38 | bogus=$(git mktree <tree) && |
| 39 | test_must_fail git read-tree $bogus |
| 40 | ' |
| 41 | done <<-EOF |
| 42 | . |
| 43 | .. |
| 44 | .git |
| 45 | .GIT |
| 46 | ${u200c}.Git {u200c}.Git |
| 47 | .gI${u200c}T .gI{u200c}T |
| 48 | .GiT${u200c} .GiT{u200c} |
| 49 | git~1 |
| 50 | .git.SPACE .git.{space} |
| 51 | .\\\\.GIT\\\\foobar backslashes |
| 52 | .git\\\\foobar backslashes2 |
| 53 | .git...:alternate-stream |
| 54 | EOF |
| 55 | |
| 56 | test_expect_success 'utf-8 paths allowed with core.protectHFS off' ' |
| 57 | test_when_finished "git read-tree HEAD" && |
| 58 | test_config core.protectHFS false && |
| 59 | printf "100644 blob %s\t%s" "$blob" ".gi${u200c}t" >tree && |
| 60 | ok=$(git mktree <tree) && |
| 61 | git read-tree $ok |
| 62 | ' |
| 63 | |
| 64 | test_done |