Skip to content

Commit a337292

Browse files
peffgitster
authored andcommitted
t1430: add another refs-escape test
In t1430, we check whether deleting the branch "../../foo" will delete ".git/foo". However, this is not that interesting a test; the precious file ".git/foo" does not look like a ref, so even if we did not notice the "escape" from the "refs/" hierarchy, we would fail for that reason (i.e., if you turned refname_is_safe into a noop, the test still passes). Let's add an additional test for the same thing, but with a file that actually looks like a ref. That will make sure we are exercising the refname_is_safe code. While we're at it, let's also make the code work a little harder by adding some extra paths and some empty path components. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03afcbe commit a337292

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

t/t1430-bad-ref-name.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ test_expect_success 'branch -D cannot delete non-ref in .git dir' '
6868
test_cmp expect .git/my-private-file
6969
'
7070

71+
test_expect_success 'branch -D cannot delete ref in .git dir' '
72+
git rev-parse HEAD >.git/my-private-file &&
73+
git rev-parse HEAD >expect &&
74+
git branch foo/legit &&
75+
test_must_fail git branch -D foo////./././../../../my-private-file &&
76+
test_cmp expect .git/my-private-file
77+
'
78+
7179
test_expect_success 'branch -D cannot delete absolute path' '
7280
git branch -f extra &&
7381
test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" &&

0 commit comments

Comments
 (0)