Skip to content

Commit a2f8028

Browse files
dschogitster
authored andcommitted
Make '!' aliases more useful
When an alias starts with an exclamation mark, the rest is interpreted as a shell command. However, all arguments passed to git used to be ignored. Now you can have an alias like $ git config alias.e '!echo' and $ git e Hello World does what you expect it to do. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7627943 commit a2f8028

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

git.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,21 @@ static int handle_alias(int *argcp, const char ***argv)
181181
git_config(git_alias_config);
182182
if (alias_string) {
183183
if (alias_string[0] == '!') {
184+
if (*argcp > 1) {
185+
int i, sz = PATH_MAX;
186+
char *s = xmalloc(sz), *new_alias = s;
187+
188+
add_to_string(&s, &sz, alias_string, 0);
189+
free(alias_string);
190+
alias_string = new_alias;
191+
for (i = 1; i < *argcp &&
192+
!add_to_string(&s, &sz, " ", 0) &&
193+
!add_to_string(&s, &sz, (*argv)[i], 1)
194+
; i++)
195+
; /* do nothing */
196+
if (!sz)
197+
die("Too many or long arguments");
198+
}
184199
trace_printf("trace: alias to shell cmd: %s => %s\n",
185200
alias_command, alias_string + 1);
186201
ret = system(alias_string + 1);

0 commit comments

Comments
 (0)