aboutsummaryrefslogtreecommitdiff
path: root/t/t1401-symbolic-ref.sh
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-09-24 17:07:22 -0400
committerJunio C Hamano <gitster@pobox.com>2015-09-25 10:18:18 -0700
commit495127dbcbd53e89d7edee8db42bfa7e57c8a120 (patch)
treea72a2916db245c5862ee09843059886b9f673b8c /t/t1401-symbolic-ref.sh
parent0e265a92a1d2b9275d638f696c65c9bbe747e78c (diff)
downloadgit-495127dbcbd53e89d7edee8db42bfa7e57c8a120.tar.gz
git-495127dbcbd53e89d7edee8db42bfa7e57c8a120.tar.xz
resolve_ref: use strbufs for internal buffers
resolve_ref already uses a strbuf internally when generating pathnames, but it uses fixed-size buffers for storing the refname and symbolic refs. This means that you cannot actually point HEAD to a ref that is larger than 256 bytes. We can lift this limit by using strbufs here, too. Like sb_path, we pass the the buffers into our helper function, so that we can easily clean up all output paths. We can also drop the "unsafe" name from our helper function, as it no longer uses a single static buffer (but of course resolve_ref_unsafe is still unsafe, because the static buffers moved there). As a bonus, we also get to drop some strcpy calls between the two fixed buffers (that cannot currently overflow because the two buffers are sized identically). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t1401-symbolic-ref.sh')
-rwxr-xr-xt/t1401-symbolic-ref.sh29
1 files changed, 29 insertions, 0 deletions
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index 36378b0e3..20b022ae3 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -63,4 +63,33 @@ test_expect_success 'symbolic-ref fails to delete real ref' '
'
reset_to_sane
+test_expect_success 'create large ref name' '
+ # make 256+ character ref; some systems may not handle that,
+ # so be gentle
+ long=0123456789abcdef &&
+ long=$long/$long/$long/$long &&
+ long=$long/$long/$long/$long &&
+ long_ref=refs/heads/$long &&
+ tree=$(git write-tree) &&
+ commit=$(echo foo | git commit-tree $tree) &&
+ if git update-ref $long_ref $commit; then
+ test_set_prereq LONG_REF
+ else
+ echo >&2 "long refs not supported"
+ fi
+'
+
+test_expect_success LONG_REF 'symbolic-ref can point to large ref name' '
+ git symbolic-ref HEAD $long_ref &&
+ echo $long_ref >expect &&
+ git symbolic-ref HEAD >actual &&
+ test_cmp expect actual
+'
+
+test_expect_success LONG_REF 'we can parse long symbolic ref' '
+ echo $commit >expect &&
+ git rev-parse --verify HEAD >actual &&
+ test_cmp expect actual
+'
+
test_done