Skip to content

Commit f1dfbd9

Browse files
chooglengitster
authored andcommitted
remote.c: reject 0-length branch names
Branch names can't be empty, so config keys with an empty branch name, e.g. "branch..remote", are silently ignored. Since these config keys will never be useful, make it a fatal error when remote.c finds a key that starts with "branch." and has an empty subsection. Signed-off-by: Glen Choo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 91e2e8f commit f1dfbd9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

remote.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,12 @@ static int handle_config(const char *key, const char *value, void *cb)
352352
struct remote_state *remote_state = cb;
353353

354354
if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
355+
/* There is no subsection. */
355356
if (!name)
356357
return 0;
358+
/* There is a subsection, but it is empty. */
359+
if (!namelen)
360+
return -1;
357361
branch = make_branch(remote_state, name, namelen);
358362
if (!strcmp(subkey, "remote")) {
359363
return git_config_string(&branch->remote_name, key, value);

t/t5516-fetch-push.sh

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,13 +602,23 @@ test_expect_success 'branch.*.pushremote config order is irrelevant' '
602602
check_push_result two_repo $the_commit heads/main
603603
'
604604

605-
test_expect_success 'push ignores empty branch name entries' '
605+
test_expect_success 'push rejects empty branch name entries' '
606606
mk_test one_repo heads/main &&
607607
test_config remote.one.url one_repo &&
608608
test_config branch..remote one &&
609609
test_config branch..merge refs/heads/ &&
610610
test_config branch.main.remote one &&
611611
test_config branch.main.merge refs/heads/main &&
612+
test_must_fail git push 2>err &&
613+
grep "bad config variable .branch\.\." err
614+
'
615+
616+
test_expect_success 'push ignores "branch." config without subsection' '
617+
mk_test one_repo heads/main &&
618+
test_config remote.one.url one_repo &&
619+
test_config branch.autoSetupMerge true &&
620+
test_config branch.main.remote one &&
621+
test_config branch.main.merge refs/heads/main &&
612622
git push
613623
'
614624

0 commit comments

Comments
 (0)