Skip to content

Commit 8faaf69

Browse files
committed
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
2 parents 5502f77 + 04ede97 commit 8faaf69

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

builtin/symbolic-ref.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
7171
if (!strcmp(argv[0], "HEAD") &&
7272
!starts_with(argv[1], "refs/"))
7373
die("Refusing to point HEAD outside of refs/");
74+
if (check_refname_format(argv[1], REFNAME_ALLOW_ONELEVEL) < 0)
75+
die("Refusing to set '%s' to invalid ref '%s'", argv[0], argv[1]);
7476
ret = !!create_symref(argv[0], argv[1], msg);
7577
break;
7678
default:

t/t1401-symbolic-ref.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,14 @@ test_expect_success 'symbolic-ref can resolve d/f name (ENOTDIR)' '
165165
test_cmp expect actual
166166
'
167167

168+
test_expect_success 'symbolic-ref refuses invalid target for non-HEAD' '
169+
test_must_fail git symbolic-ref refs/heads/invalid foo..bar
170+
'
171+
172+
test_expect_success 'symbolic-ref allows top-level target for non-HEAD' '
173+
git symbolic-ref refs/heads/top-level FETCH_HEAD &&
174+
git update-ref FETCH_HEAD HEAD &&
175+
test_cmp_rev top-level HEAD
176+
'
177+
168178
test_done

t/t4202-log.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,9 +2112,9 @@ test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
21122112
test_i18ngrep broken stderr
21132113
'
21142114

2115-
test_expect_success 'log diagnoses bogus HEAD symref' '
2115+
test_expect_success REFFILES 'log diagnoses bogus HEAD symref' '
21162116
git init empty &&
2117-
git --git-dir empty/.git symbolic-ref HEAD refs/heads/invalid.lock &&
2117+
echo "ref: refs/heads/invalid.lock" > empty/.git/HEAD &&
21182118
test_must_fail git -C empty log 2>stderr &&
21192119
test_i18ngrep broken stderr &&
21202120
test_must_fail git -C empty log --default totally-bogus 2>stderr &&

0 commit comments

Comments
 (0)