git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/3] remote: reject invalid branch names in add -m

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 26, 2026, 05:17 UTC
Message-ID
<xmqq5wxkqih7.fsf@gitster.g>
In-Reply-To
<bc1e30f6d05cf3e724a454e4c922a33f34c5a55c.1795632934.git.gitgitgadget@gmail.com>
"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> "git remote add -m" only looked at its argument after the remote had
> been created and fetched from. A bad name such as @{u} therefore got
> as far as a network fetch before failing with "Could not setup
> master", leaving a half configured remote behind.

Again, log messages are written in present tense. Have you perhaps changed your LLM settings or something?

Minor factual nit on the commit log. In add(), fetch_remote() only runs when -f is passed, so without -f no network fetch happens before refs_update_symref() fails with "Could not setup master '%s'". Saying "after the remote has been created and (with -f) fetched from" would be more accurate.

Show 16 quoted lines
> diff --git a/builtin/remote.c b/builtin/remote.c
> index b04cbe70b6..35c6a1f7fd 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -226,6 +226,14 @@ static int add(int argc, const char **argv, const char *prefix,
>  		die(_("specifying branches to track makes sense only with fetch mirrors"));
>  	for (size_t i = 0; i < track.nr; i++)
>  		validate_tracked_branchname(track.items[i].string, mirror);
> +	if (master) {
> +		struct strbuf ref = STRBUF_INIT;
> +
> +		strbuf_addf(&ref, "refs/heads/%s", master);
> +		if (check_refname_format(ref.buf, 0))
> +			die(_("'%s' is not a valid branch name"), master);
> +		strbuf_release(&ref);
> +	}

Passing 0 instead of REFNAME_REFSPEC_PATTERN here is the right choice, because -m names a single branch rather than a refspec glob pattern.

Because check_refname_format() allows "HEAD" as a component, -m HEAD still passes this check. We would then later attempt to point refs/remotes/<name>/HEAD to itself, which would be similar to the crazy configurations this series tries to prevent.

Previous: Harald Nordgren via GitGitGadget
Message 7 of 7 in “remote: reject invalid branch names”
  1. 0/3 remote: reject invalid branch namesHarald Nordgren via GitGitGadget, Nov 25, 2026
  2. 1/3 remote: reject invalid branch names in add -tHarald Nordgren via GitGitGadget, Nov 25, 2026
  3. Junio C HamanoNov 26, 2026
  4. 2/3 remote: reject invalid branch names in set-branchesHarald Nordgren via GitGitGadget, Nov 25, 2026
  5. Junio C HamanoNov 26, 2026
  6. 3/3 remote: reject invalid branch names in add -mHarald Nordgren via GitGitGadget, Nov 25, 2026
  7. Junio C HamanoNov 26, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.