Article View: linux.kernel.git
Article #4207Re: [PATCH v2] push: shell-quote names in suggested push commands
From: Nahid hasan Sagor
Date: Tue, 01 Dec 2026 16:39
Date: Tue, 01 Dec 2026 16:39
86 lines
15378 bytes
15378 bytes
Hi Patrick,
Thank you for taking the time to review the patch.
On Tue, Dec 1, 2026 at 10:18 PM Patrick Steinhardt <ps@pks.im> wrote:
>
> 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. */
Makes sense, I will simplify both comments to that oneliner in v3.
> > + strbuf_addf(&refspec, "HEAD:%s", short_upstream);
> > + sq_quote_buf_pretty("ed_remote, remote->name);
> > + sq_quote_buf_pretty("ed_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("ed_refspec, "HEAD:%s", short_upstream);
> sq_quote_buf_pretty("ed_refspec, quoted_refspec.buf);
If I'm reading `quote.c` right, both `sq_quote_buf_pretty()` and
`sq_quote_buf()` append to `dst` rather than replacing its existing
contents, so calling `sq_quote_buf_pretty("ed_refspec,
quoted_refspec.buf)` after `strbuf_addf()` would produce
`"HEAD:mainHEAD:main"` (or `"HEAD:a b'HEAD:a b'"`). Keeping the
separate `refspec` strbuf avoids duplicating the prefix.
> > 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).
Agreed I went a bit overboard trying to cover shell splitting edge cases
there. I will trim `t5529-push-errors.sh` down to a concise test
covering a remote and branch name with shell metacharacters in v3.
Technical Details
Message-ID:
<CABQNq+=dG+XHcPpS+CzGhM4B+hp_RGRwwQzmMhW7YLKDRAeHXQ@mail.gmail.com>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76803-linux-kernel-git=dewy.ruReferences:
<pull.2336.git.1795686173178.gitgitgadget@gmail.com> <pull.2336.v2.git.1795747717319.gitgitgadget@gmail.com> <aw7zZpPPVsZMXb0t@pks.im>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.mb-net.net!open-news-network.org!news.nntp4.net!nntp.xenet.de!news.neodome.net!usenet.network!.POSTED!vger.kernel.org!git+bounces-76803-linux-kernel-git=dewy.ru
From: nahidhasan141400@gmail.com (Nahid hasan Sagor)
Newsgroups: linux.kernel.git
Subject: Re: [PATCH v2] push: shell-quote names in suggested push commands
Date: Tue, 1 Dec 2026 22:39:00 +0600
Organization: Usenet Network
Message-ID: <CABQNq+=dG+XHcPpS+CzGhM4B+hp_RGRwwQzmMhW7YLKDRAeHXQ@mail.gmail.com>
References: <pull.2336.git.1795686173178.gitgitgadget@gmail.com>
<pull.2336.v2.git.1795747717319.gitgitgadget@gmail.com> <aw7zZpPPVsZMXb0t@pks.im>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: usenet.network;
logging-data="1767297"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:XEKQsh8ZWnxI1rur1SRlihs+3+U= sha256:xQgfdPHZXecpinXNw10+9v/BKP1fF37+7LY9cGwIWuw=
sha1:torEpygGquvk4L6j2byaxPVk/uU= sha256:wLBFJfVVxZ13QjIWhs6uPaU+KLNGswTXGzPL/KedHrE=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
by mail.dewy.ru (Postfix) with ESMTP id CDBEA117418; Tue, 1 Dec 2026 19:39:28 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.948
X-Spam-Status: No, score=-1.948 tagged_above=-9999 required=6.31
tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
with ESMTP id b88Ib_5APTZr;
Tue, 1 Dec 2026 19:39:26 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76803-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN>
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
by mail.dewy.ru (Postfix) with ESMTPS id 927B31173F6; Tue, 1 Dec 2026 19:39:17 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
by sea.lore.kernel.org (Postfix) with ESMTP id A8EA02C3FD; Tue, 1 Dec 2026 16:39:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=3; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796143155;
b=rmRdXV3Muc1teiio2s2ArGlP65ajxXofo+Rfq0xFsMrMvklyPqAQHmSFz5IvUmnh5G2o
EX6z2G7w3gkDKspkw1mHo+VozYeHuV0eJx3U/XHoBDQMVBd6eSSHivEL3dORnhJCntsHk
GE+1gC4IKmjCea/FthEc95MtHQGniJCPUklfBjhwg28GD+2pODm68WHQd/fGFb7l6vQpx
PiLI70jmQty3IqKr8DCKGLlGH2TgLA48cX61Kt2NYq4nGMWUPhGkrM69iuOSDtjeQgvlu
W58E/JojAjGQl8Z0zbEh8RnB2rVt4oRxVEv9c2urGbSxGAV7xAoouxG+mEYmzLATcAA==
X-ARC-Message-Signature: i=3; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796143155;
h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
X-Google-DKIM-Signature:X-Forwarded-Encrypted:X-Gm-Message-State:
X-Gm-Gg:X-Received:X-Mailing-List:List-Id:List-Post:List-Help:
List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
References:In-Reply-To:From:Date:X-Gm-Features:Message-ID:Subject:To:
Cc:Content-Type:Content-Transfer-Encoding;
bh=KjwHMxBsieGLzMB2KFez7nqeSU8SWJ6aPS/SjDyQ0kY=;
b=d3+Ewnu6qnmi3OT+iyBPC7vNWChpE6ljvnrYz6GFn8coXxikBlzdb9dcPeohfQMfpRxj
j+Z3TQNQOf/KeyxcJR1ZDqL5ui3vR0IEZLaA56FamUQsKYn63qGZTdy22kWJB9g2q75I9
WBwf6640CsSa2NETJ2+D6EjePD6EWOFv74BhSE7dfRV4siYLwGwliPrOL5VYFlxpp08NU
xavcQMkLBhrC/iZKpXVEZtiaJ6c2U4bUqngLP/Qex2138UWltAg16YgrjS/uJZsONYowq
T/hB3UxRIsHoNIe81eCQeqATBydoTSe4jxyvAyrjgjG0WGsQN7IhgcKwRKDAp01WsAg==
X-ARC-Authentication-Results: i=3; smtp.subspace.kernel.org;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=IHaMpep0;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
by smtp.subspace.kernel.org (Postfix) with ESMTP id 7F22D606A32A;
Tue, 1 Dec 2026 16:39:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=IHaMpep0
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.208.176
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
t=1796143154;
b=xUQDG7pnhLDzg1x3NbF62s+v/xuEw0PUVtGMTEKG0IdLNtidJRHojSRGCHavOkMBGkmJ
XVm8C743lPkZF6LMoU+H+Tb8AobdgdJJoAbp4p1m5dTBjWwG0OVewOwVK0g7QbmlscUSV
QWPTCzZEzFkYVlGcNpmlu+qOjYAcO7trj5XZjRnHig/oSREQFGmGepqN5ZNpy2AKWNsQ5
MDxDA2JAkEW0KmMHTvQ29kRU3Bg3GNO3sQCA4JtEj33+yvgj2+8mVUalt/RDs05/VKYp3
o3UdzmZiOaOvzJ1PszNbrosyjUDtDXNuKvT+u9sWogBTFxGeyXz0qlRUi9wU4cObNug==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
a=rsa-sha256; c=relaxed/relaxed; t=1796143154;
h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:
MIME-Version:References:In-Reply-To:From:Date:X-Gm-Features:
Message-ID:Subject:To:Cc:Content-Type:Content-Transfer-Encoding;
bh=KjwHMxBsieGLzMB2KFez7nqeSU8SWJ6aPS/SjDyQ0kY=;
b=OSlhFGX9bd8X8L8m0OqUSh8IBPUzxZEDFm6YiXe4oNldfxUh5lugJgfZFpRb4LUmRf0v
sBT1MBi/E9UvdgdvrkKbI/dNnS75b/XnQWe9j9Z3cJkbEJCAUIAwEd4W16UE6q5XFlpNV
tBSpT7t88KyFTCBFVklX7+xZAR7lKsf/EtP9d948I2vaJqw6PpsGt/cNpoMSUF3C54b0l
w9rWwvrAZtRiMuMfsBMahhpK+uHcuZ6ycSuTf56eiiVarY1L0uhDV4SQ1l/IyvektQV4s
nZ9uFrygR47xdeJ7fphx0Z6uy0nDnYGCP2KZzCBJkb+vSfvTXc+jcoAUNoOQSF2Mc9g==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org;
dmarc=pass header.from=gmail.com;
spf=pass smtp.mailfrom=gmail.com;
dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=IHaMpep0;
arc=pass header.oldest-pass=0 smtp.remote-ip=209.85.208.176
X-Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176])
(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
(No client certificate requested)
by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BB4F606A31A
for <git@vger.kernel.org>; Tue, 1 Dec 2026 16:39:14 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 4BB4F606A31A
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-3ae81ae52ffso92724591fa.2
for <git@vger.kernel.org>; Tue, 01 Dec 2026 08:39:14 -0800 (PST)
X-ARC-Seal: i=1; a=rsa-sha256; t=1796143152; cv=none;
d=google.com; s=arc-20260327;
b=fut7JlNatXquZqgGy1jP4MeRGNfLsBvROe5LzP5zeX0Kxjv8MYq/9+1lzm7OpibmD2
i+BMVLBI8h+UGYy4A1k3MRgxG7a+Sf44VhmkIZz3eGkUJdgYwRU7H4vMNrkE/LPO1qMU
UN/AIAIq1ZBXwTehQZAYVIBL3bqLl5885gdxy4Sk03ILguDCW37XGV71NM0NWhrFj1q2
yJHn8qHxJcJl8KkOM2wuISlCgqTDgt5+ecvg9a09DmM+7c1mVtY73KWGiPPkqS4Xuvbi
Qi48pjHRh+DeT8ooMDt+/JBGgFz1ZfpeJFYZiRllCEI6yy8/sYHPydlG9iouDwdkTi3T
HIrA==
X-ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327;
h=content-transfer-encoding:cc:to:subject:message-id:date:from
:in-reply-to:references:mime-version:dkim-signature;
bh=KjwHMxBsieGLzMB2KFez7nqeSU8SWJ6aPS/SjDyQ0kY=;
fh=g8c/v0n76EdyL6JYLV8H1MuL3R+GONYzdoiloVSPIiE=;
b=QsfOd7qzGuIfZb0//v/ljpTlOe7XcLa3SgbUP60lADb0598uS07GishCORoFcUhRVn
DEEtPJlNDHfr2SRj6+8htGVEPs6yx71u/gAgfgqG5e0LRYtXzR9J2vAOHLGFJZn13g15
4teDBorblJUsghVq1GwF5nF5zbHCyWURNPGJnw9QP872X9DZQlRgPgolwkrZ4We28l3T
VMlKfhg5v2dGHiyVb0qhxxwPE0qAtfnh/bELj9FvUA+iY7uHw3YIes1XfnGJ2FCXyfxZ
uF/Vv+nyg5ZGxPfifiAkgTPMgJNsSuP3E+yuhUyQYMhaSmNzUkSqtCYWZbZOiLzGXKM1
JycQ==;
darn=vger.kernel.org
X-ARC-Authentication-Results: i=1; mx.google.com; arc=none
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=gmail.com; s=20260707; t=1796143152; x=1796747952; darn=vger.kernel.org;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:from:to:cc:subject
:date:message-id:reply-to:content-type;
bh=KjwHMxBsieGLzMB2KFez7nqeSU8SWJ6aPS/SjDyQ0kY=;
b=IHaMpep0jlFmLFSJoKXxSp0VAXrpk0gbMmSSWOBOcXQ9RHOCM93t+0Q1u/h9MF4hmc
T5zR1vdpMuIeb8/XhnOPNzDzLCuyot79U9ukBMq/+LvOQGAiMKp83tCAPocGg/mxPGj3
62TB1zXb8pVAvwJewmJcevC5PokVYJoukriL6byaJ0l9hbwdFDsevQmqP1F687TSXBst
tWjJXhGaLIl5WHqY1BHkHstLxI+RSh9e06MV0L3xdSN8TlURkHPY17D/sWQtb+6EeO1L
xyxwL3tqAPPVwIyC+KFl9b70pMP71xnV7xjzW+C7FJwGP6rLhDj+Bd3X270xjJF5o+C7
cW6Q==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20260707; t=1796143152; x=1796747952;
h=content-transfer-encoding:content-type:cc:to:subject:message-id
:date:from:in-reply-to:references:mime-version:x-gm-gg
:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
:content-type;
bh=KjwHMxBsieGLzMB2KFez7nqeSU8SWJ6aPS/SjDyQ0kY=;
b=F66nwVTVh5pYoRsBiUyTFlaFT2OEyxv60l0R8YB3Z7d+A6tfpqxbgJGKUP4apYiDov
u7H6y29+9OwEQTTNEXVVGOzDCm/NR9hlpErik+7Nyd8IS2pF8fYd0fYx1+m8Xl5mQiP1
cocdApvw58uB6nZxDIX57KebT6vRsTNU1W2CV2R4f9yRfc7AUY/hrbQRMRfQMCVAMrHf
8LkDzycwlBcGZm0BrBcA1eluoovgdiEp36VfgYMnABqjBFUpchK4Aeu+reCCd1eWVrat
ACf04gfMHWPFnZfVgKSK/4Ziu7ONGgPXEXxCxzDI14mY4a2w8IFHx0f98dQXh0uNhkBv
rDPg==
X-Forwarded-Encrypted: i=1; AL+hErFNnhBPRaynMG62RkxdshCTsnJ/mUElBkZjhKD7fJxT7y/IRf63/JyS9aJkWL3pQM4GkGM=@vger.kernel.org
X-Gm-Message-State: APuU4Z+fSIi6ZC/btkQLTMthfCSlsXZWvpzE/Vg61wpO1tJzVLYMPW2D
+PqZCu9AHpWR412rv+tf53cRbBhFMy1WXNCTL6aEMBdYpDw7ReKlQ9UTT1aaB9KP/Va6QW8ZsS+
XV/HOEFjBfnGsJtl+PBzL6Ph+z/hetgQ=
X-Gm-Gg: AZFdTZchPndtGBBqg2IfcR6MLB/yd0AlRz3jHQDX8B4Mw2fHSTQ/OBMLIrhu1muyxWF
SytasvK601qxlLIPbMlHoOy58Vt9p/982VnIDcT8ptVIDD5gcpTrqawGMh3uEZJ+zG1dPZL8ytc
ooyZCz1NYZXmQymTjzuPmU+q8o7cckB++6l1N67H86EWfaVxAiy+hUZCUYbnc0zzvIDxEOCe+jI
zteYQbLiUBxoog3z56VPsHj1VVu5sdkgNMou2MhegljX0jtL7f+rRleud9jr7/AVtrTSPfs5IMv
E8wuPUaJQLyaYuJZVHqglfoU7Dq/CbxCS1LGavwWEKSaZhlcIyHEmm5DKqQFZgaqKfFWTClP4My
Z5vQsZ+QKkTlM7i0z3moyIbrmsR5RdsMjRUE=
X-Received: by 2002:a05:6512:3087:b0:5bf:e540:8606 with SMTP id
2adb3069b0e04-5c1bc898e67mr12749298e87.59.1796143152194; Tue, 01 Dec 2026
08:39:12 -0800 (PST)
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list
X-In-Reply-To: <aw7zZpPPVsZMXb0t@pks.im>
X-Gm-Features: Aa3M54oibSHAcykZsMFBAAjiGyXf2tDWToV_hnjN9IeHq0H6RQgIO1BZmRsCjA4
X-Cc: Nahid Hasan via GitGitGadget <gitgitgadget@gmail.com>, git@vger.kernel.org