From 65892943750b0c66017389f0233ba5a6a7205165 Mon Sep 17 00:00:00 2001 From: Jonatan Holmgren Date: Thu, 26 Feb 2026 21:53:27 +0100 Subject: [PATCH] alias: treat empty subsection [alias ""] as plain [alias] When git-config stores a key of the form alias..name, it records it under an empty subsection ([alias ""]). The new subsection-aware alias lookup would see a non-NULL but zero-length subsection and fall into the subsection code path, where it required a "command" key and thus silently ignored the entry. Normalize an empty subsection to NULL before any further processing so that entries stored this way continue to work as plain case-insensitive aliases, matching the pre-subsection behaviour. Users who relied on alias..name to create an alias literally named ".name" may want to migrate to subsection syntax, which looks less confusing: [alias ".name"] command = Add tests covering both the empty-subsection compatibility case and the leading-dot alias via the new syntax. Signed-off-by: Jonatan Holmgren Signed-off-by: Junio C Hamano --- alias.c | 4 ++++ t/t0014-alias.sh | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/alias.c b/alias.c index 0d636278bc..ec9833dd30 100644 --- a/alias.c +++ b/alias.c @@ -30,6 +30,10 @@ static int config_alias_cb(const char *var, const char *value, * - [alias "name"] * command = value (with subsection, case-sensitive) */ + /* Treat [alias ""] (empty subsection) the same as plain [alias]. */ + if (subsection && !subsection_len) + subsection = NULL; + if (subsection && strcmp(key, "command")) return 0; diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 34bbdb51c5..68b4903cbf 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -183,4 +183,18 @@ test_expect_success 'subsection aliases listed in help -a' ' test_grep "förgrena" output ' +test_expect_success 'empty subsection treated as no subsection' ' + test_config "alias..something" "!echo foobar" && + git something >actual && + echo foobar >expect && + test_cmp expect actual +' + +test_expect_success 'alias with leading dot via subsection syntax' ' + test_config alias.".something".command "!echo foobar" && + git .something >actual && + echo foobar >expect && + test_cmp expect actual +' + test_done -- 2.52.0