diff --git a/Documentation/config/alias.adoc b/Documentation/config/alias.adoc index 115fdbb1e3..26949a0ccb 100644 --- a/Documentation/config/alias.adoc +++ b/Documentation/config/alias.adoc @@ -30,13 +30,14 @@ Examples: ---- + With a Git alias defined, e.g., - ++ $ git config --global alias.last "cat-file commit HEAD" # Which is equivalent to $ git config --global alias.last.command "cat-file commit HEAD" ++ +`git last` is equivalent to `git cat-file commit HEAD`. -`git last` is equivalent to `git cat-file commit HEAD`. To avoid -confusion and troubles with script usage, aliases that +To avoid confusion and troubles with script usage, aliases that hide existing Git commands are ignored except for deprecated commands. Arguments are split by spaces, the usual shell quoting and escaping are supported. 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/git.c b/git.c index 6480ff8373..2b212e6675 100644 --- a/git.c +++ b/git.c @@ -119,7 +119,7 @@ static int list_cmds(const char *spec) } for (size_t i = 0; i < list.nr; i++) puts(list.items[i].string); - string_list_clear(&list, 0); + string_list_clear(&list, 1); return 0; } diff --git a/help.c b/help.c index 95f576c5c8..3e59d07c37 100644 --- a/help.c +++ b/help.c @@ -422,7 +422,7 @@ void list_cmds_by_config(struct string_list *list) if (repo_config_get_string_tmp(the_repository, "completion.commands", &cmd_list)) return; - string_list_sort_u(list, 0); + string_list_sort_u(list, 1); while (*cmd_list) { struct strbuf sb = STRBUF_INIT; 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