From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795968504; b=G/KBjvCRAz0N+S3hRiVLYPL+OClKjmwAKr910fovZtWSb/8rCu5TMwKwxjVqRhZ5Wvj3 KFfwy9joAJPvBjYAyNF59wjAzJh24DvbMAV6nGfFXkwWbwoEtXN5G+HcfMfTcfr8KECNG nb8hn9H2+AX6zMDJbgMRYTrF0BLkxlpOoCSNP5o/6Pj2gtxEfUtPaoyB+7nLn4kpWudxu 0GCxnjEPo5JbVJWl03QrmsHTLpgatnqpRuDqh8YPmcYalYrEZFlnrKv6vSrcVa4PUPyz/ gWOmqmBfgu2B+PL3Qqw9wqxrFhLSgbVLCVwwX06hewHLGOVRq2tyC/4ehylXTBYdGtw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795968504; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:From:Reply-To:Subject:To:Cc: References:Content-Language:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=YQTutRpZiUDhrjaNvqet/iJF9L7amY2MttLtcgZJrXU=; b=aS0sINCy39Q9oqbtKWXKReU6et1B4unsnyvbaoIH2w5kjS85hC629Vqrk310A2OHPfe/ qbtLu3Dzp7+wFBTKeoNYKFo1fb1WcM9qtejb+BzFfq5SU8YU0hpFtvl1doTh09tx8446O moMPVW0AgL816+b4Bt6wm44X+UBuC+m+yURVO69iQyd/XgqHQQD8iZYta4oqS9h3Utzr6 vg4LaKHUt6KkOk1sRwOubhspu5MZQ5Lu4wrlPZkjiyr5iZR57xUvcp/tpeVHuisGrowWs LjQwnjGRWWNeXy6mEqVEh9DKglP+9wytqUWVZFkTaFtkBsIZq8oeZR40P8Op6fz94IA== ARC-Authentication-Results: i=1; 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=v7wnrBE9; arc=none smtp.remote-ip=209.85.128.53 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (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 A75B1606A33C for ; Sun, 29 Nov 2026 16:08:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A75B1606A33C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com 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=v7wnrBE9 Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-4ba013938d7so90942455e9.2 for ; Sun, 29 Nov 2026 08:08:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795968500; x=1796573300; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:reply-to:from:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to:content-type; bh=YQTutRpZiUDhrjaNvqet/iJF9L7amY2MttLtcgZJrXU=; b=v7wnrBE9Ae+o4bc3IZqdL0eHxyT5YQ1iWGlih93fqFhh2FpMz/3ynoalHcF8hKQxGz gTictKFSZFROdazJc8A2N8fv7k+rKN7WKv/hKot5CcETspQ5adORGcpOsqpzbaas9w1p D7CNKeexbrz17uyxGGs1Uz3wAUuaFl4VTItcZdE6lxYJ7QKwOCqGAVkzK0IE810qH8bE eZaPYXndhvL1dm4SX1AXs1ljHmvsnUfrP+TgLudJ+FWsJ3Uj1FGulRpwS6q0/S+/Gd8i Y9nIrYyGunMqn0vM77cGskgxQhyE6Z5jLZnppzKGv+ojaIPItndiOHoOaQ0vLRUTsiXo nN+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795968500; x=1796573300; h=content-transfer-encoding:content-type:in-reply-to:content-language :references:cc:to:subject:reply-to:from:user-agent:mime-version:date :message-id:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=YQTutRpZiUDhrjaNvqet/iJF9L7amY2MttLtcgZJrXU=; b=BEPLUY4RnThJmnm4Cz0+kR4BsfgJTbDk9NYE+Zs8hemRB/B7rhCzldvJ3TqN8Yyiy4 61mWD4bzrBgqOI5HLOuRuT8QO9TQokUg8lzyjt6RT5Jt78CjUCtrK7KZu5HyyuOUN+XB wJhMrwgQMmEGGeDabu10QsmqQalTXOLq2+xx0ZZMICH+1O1t+XwBTIjoyPuTA6uaEh4Z UJT47+aESv2xX+epfoh1qUxASvu7OuQvLDyXBrW3xJmwDOUjimMkxcsjSfwd2pBCGHTV JFcg/oN5R6YyS1lHUr407+oGQBx3fb/XGIsImKPIHJwLrhrXwn4zME3u4TDjYL4utLZi AEDg== X-Forwarded-Encrypted: i=1; AL+hErFBjYyedp1dFZ3uDXa4gJPkDgK5fNvzgVXxoPwGt5Uwjl6wFE5570Nxj4DX+F+qpNdbPBo=@vger.kernel.org X-Gm-Message-State: APuU4Z/HfcBTAcTo3r7+nK6qoTGUn99B6K6augXPLJzdoYDe+OFIt04+ nD/SceZHR3OQgEUCDgqTlO6r1FWLbF0VYVDQp9zVeT8RKtaeLQfnVC52 X-Gm-Gg: AZFdTZf9GYAivTHKY/SLSnEaWWp2R04df1I288FK+lwytmqDAgRZVLJ6HUrLVWUYT9n oDTVQy9BNRDaCFmFSC8bjfzFx0tAy8mFZw5pjH2eM0YoR1wX9DIs14TRl3f8yeOsIWjWsof+VYx dzuh8yJd00VkKtDSIB1BRJxhu3Rnjs34y2GlnNXw5L/WIdRyUh7wncg9lIzZFXa0S0K6Hdvskbt IhXRAddBSGaeoYFiwmMRckWLXIt69dL52MyG6YjRYfv2OF3hSP5TEAaHAfX9rylTNbdFNtF1llY 58TKJsPbEvN3T3I7rv5219ENw2Lowz8I8IUitsapQRsTEyRTpCocES4O/zdFIJ8EslMg3Szdr5X Ua0R1fjXbCT6pHwm0s40PjJ6u/yqa/rDZw7BRgPrB1i8TshbAx5bm8LwAwRKcE4XdXi46i5uw9N q50pRwRduSYdY8oTnTS276m2/1u7HYnLOb6qH+zkBjsElDsukusbCXMEucYDzLYDJeMIvuEzLS5 WAnSjCJF9vaJYS/wE5TvelTlZ315IoaxMajwVIf6sHuVi66iMEaNNHWbGYucXKqUTTDrmMr0E1L XpANmGZt5XC4ZpMkNZICdUR3LNK3dqEz7lD+vjYFtJv7CmjzOJAqmHW31fjZBD8MR2qVKn8CEZG z6b3UtuE= X-Received: by 2002:a05:600c:4585:b0:4a1:83f0:7c91 with SMTP id 5b1f17b1804b1-4bb8882948dmr633075595e9.18.1795968499689; Sun, 29 Nov 2026 08:08:19 -0800 (PST) Received: from ?IPV6:2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f? ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb8526cbd0sm1163023855e9.0.2026.11.29.08.08.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 29 Nov 2026 08:08:19 -0800 (PST) Message-ID: <65a734d2-51ec-42fe-9f2d-9026b58838a5@gmail.com> Date: Sun, 29 Nov 2026 16:08:17 +0000 X-Mailing-List: git@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird From: Phillip Wood Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [PATCH v2] config: make the suggested "set" command safe to paste To: Harald Nordgren via GitGitGadget , git@vger.kernel.org Cc: Ben Knoble , Harald Nordgren References: Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Harald This looks fine to me. We could quite happily test the quoting of the config key and config value in a single test but it is not worth re-rolling just for that. Thanks Phillip On 28/11/2026 18:13, Harald Nordgren via GitGitGadget wrote: > From: Harald Nordgren > > When "git config" is given "=" as a single argument and > the value contains spaces, the suggested command does not work when > pasted back into a shell: > > $ git config status.comparebranches="@{upstream} @{push}" > error: missing value to set to the variable 'status.comparebranches=@{upstream} @{push}' > hint: did you mean "git config set status.comparebranches @{upstream} @{push}"? > > The shell splits the value into two arguments and the command fails > with "wrong number of arguments". > > Quote the key and the value when they need it, and put the command > on a line of its own the way other hints show commands, so it can be > copied without the surrounding quotes: > > hint: did you mean: > hint: > hint: git config set status.comparebranches '@{upstream} @{push}' > > Signed-off-by: Harald Nordgren > --- > config: make the suggested "set" command safe to paste > > When git config = is given a value with spaces, the > suggested command fails when pasted back into a shell. Quote the key and > the value when they need it and put the command on its own line, the way > other hints show commands: > > $ git config status.comparebranches="@{upstream} @{push}" > error: missing value to set to the variable 'status.comparebranches=@{upstream} @{push}' > hint: did you mean: > hint: > hint: git config set status.comparebranches '@{upstream} @{push}' > > > Changes in v2: > > * Quote the suggested key and value with sq_quote_buf_pretty() > directly, without post-processing its output. A value like !git > status is now shown as ''\!'git status'. > * Add a test that a key with spaces is quoted. > * Drop the test for the ! alias value. > > Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2457%2FHaraldNordgren%2Fconfig-set-hint-quote-v2 > Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2457/HaraldNordgren/config-set-hint-quote-v2 > Pull-Request: https://github.com/git/git/pull/2457 > > Range-diff vs v1: > > 1: 2aeb767b21 ! 1: e3f2747c22 config: make the suggested "set" command safe to paste > @@ Commit message > The shell splits the value into two arguments and the command fails > with "wrong number of arguments". > > - Quote the value when it needs it, and put the command on a line of > - its own the way other hints show commands, so it can be copied > - without the surrounding quotes: > + Quote the key and the value when they need it, and put the command > + on a line of its own the way other hints show commands, so it can be > + copied without the surrounding quotes: > > hint: did you mean: > hint: > @@ Commit message > Signed-off-by: Harald Nordgren > > ## builtin/config.c ## > -@@ builtin/config.c: static void check_argc(int argc, int min, int max) > - exit(129); > - } > - > -+static void add_suggested_arg(struct strbuf *buf, const char *arg) > -+{ > -+ struct strbuf quoted = STRBUF_INIT; > -+ > -+ sq_quote_buf_pretty("ed, arg); > -+ if (strcmp(quoted.buf, arg) && !strchr(arg, '\'')) > -+ strbuf_addf(buf, "'%s'", arg); > -+ else > -+ strbuf_addbuf(buf, "ed); > -+ strbuf_release("ed); > -+} > -+ > - static NORETURN void die_missing_set_value(const char *arg) > - { > - const char *last_dot = strrchr(arg, '.'); > @@ builtin/config.c: static NORETURN void die_missing_set_value(const char *arg) > char *prefix = eq ? xstrndup(arg, eq - arg) : NULL; > > if (prefix && git_config_key_is_valid(prefix)) { > + struct strbuf suggestion = STRBUF_INIT; > + > -+ add_suggested_arg(&suggestion, prefix); > ++ sq_quote_buf_pretty(&suggestion, prefix); > + strbuf_addch(&suggestion, ' '); > -+ add_suggested_arg(&suggestion, eq + 1); > ++ sq_quote_buf_pretty(&suggestion, eq + 1); > error(_("missing value to set to the variable '%s'"), arg); > - advise(_("did you mean \"git config set %s %s\"?"), > - prefix, eq + 1); > @@ t/t1300-config.sh: test_expect_success 'invalid key' ' > + test_cmp expect err > +' > + > -+test_expect_success 'set with 1 arg of "key=value": suggestion keeps shell alias readable' ' > ++test_expect_success 'set with 1 arg of "key=value": suggestion quotes key with spaces' ' > + cat >expect <<-EOF && > -+ error: missing value to set to the variable ${SQ}alias.st=!git status${SQ} > ++ error: missing value to set to the variable ${SQ}branch.my topic.remote=origin${SQ} > + hint: did you mean: > + hint: > -+ hint: git config set alias.st ${SQ}!git status${SQ} > ++ hint: git config set ${SQ}branch.my topic.remote${SQ} origin > + EOF > -+ test_must_fail git config alias.st="!git status" 2>err && > ++ test_must_fail git config "branch.my topic.remote=origin" 2>err && > + test_cmp expect err > ' > > > > builtin/config.c | 9 +++++++-- > t/t1300-config.sh | 49 +++++++++++++++++++++++++++++++++++++++++------ > 2 files changed, 50 insertions(+), 8 deletions(-) > > diff --git a/builtin/config.c b/builtin/config.c > index f786c0b123..736df8ba0f 100644 > --- a/builtin/config.c > +++ b/builtin/config.c > @@ -218,9 +218,14 @@ static NORETURN void die_missing_set_value(const char *arg) > char *prefix = eq ? xstrndup(arg, eq - arg) : NULL; > > if (prefix && git_config_key_is_valid(prefix)) { > + struct strbuf suggestion = STRBUF_INIT; > + > + sq_quote_buf_pretty(&suggestion, prefix); > + strbuf_addch(&suggestion, ' '); > + sq_quote_buf_pretty(&suggestion, eq + 1); > error(_("missing value to set to the variable '%s'"), arg); > - advise(_("did you mean \"git config set %s %s\"?"), > - prefix, eq + 1); > + advise(_("did you mean:\n\n\tgit config set %s"), suggestion.buf); > + strbuf_release(&suggestion); > } else if (git_config_key_is_valid(arg)) { > error(_("missing value to set to the variable '%s'"), arg); > } else { > diff --git a/t/t1300-config.sh b/t/t1300-config.sh > index 16bb396b63..e7b5bde7af 100755 > --- a/t/t1300-config.sh > +++ b/t/t1300-config.sh > @@ -470,15 +470,47 @@ test_expect_success 'invalid key' ' > ' > > test_expect_success 'set with 1 arg of "key=value": valid key suggests split form' ' > + cat >expect <<-EOF && > + error: missing value to set to the variable ${SQ}pull.rebase=false${SQ} > + hint: did you mean: > + hint: > + hint: git config set pull.rebase false > + EOF > test_must_fail git config set pull.rebase=false 2>err && > - test_grep "missing value to set to the variable .pull\\.rebase=false." err && > - test_grep "did you mean .git config set pull\\.rebase false." err > + test_cmp expect err > ' > > test_expect_success 'set with 1 arg of "key=value": implicit form suggests split form' ' > + cat >expect <<-EOF && > + error: missing value to set to the variable ${SQ}pull.rebase=false${SQ} > + hint: did you mean: > + hint: > + hint: git config set pull.rebase false > + EOF > test_must_fail git config pull.rebase=false 2>err && > - test_grep "missing value to set to the variable .pull\\.rebase=false." err && > - test_grep "did you mean .git config set pull\\.rebase false." err > + test_cmp expect err > +' > + > +test_expect_success 'set with 1 arg of "key=value": suggestion quotes value with spaces' ' > + cat >expect <<-EOF && > + error: missing value to set to the variable ${SQ}status.comparebranches=@{upstream} @{push}${SQ} > + hint: did you mean: > + hint: > + hint: git config set status.comparebranches ${SQ}@{upstream} @{push}${SQ} > + EOF > + test_must_fail git config status.comparebranches="@{upstream} @{push}" 2>err && > + test_cmp expect err > +' > + > +test_expect_success 'set with 1 arg of "key=value": suggestion quotes key with spaces' ' > + cat >expect <<-EOF && > + error: missing value to set to the variable ${SQ}branch.my topic.remote=origin${SQ} > + hint: did you mean: > + hint: > + hint: git config set ${SQ}branch.my topic.remote${SQ} origin > + EOF > + test_must_fail git config "branch.my topic.remote=origin" 2>err && > + test_cmp expect err > ' > > test_expect_success 'set with 1 arg of "key=value": invalid key does not suggest split form' ' > @@ -494,9 +526,14 @@ test_expect_success 'set with 1 arg: variable name starting with digit is invali > ' > > test_expect_success 'set with 1 arg: digit-led section name is valid' ' > + cat >expect <<-EOF && > + error: missing value to set to the variable ${SQ}1foo.bar=baz${SQ} > + hint: did you mean: > + hint: > + hint: git config set 1foo.bar baz > + EOF > test_must_fail git config set 1foo.bar=baz 2>err && > - test_grep "missing value to set to the variable .1foo\\.bar=baz." err && > - test_grep "did you mean .git config set 1foo\\.bar baz." err > + test_cmp expect err > ' > > test_expect_success 'set with 1 arg: subsection plus invalid variable name' ' > > base-commit: acba8bf9753134d9bde89f94369f775838a8c5fe