Skip to content

Commit 6589294

Browse files
jonatan-holmgrengitster
authored andcommitted
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 = <value> Add tests covering both the empty-subsection compatibility case and the leading-dot alias via the new syntax. Signed-off-by: Jonatan Holmgren <jonatan@jontes.page> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 2e3a987 commit 6589294

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

alias.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ static int config_alias_cb(const char *var, const char *value,
3030
* - [alias "name"]
3131
* command = value (with subsection, case-sensitive)
3232
*/
33+
/* Treat [alias ""] (empty subsection) the same as plain [alias]. */
34+
if (subsection && !subsection_len)
35+
subsection = NULL;
36+
3337
if (subsection && strcmp(key, "command"))
3438
return 0;
3539

t/t0014-alias.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,4 +183,18 @@ test_expect_success 'subsection aliases listed in help -a' '
183183
test_grep "förgrena" output
184184
'
185185

186+
test_expect_success 'empty subsection treated as no subsection' '
187+
test_config "alias..something" "!echo foobar" &&
188+
git something >actual &&
189+
echo foobar >expect &&
190+
test_cmp expect actual
191+
'
192+
193+
test_expect_success 'alias with leading dot via subsection syntax' '
194+
test_config alias.".something".command "!echo foobar" &&
195+
git .something >actual &&
196+
echo foobar >expect &&
197+
test_cmp expect actual
198+
'
199+
186200
test_done

0 commit comments

Comments
 (0)