Merge branch 'gc/zero-length-branch-config-fix'

A misconfigured 'branch..remote' led to a bug in configuration
parsing.

* gc/zero-length-branch-config-fix:
  remote.c: reject 0-length branch names
  remote.c: don't BUG() on 0-length branch names
pull/1271/merge
Junio C Hamano 4 months ago
commit 0b91d563d8
  1. 10
      remote.c
  2. 20
      t/t5516-fetch-push.sh

@ -196,9 +196,6 @@ static struct branch *find_branch(struct remote_state *remote_state,
struct branches_hash_key lookup;
struct hashmap_entry lookup_entry, *e;
if (!len)
len = strlen(name);
lookup.str = name;
lookup.len = len;
hashmap_entry_init(&lookup_entry, memhash(name, len));
@ -215,7 +212,8 @@ static void die_on_missing_branch(struct repository *repo,
{
/* branch == NULL is always valid because it represents detached HEAD. */
if (branch &&
branch != find_branch(repo->remote_state, branch->name, 0))
branch != find_branch(repo->remote_state, branch->name,
strlen(branch->name)))
die("branch %s was not found in the repository", branch->name);
}
@ -355,8 +353,12 @@ static int handle_config(const char *key, const char *value, void *cb)
struct remote_state *remote_state = cb;
if (parse_config_key(key, "branch", &name, &namelen, &subkey) >= 0) {
/* There is no subsection. */
if (!name)
return 0;
/* There is a subsection, but it is empty. */
if (!namelen)
return -1;
branch = make_branch(remote_state, name, namelen);
if (!strcmp(subkey, "remote")) {
return git_config_string(&branch->remote_name, key, value);

@ -598,6 +598,26 @@ test_expect_success 'branch.*.pushremote config order is irrelevant' '
check_push_result two_repo $the_commit heads/main
'
test_expect_success 'push rejects empty branch name entries' '
mk_test one_repo heads/main &&
test_config remote.one.url one_repo &&
test_config branch..remote one &&
test_config branch..merge refs/heads/ &&
test_config branch.main.remote one &&
test_config branch.main.merge refs/heads/main &&
test_must_fail git push 2>err &&
grep "bad config variable .branch\.\." err
'
test_expect_success 'push ignores "branch." config without subsection' '
mk_test one_repo heads/main &&
test_config remote.one.url one_repo &&
test_config branch.autoSetupMerge true &&
test_config branch.main.remote one &&
test_config branch.main.merge refs/heads/main &&
git push
'
test_expect_success 'push with dry-run' '
mk_test testrepo heads/main &&

Loading…
Cancel
Save