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

Re: [PATCH v2] push: shell-quote names in suggested push commands

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 1, 2026, 16:18 UTC
Message-ID
<aw7zZpPPVsZMXb0t@pks.im>
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:
Show 23 quoted lines
> 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);
Show 14 quoted lines
> 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
Previous: Nahid hasan SagorNext: Nahid hasan Sagor
Message 10 of 11 in “push: shell-quote names in suggested push commands”
  1. push: shell-quote names in suggested push commandsNahid Hasan via GitGitGadget, Nov 26, 2026
  2. Junio C HamanoNov 26, 2026
  3. Nahid hasan SagorNov 27, 2026
  4. push: shell-quote names in suggested push commandsNahid Hasan via GitGitGadget, Nov 27, 2026
  5. Nahid hasan SagorNov 27, 2026
  6. Junio C HamanoNov 27, 2026
  7. Nahid hasan SagorNov 27, 2026
  8. Junio C HamanoNov 27, 2026
  9. Nahid hasan SagorNov 27, 2026
  10. Patrick SteinhardtDec 1, 2026
  11. Nahid hasan SagorDec 1, 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.