* [PATCH] config: suggest the correct form when key contains "="
@ 2026-05-13 13:58 Harald Nordgren via GitGitGadget
2026-05-14 21:26 ` Junio C Hamano
2026-05-16 12:52 ` [PATCH v2] config: suggest the correct form when key contains "=" in set context Harald Nordgren via GitGitGadget
0 siblings, 2 replies; 9+ messages in thread
From: Harald Nordgren via GitGitGadget @ 2026-05-13 13:58 UTC (permalink / raw)
To: git; +Cc: Harald Nordgren, Harald Nordgren
From: Harald Nordgren <haraldnordgren@gmail.com>
When a user types "git config foo.bar=baz", git_config_parse_key()
rejects the key with "error: invalid key: foo.bar=baz" but gives no
indication of what the user should have written. The mistake is a
common one for users who reach for INI-file syntax or for the
"--flag=value" convention used by other command-line tools.
Since "=" is never a valid character in a config key, treat its
presence as a strong signal of this specific mistake and follow the
error with a one-line suggestion in the "(did you mean ...)" style
used elsewhere in git, e.g.:
$ git config pull.rebase=false
error: invalid key: pull.rebase=false
(did you mean "git config set pull.rebase false"?)
The hint is emitted only when the offending character is "="; other
invalid characters (newlines, "@", etc.) keep their existing error
unchanged.
Signed-off-by: Harald Nordgren <harald.nordgren@kostdoktorn.se>
---
config: suggest the correct form when key contains "="
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2302%2FHaraldNordgren%2Fconfig-hint-equals-key-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2302/HaraldNordgren/config-hint-equals-key-v1
Pull-Request: https://github.com/git/git/pull/2302
config.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/config.c b/config.c
index a1b92fe083..6e658d71d1 100644
--- a/config.c
+++ b/config.c
@@ -580,6 +580,10 @@ int git_config_parse_key(const char *key, char **store_key, size_t *baselen_)
if (!iskeychar(c) ||
(i == baselen + 1 && !isalpha(c))) {
error(_("invalid key: %s"), key);
+ if (c == '=')
+ fprintf_ln(stderr,
+ _(" (did you mean \"git config set %.*s %s\"?)"),
+ (int)i, key, key + i + 1);
goto out_free_ret_1;
}
c = tolower(c);
base-commit: 59ff4886a579f4bc91e976fe18590b9ae02c7a08
--
gitgitgadget
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH] config: suggest the correct form when key contains "=" 2026-05-13 13:58 [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren via GitGitGadget @ 2026-05-14 21:26 ` Junio C Hamano 2026-05-14 22:16 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren 2026-05-16 12:51 ` [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren 2026-05-16 12:52 ` [PATCH v2] config: suggest the correct form when key contains "=" in set context Harald Nordgren via GitGitGadget 1 sibling, 2 replies; 9+ messages in thread From: Junio C Hamano @ 2026-05-14 21:26 UTC (permalink / raw) To: Harald Nordgren via GitGitGadget; +Cc: git, Harald Nordgren "Harald Nordgren via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Harald Nordgren <haraldnordgren@gmail.com> > > When a user types "git config foo.bar=baz", git_config_parse_key() > rejects the key with "error: invalid key: foo.bar=baz" but gives no > indication of what the user should have written. The mistake is a > common one for users who reach for INI-file syntax or for the > "--flag=value" convention used by other command-line tools. > > Since "=" is never a valid character in a config key, treat its > presence as a strong signal of this specific mistake and follow the > error with a one-line suggestion in the "(did you mean ...)" style > used elsewhere in git, e.g.: > > $ git config pull.rebase=false > error: invalid key: pull.rebase=false > (did you mean "git config set pull.rebase false"?) If the command line were git config get foo.bar=baz git config set foo.bar=baz nitfol we shouldn't give an extra "did you mean?" at all. The only cases you may want to do the "did you mean?" I think are git config foo.bar=baz git config set foo.bar=baz And I think git_config_parse_key() is at a way too low level to tell in what context we are seeing this faulty key to guess end-user's intention to limit our "did you mean?" I also wonder if, given that "=" in anywhere other than three-level names, is invalid, we should just start accept git config foo.bar=baz git config set foo.bar=baz and interpret them as git config set foo.bar baz We of course need to be careful about non-invalid keys, i.e. git config foo.bar=baz.boo is a request to read the value of that named variable, i.e. [foo "bar=baz"] boo = its value so either you start offering unsolicited "did you mean?" or accepting tokens with '=' in them as new style "set", you need to be extra careful not to trigger a false positive. ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH] fetch: add fetch.pruneLocalBranches config 2026-05-14 21:26 ` Junio C Hamano @ 2026-05-14 22:16 ` Harald Nordgren 2026-05-15 1:28 ` Junio C Hamano 2026-05-16 12:51 ` [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren 1 sibling, 1 reply; 9+ messages in thread From: Harald Nordgren @ 2026-05-14 22:16 UTC (permalink / raw) To: gitster; +Cc: git, gitgitgadget, haraldnordgren > I also wonder if, given that "=" in anywhere other than three-level > names, is invalid, we should just start accept > > git config foo.bar=baz > git config set foo.bar=baz > > and interpret them as > > git config set foo.bar baz That sounds good too! Probably even better. Harald ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] fetch: add fetch.pruneLocalBranches config 2026-05-14 22:16 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren @ 2026-05-15 1:28 ` Junio C Hamano 2026-05-15 7:56 ` Email issues Harald Nordgren 2026-05-15 9:39 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren 0 siblings, 2 replies; 9+ messages in thread From: Junio C Hamano @ 2026-05-15 1:28 UTC (permalink / raw) To: Harald Nordgren; +Cc: git, gitgitgadget Harald Nordgren <haraldnordgren@gmail.com> writes: >> I also wonder if, given that "=" in anywhere other than three-level >> names, is invalid, we should just start accept >> >> git config foo.bar=baz >> git config set foo.bar=baz >> >> and interpret them as >> >> git config set foo.bar baz > > That sounds good too! Probably even better. > > > Harald Why do I get the above, which apparently is a response to my review for [PATCH] config: suggest the correct form when key contains "=" under this thread? Am I dealing with some sort of mechanical slop? ^ permalink raw reply [flat|nested] 9+ messages in thread
* Email issues 2026-05-15 1:28 ` Junio C Hamano @ 2026-05-15 7:56 ` Harald Nordgren 2026-05-15 12:02 ` Kristoffer Haugsbakk 2026-05-15 9:39 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren 1 sibling, 1 reply; 9+ messages in thread From: Harald Nordgren @ 2026-05-15 7:56 UTC (permalink / raw) To: gitster; +Cc: git, gitgitgadget, haraldnordgren > Why do I get the above, which apparently is a response to my review > for > > [PATCH] config: suggest the correct form when key contains "=" > > under this thread? Am I dealing with some sort of mechanical slop? I think the problem here is my email sending process is not good. I edit all the emails in Sublime text, where I keep the same file for all different threads. I have the subject line as the first line of the file and like you notice I forget to change it sometimes. I keep each of the topics bookmarked like this, https://lore.kernel.org/git/xmqqecjdea13.fsf@gitster.g/, and then utilize that like to send the email ``` git send-email \ --in-reply-to=xmqqecjdea13.fsf@gitster.g \ --to=gitster@pobox.com \ --cc=git@vger.kernel.org \ --cc=gitgitgadget@gmail.com \ --cc=haraldnordgren@gmail.com \ /path/to/YOUR_REPLY ``` I tried playing with neomutt and and email client replacement, but that adds the complexity of downloading a new mbox file for each reply, it didn't seem easier, but maybe it is. How do you handle emails? Harald ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Email issues 2026-05-15 7:56 ` Email issues Harald Nordgren @ 2026-05-15 12:02 ` Kristoffer Haugsbakk 0 siblings, 0 replies; 9+ messages in thread From: Kristoffer Haugsbakk @ 2026-05-15 12:02 UTC (permalink / raw) To: Harald Nordgren, Junio C Hamano; +Cc: git, Koji Nakamaru On Fri, May 15, 2026, at 09:56, Harald Nordgren wrote: >> Why do I get the above, which apparently is a response to my review >> for >> >> [PATCH] config: suggest the correct form when key contains "=" >> >> under this thread? Am I dealing with some sort of mechanical slop? > > I think the problem here is my email sending process is not good. I edit > all the emails in Sublime text, where I keep the same file for all > different threads. > > I have the subject line as the first line of the file and like you notice I > forget to change it sometimes. > > I keep each of the topics bookmarked like this, > https://lore.kernel.org/git/xmqqecjdea13.fsf@gitster.g/, and then utilize > that like to send the email > > ``` > git send-email \ > --in-reply-to=xmqqecjdea13.fsf@gitster.g \ > --to=gitster@pobox.com \ > --cc=git@vger.kernel.org \ > --cc=gitgitgadget@gmail.com \ > --cc=haraldnordgren@gmail.com \ > /path/to/YOUR_REPLY > ``` > > I tried playing with neomutt and and email client replacement, but that > adds the complexity of downloading a new mbox file for each reply, it > didn't seem easier, but maybe it is. > > How do you handle emails? I use the Fastmail webmail client for regular non-patch emails. The only things it messes up so far is long lines in replies to patches. I edit the emails in a text editor. And sometimes I have left multiple drafts before sending them and switched them around. Only to see my mistake on the Lore archive later. :) But by and large it works just fine. I haven't had the need for a more ergonomic setup. -- Sent from mobile ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] fetch: add fetch.pruneLocalBranches config 2026-05-15 1:28 ` Junio C Hamano 2026-05-15 7:56 ` Email issues Harald Nordgren @ 2026-05-15 9:39 ` Harald Nordgren 1 sibling, 0 replies; 9+ messages in thread From: Harald Nordgren @ 2026-05-15 9:39 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, gitgitgadget > Why do I get the above, which apparently is a response to my review > for > > [PATCH] config: suggest the correct form when key contains "=" > > under this thread? Am I dealing with some sort of mechanical slop? (Testing plain text email sending via Gmail for a less error-prone workflow, does it still add the CC's correctly?) Harald ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] config: suggest the correct form when key contains "=" 2026-05-14 21:26 ` Junio C Hamano 2026-05-14 22:16 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren @ 2026-05-16 12:51 ` Harald Nordgren 1 sibling, 0 replies; 9+ messages in thread From: Harald Nordgren @ 2026-05-16 12:51 UTC (permalink / raw) To: Junio C Hamano; +Cc: Harald Nordgren via GitGitGadget, git > And I think git_config_parse_key() is at a way too low level to tell > in what context we are seeing this faulty key to guess end-user's > intention to limit our "did you mean?" > > I also wonder if, given that "=" in anywhere other than three-level > names, is invalid, we should just start accept > > git config foo.bar=baz > git config set foo.bar=baz > > and interpret them as > > git config set foo.bar baz I tried implementing a version to be more liberal in what to accept, but the implementation became very complex. Moving in the other direction: show the warning, but try to make it more correct. (Also switching over to replying to emails with Gmail with 'plain text mode'), hopefully there will be less miss-sends that end up on the wrong topic from now on.) Harald ^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH v2] config: suggest the correct form when key contains "=" in set context 2026-05-13 13:58 [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren via GitGitGadget 2026-05-14 21:26 ` Junio C Hamano @ 2026-05-16 12:52 ` Harald Nordgren via GitGitGadget 1 sibling, 0 replies; 9+ messages in thread From: Harald Nordgren via GitGitGadget @ 2026-05-16 12:52 UTC (permalink / raw) To: git; +Cc: Kristoffer Haugsbakk, Harald Nordgren, Harald Nordgren From: Harald Nordgren <haraldnordgren@gmail.com> A user who types "git config pull.rebase=false" gets only "error: invalid key: pull.rebase=false" with no clue what went wrong. Emit a "did you mean ..." hint suggesting the split form. Restrict it to plausible-set contexts ("git config set", bare "git config <key>", and their 2-arg forms); explicit "get"/"unset" keep the existing error. "=" is legal inside a subsection, so only fire when "=" lands after the last ".". When the user supplied a separate value, use it in the suggestion instead of the suffix after "=": $ git config set pull.rebase=false true error: invalid key: pull.rebase=false hint: did you mean "git config set pull.rebase true"? Signed-off-by: Harald Nordgren <harald.nordgren@kostdoktorn.se> --- config: suggest the correct form when key contains "=" * Hint moved from git_config_parse_key() to a new advise_setting_with_equals() in builtin/config.c; wired only into set and bare paths. * Only fires when = is after the last .; 2-arg forms use the user's value. Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2302%2FHaraldNordgren%2Fconfig-hint-equals-key-v2 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2302/HaraldNordgren/config-hint-equals-key-v2 Pull-Request: https://github.com/git/git/pull/2302 Range-diff vs v1: 1: 56eb3ce6fd < -: ---------- config: suggest the correct form when key contains "=" -: ---------- > 1: 40d9eb3e5c config: suggest the correct form when key contains "=" in set context builtin/config.c | 30 ++++++++++++++++++++++++++++++ t/t1300-config.sh | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/builtin/config.c b/builtin/config.c index cf4ba0f7cc..f14a30e720 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1,6 +1,7 @@ #define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" #include "abspath.h" +#include "advice.h" #include "config.h" #include "color.h" #include "date.h" @@ -210,6 +211,22 @@ static void check_argc(int argc, int min, int max) exit(129); } +static void advise_setting_with_equals(const char *key, const char *value) +{ + const char *last_dot = strrchr(key, '.'); + const char *eq; + + if (!last_dot) + return; + eq = strchr(last_dot + 1, '='); + if (!eq) + return; + if (!value) + value = eq + 1; + advise(_("did you mean \"git config set %.*s %s\"?"), + (int)(eq - key), key, value); +} + static void show_config_origin(const struct config_display_options *opts, const struct key_value_info *kvi, struct strbuf *buf) @@ -1133,6 +1150,11 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix, argc = parse_options(argc, argv, prefix, opts, builtin_config_set_usage, PARSE_OPT_STOP_AT_NON_OPTION); + if (argc == 1 && strchr(argv[0], '=')) { + error(_("wrong number of arguments, should be 2")); + advise_setting_with_equals(argv[0], NULL); + exit(129); + } check_argc(argc, 2, 2); if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern) @@ -1160,6 +1182,8 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix, error(_("cannot overwrite multiple values with a single value\n" " Use --value=<pattern>, --append or --all to change %s."), argv[0]); } + if (ret == CONFIG_INVALID_KEY) + advise_setting_with_equals(argv[0], argv[1]); location_options_release(&location_opts); free(comment); @@ -1371,6 +1395,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) }; char *value = NULL, *comment = NULL; int ret = 0; + int actions_implicit; struct key_value_info default_kvi = KVI_INIT; argc = parse_options(argc, argv, prefix, opts, @@ -1385,6 +1410,7 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) exit(129); } + actions_implicit = (actions == 0); if (actions == 0) switch (argc) { case 1: actions = ACTION_GET; break; @@ -1485,6 +1511,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) if (ret == CONFIG_NOTHING_SET) error(_("cannot overwrite multiple values with a single value\n" " Use a regexp, --add or --replace-all to change %s."), argv[0]); + else if (ret == CONFIG_INVALID_KEY) + advise_setting_with_equals(argv[0], argv[1]); } else if (actions == ACTION_SET_ALL) { check_write(&location_opts.source); @@ -1515,6 +1543,8 @@ static int cmd_config_actions(int argc, const char **argv, const char *prefix) check_argc(argc, 1, 2); ret = get_value(&location_opts, &display_opts, argv[0], argv[1], 0, flags); + if (ret == CONFIG_INVALID_KEY && actions_implicit) + advise_setting_with_equals(argv[0], NULL); } else if (actions == ACTION_GET_ALL) { check_argc(argc, 1, 2); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 128971ee12..f46c081413 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -462,6 +462,53 @@ test_expect_success 'invalid key' ' test_must_fail git config inval.2key blabla ' +test_expect_success 'misplaced "=" in key: bare 1-arg form hints' ' + test_must_fail git config pull.rebase=false 2>err && + test_grep "invalid key: pull\\.rebase=false" err && + test_grep "did you mean .git config set pull\\.rebase false." err +' + +test_expect_success 'misplaced "=" in key: bare 2-arg form uses given value' ' + test_must_fail git config pull.rebase=false true 2>err && + test_grep "did you mean .git config set pull\\.rebase true." err +' + +test_expect_success 'misplaced "=" in key: set subcommand uses given value' ' + test_must_fail git config set pull.rebase=false true 2>err && + test_grep "did you mean .git config set pull\\.rebase true." err +' + +test_expect_success 'misplaced "=" in key: set with single arg hints' ' + test_must_fail git config set pull.rebase=false 2>err && + test_grep "wrong number of arguments" err && + test_grep "did you mean .git config set pull\\.rebase false." err +' + +test_expect_success 'misplaced "=" in key: explicit --get does not hint' ' + test_must_fail git config --get pull.rebase=false 2>err && + test_grep "invalid key: pull\\.rebase=false" err && + test_grep ! "did you mean" err +' + +test_expect_success 'misplaced "=" in key: get subcommand does not hint' ' + test_must_fail git config get pull.rebase=false 2>err && + test_grep ! "did you mean" err +' + +test_expect_success 'misplaced "=" in key: unset subcommand does not hint' ' + test_must_fail git config unset pull.rebase=false 2>err && + test_grep ! "did you mean" err +' + +test_expect_success '"=" inside subsection is valid, no hint' ' + test_when_finished "rm -f subsection.cfg" && + git config set -f subsection.cfg foo.bar=baz.boo qux 2>err && + test_grep ! "did you mean" err && + echo qux >expect && + git config get -f subsection.cfg foo.bar=baz.boo >actual && + test_cmp expect actual +' + test_expect_success 'correct key' ' git config 123456.a123 987 ' base-commit: 59ff4886a579f4bc91e976fe18590b9ae02c7a08 -- gitgitgadget ^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-05-16 12:52 UTC | newest] Thread overview: 9+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-05-13 13:58 [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren via GitGitGadget 2026-05-14 21:26 ` Junio C Hamano 2026-05-14 22:16 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren 2026-05-15 1:28 ` Junio C Hamano 2026-05-15 7:56 ` Email issues Harald Nordgren 2026-05-15 12:02 ` Kristoffer Haugsbakk 2026-05-15 9:39 ` [PATCH] fetch: add fetch.pruneLocalBranches config Harald Nordgren 2026-05-16 12:51 ` [PATCH] config: suggest the correct form when key contains "=" Harald Nordgren 2026-05-16 12:52 ` [PATCH v2] config: suggest the correct form when key contains "=" in set context Harald Nordgren via GitGitGadget
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox