From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.222.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795889613; b=OcW/Cc5N7ziLa5bbjuJYErIXysxULflSzUp61r7t9fQs+cZPzjc2MYbzX/LIfc/RntXW jmEkMma6mpd3KblzJkXIL96kGlNLW0BSAv/AMVhKliTppSoO4q6tItUKZVlCb9m/O6UCE v5H8t7RdZ16ZdZlr+vBtRNO0m1R1WApf6K607z7jkN4oMtwg0dgxk/yUl5kvuhujYysWZ 3kEi34XQzgkjzZaarkG1qqFgktzlDYvnM/bPmTsRbTQUGHn2uGVp7V90wDHQnE3Jfnu4L vk3s+PqWKXbaID+EdsriQJi6TbPyw6tXXAi3+wPJytLDbTjyOCsfFJh4+vLDQ3lm8GA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795889613; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:Message-Id:In-Reply-To: References:From:Date:Subject:Fcc:Content-Type: Content-Transfer-Encoding:MIME-Version:To:Cc; bh=iPCN9njAQScE/lHui76tqPKUniGB4HR3sJq5jmoYvFs=; b=mauR2CoZePQjHnzy5UnCo+WVggQvb73DoefZLmY/ouEgCSI9ekwdwbnJhWIm7gbK0BYl 1DYO9ODJJsTietFvvZIVcOagc2Wqyd1V+mmLaG6xGqBbkY0IfOaeKTzF19U50vYBYhyKb R4BZapLD8aHT1PniojVaEigBfFwlF/yRa/zTWiHGfAVyb4ObW6lhBhvrwyYCRMYpxwoaB qDMUv9Q4qF9PfKpeNAi+/bi/fmZsKkKqHTyPAf02R56O/g53TtQxcdcY3NwB7jc1TkF0D 3XVNdjuv5FqjM2t1pSWiVEXubb053D1WGT5vbh7zJLi4om4n5EuUKNFSU/4swi+qK+Q== 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=VagI4NHY; arc=none smtp.remote-ip=209.85.222.174 Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) (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 BE356606A31C for ; Sat, 28 Nov 2026 18:13:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BE356606A31C 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=VagI4NHY Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-94958650b09so868167785a.1 for ; Sat, 28 Nov 2026 10:13:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1795889612; x=1796494412; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=iPCN9njAQScE/lHui76tqPKUniGB4HR3sJq5jmoYvFs=; b=VagI4NHYUlEW4hM+E80OBr4vbJ7n8S3augxLNzf0DGQgh9kfR60ivIBbtPaUuQd/ou XTDIjweETcZBaJ0FRLavvJ3foCdZEGfCyca2mDzWKDAFdym3IoCU1IQlRmIOoxTVfneN ZvHwA/7mdXCKONg13wTfuWZhbHHB0EvFwVsFe9xap8i19xp3H0nt4Zi/f8UvTKHfByqx oW8suqHgGXR4tez/MUEvqYUo4TlXCHuRCKOhN0OYGBTFB1bXl10L5UtoyLLEtdnR44PU Q/WlwhT/6b00+mF8kFTgenM1oDXLx3shcjJMp46FXxubY7a/rMMhg/jPXJ55AjPKLTFg tM9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1795889612; x=1796494412; h=cc:to:mime-version:content-transfer-encoding:content-type:fcc :subject:date:from:references:in-reply-to:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=iPCN9njAQScE/lHui76tqPKUniGB4HR3sJq5jmoYvFs=; b=eNCtOeMs5mcO5sfkCUEyuEvYTmIkoPcsKf2KD2YIjuOIfecpREvi9ibUA8J++/IXiq RhJSR1ZsEE0L4eQJVm44cPPvMEJwKd3qvLpXr+B4DwNatIzcBI1qUUQetItT9Tu0jqOJ nVPjGU0R5xD89ViKLOU5432FVlLnACNKc0JGuYwU3HcqUE2StGa+2xbQr2QMXRdwNMY4 tiEbNJWWNpz8v/ZRKshmpxExz3BZ0qxRRJkYWL4cPSdOUL3aWNllE7SZWFbc/xRHc3TQ UTUqcmxoPmIcB4frocBW6Yd4UM1uHuWLWegtPuvAuaHyIWEn9Abfo/3KovBxoo1oXxg/ Y7Lw== X-Gm-Message-State: APuU4Z+0Djdkq1iBvXIgvmYVfJLXb5qxjq6I9QKRB1bhoDKpo/PkX60d gua/g+/epi8QYCm/tObpq4c2OGkSuW4WLZzLaZJV29B9T2AuRHRMnXv1oezc1g== X-Gm-Gg: AZFdTZcvbdAmDC6id3VVjtGuWQX9MfRUAXC5/UPQC8+bzS1wcgSljAu8B1sBowJI/S/ IymQjV3c12YFIStxYEs4yPqzo6wnpSeulGjWKx0LHYGAkGlTeg0+viL5A+rJ3f6Tm/jwwCGAIb5 hmkbED1tGhGB9ojQWoKXHKJCkU0+MEEGtS76Hk/D1f5KZp8TeSNpSV8dEb1ktZhaouSc9qpaZzf t5hBtpNo9Jk00eMgl5V4TSfbjI73mxXVmoITo8jiU5hj5zdYk4M4hpzbgJvuOoqvJWcCwxszQSb ZMedOHpCb7k2LnVm6HtISOZmV9TSdvBk+AbFS0YgkoHkvPfIeBQGJYRRP24pjoPtqn+kBk4jWIz 5OVyYcHxiO2fz1vTkwQ+jOzVNdhjvWSjOA8i+keYNyXwmxbxhIH6s9Ak0hJSzd6qtulFfQZ+yNz ZrBIshJQooAYRAC5o8RnAzhvJ1nLsrIkt105TC5F5zXXcX0jtOVLSkRv+OvXFoBmVQdpT5F2PPl WbcP9hwaTsTCYwKl6Yg1jyA9cQRZkplpOPluGbYxM+gXvuN2vr7SFN490ys+Po8Fu3hbP0IljDv kntrvX4kJWY9pt7VwJ3tYhqI5XklHZ1u4NJZiUXEbj2Gb5boIgqQtj6p8vZo6EQmDWi0ancyQb4 = X-Received: by 2002:a05:620a:4008:b0:949:72f0:cc12 with SMTP id af79cd13be357-949baa151a2mr5443143585a.64.1795889611522; Sat, 28 Nov 2026 10:13:31 -0800 (PST) Received: from [127.0.0.1] (ec2-3-41-210-134.compute-1.amazonaws.com. [3.41.210.134]) by smtp.gmail.com with ESMTPSA id af79cd13be357-949bb418241sm2093513285a.38.2026.11.28.10.13.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Nov 2026 10:13:30 -0800 (PST) Message-Id: In-Reply-To: References: From: "Harald Nordgren via GitGitGadget" Date: Sat, 28 Nov 2026 18:13:30 +0000 Subject: [PATCH v2] config: make the suggested "set" command safe to paste Fcc: Sent Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 To: git@vger.kernel.org Cc: Ben Knoble , Phillip Wood , Harald Nordgren , Harald Nordgren 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 -- gitgitgadget