Skip to content

Commit 291ef5b

Browse files
ianwgitster
authored andcommitted
run-command: show prepared command
This adds a trace point in start_command so we can see the full command invocation without having to resort to strace/code inspection. For example: $ GIT_TRACE=1 git test foo git.c:755 trace: exec: git-test foo run-command.c:657 trace: run_command: git-test foo run-command.c:657 trace: run_command: 'echo $*' foo run-command.c:749 trace: start_command: /bin/sh -c 'echo $* "$@"' 'echo $*' foo Prior changes have made the documentation around the internals of the alias command execution clearer, but I have still found this detailed view of the aliased command being run helpful for debugging purposes. A test case is added to ensure the full command output is present in the execution flow. Signed-off-by: Ian Wienand <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d35a743 commit 291ef5b

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

run-command.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,8 @@ int start_command(struct child_process *cmd)
746746
goto end_of_spawn;
747747
}
748748

749+
trace_argv_printf(&argv.v[1], "trace: start_command:");
750+
749751
if (pipe(notify_pipe))
750752
notify_pipe[0] = notify_pipe[1] = -1;
751753

@@ -913,6 +915,7 @@ int start_command(struct child_process *cmd)
913915
else if (cmd->use_shell)
914916
cmd->args.v = prepare_shell_cmd(&nargv, sargv);
915917

918+
trace_argv_printf(cmd->args.v, "trace: start_command:");
916919
cmd->pid = mingw_spawnvpe(cmd->args.v[0], cmd->args.v,
917920
(char**) cmd->env.v,
918921
cmd->dir, fhin, fhout, fherr);

t/t0014-alias.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,15 @@ test_expect_success 'run-command formats empty args properly' '
4444
test_cmp expect actual
4545
'
4646

47+
test_expect_success 'tracing a shell alias with arguments shows trace of prepared command' '
48+
cat >expect <<-EOF &&
49+
trace: start_command: SHELL -c ${SQ}echo \$* "\$@"${SQ} ${SQ}echo \$*${SQ} arg
50+
EOF
51+
git config alias.echo "!echo \$*" &&
52+
env GIT_TRACE=1 git echo arg 2>output &&
53+
# redact platform differences
54+
sed -n -e "s/^\(trace: start_command:\) .* -c /\1 SHELL -c /p" output >actual &&
55+
test_cmp expect actual
56+
'
57+
4758
test_done

0 commit comments

Comments
 (0)