Skip to content

Commit

Permalink
t1430: add another refs-escape test
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Apr 16, 2015
1 parent 03afcbe commit a337292
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions t/t1430-bad-ref-name.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@ test_expect_success 'branch -D cannot delete non-ref in .git dir' '
test_cmp expect .git/my-private-file
'

test_expect_success 'branch -D cannot delete ref in .git dir' '
git rev-parse HEAD >.git/my-private-file &&
git rev-parse HEAD >expect &&
git branch foo/legit &&
test_must_fail git branch -D foo////./././../../../my-private-file &&
test_cmp expect .git/my-private-file
'

test_expect_success 'branch -D cannot delete absolute path' '
git branch -f extra &&
test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" &&
Expand Down

0 comments on commit a337292

Please sign in to comment.