Git development
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: Nahid Hasan via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Nahid Hasan <nahidhasan141400@gmail.com>
Subject: Re: [PATCH v2] push: shell-quote names in suggested push commands
Date: Tue, 1 Dec 2026 17:18:46 +0100	[thread overview]
Message-ID: <aw7zZpPPVsZMXb0t@pks.im> (raw)
In-Reply-To: <pull.2336.v2.git.1795747717319.gitgitgadget@gmail.com>

On Fri, Nov 27, 2026 at 02:48:37AM +0000, Nahid Hasan via GitGitGadget wrote:
> diff --git a/builtin/push.c b/builtin/push.c
> index 2377b5af55..3908f5f532 100644
> --- a/builtin/push.c
> +++ b/builtin/push.c
> @@ -155,6 +156,9 @@ static NORETURN void die_push_simple(struct branch *branch,
>  	const char *advice_automergesimple_maybe = "";
>  	const char *short_upstream = branch->merge[0]->src;
>  	struct repo_config_values *cfg = repo_config_values(the_repository);
> +	struct strbuf quoted_remote = STRBUF_INIT;
> +	struct strbuf refspec = STRBUF_INIT;
> +	struct strbuf quoted_refspec = STRBUF_INIT;
>  
>  	skip_prefix(short_upstream, "refs/heads/", &short_upstream);
>  
> @@ -173,18 +177,26 @@ static NORETURN void die_push_simple(struct branch *branch,
>  				 "won't match the local branch, see option "
>  				 "'simple' of branch.autoSetupMerge\n"
>  				 "in 'git help config'.\n");
> +
> +	/*
> +	 * Quote for copy-paste into a POSIX shell. Ordinary names stay
> +	 * bare; metacharacters are wrapped in single quotes.
> +	 */

I think it's unnecessary to document how the quoting is performed,
that's none of our business here. So this can be a oneliner:

  /* Quote for copy-paste into a POSIX shell. */

> +	strbuf_addf(&refspec, "HEAD:%s", short_upstream);
> +	sq_quote_buf_pretty(&quoted_remote, remote->name);
> +	sq_quote_buf_pretty(&quoted_refspec, refspec.buf);

Do we need the extra `refspec` buffer? As far as I can see,
`sq_quote_buf_pretty()` calls `sq_quote_buf()`, and that function
handles the case where `dst.buf == src`. So:

        strbuf_aqqf(&quoted_refspec, "HEAD:%s", short_upstream);
        sq_quote_buf_pretty(&quoted_refspec, quoted_refspec.buf);

> diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh
> index 5f8aa1ed19..57d50d8950 100755
> --- a/t/t5529-push-errors.sh
> +++ b/t/t5529-push-errors.sh
> @@ -94,4 +94,103 @@ test_expect_success 'detect ambiguous refs early' '
>  	test_cmp expect rp-ran
>  '
>  
> +# How a POSIX shell splits a copy-paste command line.
> +shell_split () {
> +	line=$1
> +	eval "set -- $line"
> +	printf "%s\n" "$#" "$@"
> +}

Aren't all of these tests it t5529 a tiny bit excessive only to verify
that we quote the output correctly? It almost feels as if we're now
unit-testing `sq_quote_buf()` itself, but if we wanted to do that we
should do it via a proper unit test and not via git-push(1).

Patrick

  parent reply	other threads:[~2026-12-01 16:18 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:42 [PATCH] push: shell-quote names in suggested push commands Nahid Hasan via GitGitGadget
2026-11-26 19:04 ` Junio C Hamano
2026-11-27  2:54   ` Nahid hasan Sagor
2026-11-27  2:48 ` [PATCH v2] " Nahid Hasan via GitGitGadget
2026-11-27  2:52   ` Nahid hasan Sagor
2026-11-27  5:19     ` Junio C Hamano
2026-11-27  5:26       ` Nahid hasan Sagor
2026-11-27  5:53   ` Junio C Hamano
2026-11-27  6:06     ` Nahid hasan Sagor
2026-12-01 16:18   ` Patrick Steinhardt [this message]
2026-12-01 16:39     ` Nahid hasan Sagor

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=aw7zZpPPVsZMXb0t@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=nahidhasan141400@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