Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org,  Harald Nordgren <haraldnordgren@gmail.com>
Subject: Re: [PATCH 2/3] remote: reject invalid branch names in set-branches
Date: Wed, 25 Nov 2026 21:17:38 -0800	[thread overview]
Message-ID: <xmqqa4mwqih9.fsf@gitster.g> (raw)
In-Reply-To: <5140655d23413ea5e739ecd4f413b931bddfd5f8.1795632934.git.gitgitgadget@gmail.com> (Harald Nordgren via GitGitGadget's message of "Wed, 25 Nov 2026 18:55:33 +0000")

"Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes:

> From: Harald Nordgren <haraldnordgren@gmail.com>
>
> Giving "git remote set-branches" a name like @{u} wrote a fetch
> refspec that could never match anything. Worse, without --add the
> existing remote.<name>.fetch entries were thrown away first, so a
> single typo left the remote with a broken configuration and no
> indication of what went wrong.

The same "make an observation on the current state in the present tense"
applies here.

In fact, once an invalid refspec like '+refs/heads/@{u}:...' is written
to remote.<name>.fetch, even running 'git remote set-branches' again
cannot fix it, because remote_get() dies while parsing the existing
config.  Good catch.

> diff --git a/builtin/remote.c b/builtin/remote.c
> index 63d2db39fe..b04cbe70b6 100644
> --- a/builtin/remote.c
> +++ b/builtin/remote.c
> @@ -1786,6 +1787,9 @@ static int set_remote_branches(const char *remotename, const char **branches,
>  		exit(2);
>  	}
>  
> +	for (branch = branches; *branch; branch++)
> +		validate_tracked_branchname(*branch, remote->mirror);
> +

In the unshown call at the end of set_remote_branches(), add_branches()
passes the '.mirror' member to add_branch():

    static void add_branches(struct remote *remote, const char **branches,
                             const char *key)
    {
            const char *remotename = remote->name;
            int mirror = remote->mirror;
            ...
            for (; *branches; branches++)
                    add_branch(key, *branches, remotename, mirror, &refspec);

So passing remote->mirror to validate_tracked_branchname() matches the
refspec construction that follows, and checking every element of
branches before remove_all_fetch_refspecs() ensures neither replace mode
nor --add touches existing config on failure.

Looking good.

  reply	other threads:[~2026-11-26  5:17 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 18:55 [PATCH 0/3] remote: reject invalid branch names Harald Nordgren via GitGitGadget
2026-11-25 18:55 ` [PATCH 1/3] remote: reject invalid branch names in add -t Harald Nordgren via GitGitGadget
2026-11-26  3:07   ` Junio C Hamano
2026-11-25 18:55 ` [PATCH 2/3] remote: reject invalid branch names in set-branches Harald Nordgren via GitGitGadget
2026-11-26  5:17   ` Junio C Hamano [this message]
2026-11-25 18:55 ` [PATCH 3/3] remote: reject invalid branch names in add -m Harald Nordgren via GitGitGadget
2026-11-26  5:17   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqa4mwqih9.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=haraldnordgren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox