Skip to content

Commit 7d5c960

Browse files
peffgitster
authored andcommitted
strbuf_check_ref_format(): expand only local branches
This function asks strbuf_branchname() to expand any @-marks in the branchname, and then we blindly stick refs/heads/ in front of the result. This is obviously nonsense if the expansion is "HEAD" or a ref in refs/remotes/. The most obvious end-user effect is that creating or renaming a branch with an expansion may have confusing results (e.g., creating refs/heads/origin/master from "@{upstream}" when the operation should be disallowed). We can fix this by telling strbuf_branchname() that we are only interested in local expansions. Any unexpanded bits are then fed to check_ref_format(), which either disallows them (in the case of "@{upstream}") or lets them through ("refs/heads/@" is technically valid, if a bit silly). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6b145e0 commit 7d5c960

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

sha1_name.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ void strbuf_branchname(struct strbuf *sb, const char *name, unsigned allowed)
13191319

13201320
int strbuf_check_branch_ref(struct strbuf *sb, const char *name)
13211321
{
1322-
strbuf_branchname(sb, name, 0);
1322+
strbuf_branchname(sb, name, INTERPRET_BRANCH_LOCAL);
13231323
if (name[0] == '-')
13241324
return -1;
13251325
strbuf_splice(sb, 0, 0, "refs/heads/", 11);

t/t3204-branch-name-interpretation.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ test_expect_success 'update branch via local @{upstream}' '
4242
expect_branch local two
4343
'
4444

45-
test_expect_failure 'disallow updating branch via remote @{upstream}' '
45+
test_expect_success 'disallow updating branch via remote @{upstream}' '
4646
git update-ref refs/remotes/origin/remote one &&
4747
git branch --set-upstream-to=origin/remote &&
4848
@@ -109,7 +109,7 @@ test_expect_success 'disallow deleting remote branch via @{-1}' '
109109
# and not refs/heads/HEAD. These tests should not imply that refs/heads/@ is a
110110
# sane thing, but it _is_ technically allowed for now. If we disallow it, these
111111
# can be switched to test_must_fail.
112-
test_expect_failure 'create branch named "@"' '
112+
test_expect_success 'create branch named "@"' '
113113
git branch -f @ one &&
114114
expect_branch refs/heads/@ one
115115
'

0 commit comments

Comments
 (0)