Skip to content

Commit 7d9c821

Browse files
committed
PR 128364: Pass the exit code to the post-command hook proc. This means that a call
Pass the exit code to the post-command hook proc. This means that a call "git status" will result in the following pre/post-command: ".git/hooks/pre-command status" ".git/hooks/post-command status --exit_code=0" Related work items: #627141
1 parent b7633a3 commit 7d9c821

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

git.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ static int handle_alias(int *argcp, const char ***argv)
307307
*/
308308
struct argv_array sargv = ARGV_ARRAY_INIT;
309309
int pre_command_hook = 0;
310+
int exit_code = -1;
310311
static void post_command_hook_atexit(void)
311312
{
312313
struct child_process cp = CHILD_PROCESS_INIT;
@@ -315,6 +316,7 @@ static void post_command_hook_atexit(void)
315316
if (hook) {
316317
argv_array_push(&cp.args, hook);
317318
argv_array_pushv(&cp.args, sargv.argv);
319+
argv_array_pushf(&cp.args, "--exit_code=%u", exit_code);
318320
run_command(&cp);
319321
}
320322

@@ -403,7 +405,7 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
403405

404406
trace_argv_printf(argv, "trace: built-in: git");
405407

406-
status = p->fn(argc, argv, prefix);
408+
exit_code = status = p->fn(argc, argv, prefix);
407409
if (status)
408410
return status;
409411

@@ -623,7 +625,7 @@ static void execv_dashed_external(const char **argv)
623625
* if we fail because the command is not found, it is
624626
* OK to return. Otherwise, we just pass along the status code.
625627
*/
626-
status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT);
628+
exit_code = status = run_command_v_opt(argv, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT);
627629
if (status >= 0 || errno != ENOENT)
628630
exit(status);
629631

0 commit comments

Comments
 (0)