Skip to content

Commit 154b5bf

Browse files
committed
Merge branch 'jh/alias-i18n-fixes' into jch
Further update to the i18n alias support to avoid regressions. * jh/alias-i18n-fixes: alias: restore support for simple dotted aliases
2 parents 2f2333a + 21186cf commit 154b5bf

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

alias.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,20 @@ static int config_alias_cb(const char *var, const char *value,
3434
if (subsection && !subsection_len)
3535
subsection = NULL;
3636

37-
if (subsection && strcmp(key, "command"))
38-
return 0;
37+
if (subsection && strcmp(key, "command")) {
38+
/*
39+
* We have historically supported the "alias.name" form when
40+
* "name" happens to contain dots (e.g., alias.foo.bar to allow
41+
* "git foo.bar". But our parsing above would split that into
42+
* subsection "foo".
43+
*
44+
* If we do not understand the final key in a subsection-style
45+
* variable, fall back to treating it as a two-level alias.
46+
*/
47+
key = var + strlen("alias.");
48+
subsection = NULL;
49+
subsection_len = 0;
50+
}
3951

4052
if (data->alias) {
4153
int match;

help.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,14 +592,21 @@ static int git_unknown_cmd_config(const char *var, const char *value,
592592
/* Also use aliases for command lookup */
593593
if (!parse_config_key(var, "alias", &subsection, &subsection_len,
594594
&key)) {
595+
size_t key_len = strlen(key);
596+
595597
if (subsection) {
596598
/* [alias "name"] command = value */
597599
if (!strcmp(key, "command"))
598600
add_cmdname(&cfg->aliases, subsection,
599601
subsection_len);
602+
else {
603+
key = var + strlen("alias.");
604+
key_len = strlen(key);
605+
add_cmdname(&cfg->aliases, key, key_len);
606+
}
600607
} else {
601608
/* alias.name = value */
602-
add_cmdname(&cfg->aliases, key, strlen(key));
609+
add_cmdname(&cfg->aliases, key, key_len);
603610
}
604611
}
605612

t/t0014-alias.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ test_expect_success 'subsection syntax works' '
128128
test_grep "ran-subsection" output
129129
'
130130

131+
test_expect_success 'simple dotted alias syntax still works' '
132+
test_config alias.simple.dotted "!echo ran-simple-dotted" &&
133+
git simple.dotted >output &&
134+
test_grep "ran-simple-dotted" output
135+
'
136+
131137
test_expect_success 'subsection syntax only accepts command key' '
132138
test_config alias.invalid.notcommand value &&
133139
test_must_fail git invalid 2>error &&
@@ -183,6 +189,12 @@ test_expect_success 'subsection aliases listed in help -a' '
183189
test_grep "förgrena" output
184190
'
185191

192+
test_expect_success 'simple dotted aliases listed in help -a' '
193+
test_config alias.simple.listed "!echo test" &&
194+
git help -a >output &&
195+
test_grep "simple.listed" output
196+
'
197+
186198
test_expect_success 'empty subsection treated as no subsection' '
187199
test_config "alias..something" "!echo foobar" &&
188200
git something >actual &&

0 commit comments

Comments
 (0)