Skip to content

Commit 42afcb9

Browse files
committed
Merge branch 'jh/alias-i18n-fixes'
Further update to the i18n alias support to avoid regressions. * jh/alias-i18n-fixes: doc: fix list continuation in alias.adoc git, help: fix memory leaks in alias listing alias: treat empty subsection [alias ""] as plain [alias] doc: fix list continuation in alias subsection example
2 parents 08c3609 + 73cc549 commit 42afcb9

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

Documentation/config/alias.adoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@ Examples:
3030
----
3131
+
3232
With a Git alias defined, e.g.,
33-
33+
+
3434
$ git config --global alias.last "cat-file commit HEAD"
3535
# Which is equivalent to
3636
$ git config --global alias.last.command "cat-file commit HEAD"
37-
38-
`git last` is equivalent to `git cat-file commit HEAD`. To avoid
39-
confusion and troubles with script usage, aliases that
37+
+
38+
`git last` is equivalent to `git cat-file commit HEAD`.
39+
+
40+
To avoid confusion and troubles with script usage, aliases that
4041
hide existing Git commands are ignored except for deprecated
4142
commands. Arguments are split by
4243
spaces, the usual shell quoting and escaping are supported.

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

git.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int list_cmds(const char *spec)
119119
}
120120
for (size_t i = 0; i < list.nr; i++)
121121
puts(list.items[i].string);
122-
string_list_clear(&list, 0);
122+
string_list_clear(&list, 1);
123123
return 0;
124124
}
125125

help.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ void list_cmds_by_config(struct string_list *list)
422422
if (repo_config_get_string_tmp(the_repository, "completion.commands", &cmd_list))
423423
return;
424424

425-
string_list_sort_u(list, 0);
425+
string_list_sort_u(list, 1);
426426

427427
while (*cmd_list) {
428428
struct strbuf sb = STRBUF_INIT;

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)