From ac1f12a9de4b79b176a08f524fecdb092ff00e74 Mon Sep 17 00:00:00 2001 From: Jonatan Holmgren Date: Wed, 18 Feb 2026 22:57:36 +0100 Subject: alias: support non-alphanumeric names via subsection syntax MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Git alias names are limited to ASCII alphanumeric characters and dashes because aliases are implemented as config variable names. This prevents aliases being created in languages using characters outside that range. Add support for arbitrary alias names by using config subsections: [alias "förgrena"] command = branch The subsection name is matched as-is (case-sensitive byte comparison), while the existing definition without a subsection (e.g., "[alias] co = checkout") remains case-insensitive for backward compatibility. This uses existing config infrastructure since subsections already support arbitrary bytes, and avoids introducing Unicode normalization. Also teach the help subsystem about the new syntax so that "git help -a" properly lists subsection aliases and the autocorrect feature can suggest them. Use utf8_strwidth() instead of strlen() for column alignment so that non-ASCII alias names display correctly. Suggested-by: Jeff King Signed-off-by: Jonatan Holmgren Signed-off-by: Junio C Hamano --- help.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'help.c') diff --git a/help.c b/help.c index a781ebb98d..82fb2eaa3f 100644 --- a/help.c +++ b/help.c @@ -21,6 +21,7 @@ #include "fsmonitor-ipc.h" #include "repository.h" #include "alias.h" +#include "utf8.h" #ifndef NO_CURL #include "git-curl-compat.h" /* For LIBCURL_VERSION only */ @@ -108,7 +109,7 @@ static void print_command_list(const struct cmdname_help *cmds, for (i = 0; cmds[i].name; i++) { if (cmds[i].category & mask) { - size_t len = strlen(cmds[i].name); + size_t len = utf8_strwidth(cmds[i].name); printf(" %s ", cmds[i].name); if (longest > len) mput_char(' ', longest - len); @@ -493,7 +494,7 @@ static void list_all_cmds_help_aliases(int longest) string_list_sort(&alias_list); for (i = 0; i < alias_list.nr; i++) { - size_t len = strlen(alias_list.items[i].string); + size_t len = utf8_strwidth(alias_list.items[i].string); if (longest < len) longest = len; } @@ -592,8 +593,15 @@ static int git_unknown_cmd_config(const char *var, const char *value, /* Also use aliases for command lookup */ if (!parse_config_key(var, "alias", &subsection, &subsection_len, &key)) { - if (!subsection) + if (subsection) { + /* [alias "name"] command = value */ + if (!strcmp(key, "command")) + add_cmdname(&cfg->aliases, subsection, + subsection_len); + } else { + /* alias.name = value */ add_cmdname(&cfg->aliases, key, strlen(key)); + } } return 0; -- cgit v1.3-5-g9baa