Skip to content

Commit f5bbbf9

Browse files
committed
Merge branch 'ef/alias-via-run-command'
* ef/alias-via-run-command: alias: use run_command api to execute aliases
2 parents 05f08e4 + 7f51f8b commit f5bbbf9

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

git.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -177,24 +177,24 @@ static int handle_alias(int *argcp, const char ***argv)
177177
alias_string = alias_lookup(alias_command);
178178
if (alias_string) {
179179
if (alias_string[0] == '!') {
180+
const char **alias_argv;
181+
int argc = *argcp, i;
182+
180183
commit_pager_choice();
181-
if (*argcp > 1) {
182-
struct strbuf buf;
183-
184-
strbuf_init(&buf, PATH_MAX);
185-
strbuf_addstr(&buf, alias_string);
186-
sq_quote_argv(&buf, (*argv) + 1, PATH_MAX);
187-
free(alias_string);
188-
alias_string = buf.buf;
189-
}
190-
trace_printf("trace: alias to shell cmd: %s => %s\n",
191-
alias_command, alias_string + 1);
192-
ret = system(alias_string + 1);
193-
if (ret >= 0 && WIFEXITED(ret) &&
194-
WEXITSTATUS(ret) != 127)
195-
exit(WEXITSTATUS(ret));
196-
die("Failed to run '%s' when expanding alias '%s'",
197-
alias_string + 1, alias_command);
184+
185+
/* build alias_argv */
186+
alias_argv = xmalloc(sizeof(*alias_argv) * (argc + 1));
187+
alias_argv[0] = alias_string + 1;
188+
for (i = 1; i < argc; ++i)
189+
alias_argv[i] = (*argv)[i];
190+
alias_argv[argc] = NULL;
191+
192+
ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
193+
if (ret >= 0) /* normal exit */
194+
exit(ret);
195+
196+
die_errno("While expanding alias '%s': '%s'",
197+
alias_command, alias_string + 1);
198198
}
199199
count = split_cmdline(alias_string, &new_argv);
200200
if (count < 0)

0 commit comments

Comments
 (0)