summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-08-12 20:19:07 (GMT)
committerJunio C Hamano <gitster@pobox.com>2022-08-12 20:19:08 (GMT)
commit8faaf690f7174a9b56438788308de4fa195893e2 (patch)
tree578b0a325694973abf3d1f766b6712fea55407c5
parent5502f77b6944eda8e26813d8f542cffe7d110aea (diff)
parent04ede97211c132f4d71c96c61f5124cbb3ebdc77 (diff)
downloadgit-8faaf690f7174a9b56438788308de4fa195893e2.zip
git-8faaf690f7174a9b56438788308de4fa195893e2.tar.gz
git-8faaf690f7174a9b56438788308de4fa195893e2.tar.bz2
Merge branch 'lt/symbolic-ref-sanity'
"git symbolic-ref symref non..sen..se" is now diagnosed as an error. * lt/symbolic-ref-sanity: symbolic-ref: refuse to set syntactically invalid target
-rw-r--r--builtin/symbolic-ref.c2
-rwxr-xr-xt/t1401-symbolic-ref.sh10
-rwxr-xr-xt/t4202-log.sh4
3 files changed, 14 insertions, 2 deletions
diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c
index e547a08..1b0f102 100644
--- a/builtin/symbolic-ref.c
+++ b/builtin/symbolic-ref.c
@@ -71,6 +71,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
if (!strcmp(argv[0], "HEAD") &&
!starts_with(argv[1], "refs/"))
die("Refusing to point HEAD outside of refs/");
+ if (check_refname_format(argv[1], REFNAME_ALLOW_ONELEVEL) < 0)
+ die("Refusing to set '%s' to invalid ref '%s'", argv[0], argv[1]);
ret = !!create_symref(argv[0], argv[1], msg);
break;
default:
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index 9fb0b90..0c20408 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -165,4 +165,14 @@ test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' '
test_cmp expect actual
'
+test_expect_success 'symbolic-ref refuses invalid target for non-HEAD' '
+ test_must_fail git symbolic-ref refs/heads/invalid foo..bar
+'
+
+test_expect_success 'symbolic-ref allows top-level target for non-HEAD' '
+ git symbolic-ref refs/heads/top-level FETCH_HEAD &&
+ git update-ref FETCH_HEAD HEAD &&
+ test_cmp_rev top-level HEAD
+'
+
test_done
diff --git a/t/t4202-log.sh b/t/t4202-log.sh
index 6e66352..f0aaa1f 100755
--- a/t/t4202-log.sh
+++ b/t/t4202-log.sh
@@ -2112,9 +2112,9 @@ test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
test_i18ngrep broken stderr
'
-test_expect_success 'log diagnoses bogus HEAD symref' '
+test_expect_success REFFILES 'log diagnoses bogus HEAD symref' '
git init empty &&
- git --git-dir empty/.git symbolic-ref HEAD refs/heads/invalid.lock &&
+ echo "ref: refs/heads/invalid.lock" > empty/.git/HEAD &&
test_must_fail git -C empty log 2>stderr &&
test_i18ngrep broken stderr &&
test_must_fail git -C empty log --default totally-bogus 2>stderr &&