Hooks like "post-checkout" require that hooks have a different working directory than the initial process. Pipe that directly through to struct child_process. Because we can just run 'git -C <some-dir> hook run ...' it shouldn't be necessary to pipe this option through the frontend. In fact, this reduces the possibility of users running hooks which affect some part of the filesystem outside of the repo in question. Signed-off-by: Emily Shaffer <emilyshaffer@xxxxxxxxxx> --- Notes: Needed later for "post-checkout" conversion. hook.c | 2 ++ hook.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/hook.c b/hook.c index fe8860860b..67ad3aa747 100644 --- a/hook.c +++ b/hook.c @@ -251,6 +251,7 @@ void run_hooks_opt_init_sync(struct run_hooks_opt *o) o->path_to_stdin = NULL; o->run_hookdir = configured_hookdir_opt(); o->jobs = 1; + o->dir = NULL; } void run_hooks_opt_init_async(struct run_hooks_opt *o) @@ -306,6 +307,7 @@ static int pick_next_hook(struct child_process *cp, cp->env = hook_cb->options->env.v; cp->stdout_to_stderr = 1; cp->trace2_hook_name = hook->command.buf; + cp->dir = hook_cb->options->dir; /* * Commands from the config could be oneliners, but we know diff --git a/hook.h b/hook.h index 2593f932c0..fcd8e99e39 100644 --- a/hook.h +++ b/hook.h @@ -61,6 +61,9 @@ struct run_hooks_opt /* Number of threads to parallelize across */ int jobs; + + /* Path to initial working directory for subprocess */ + const char *dir; }; /* -- 2.31.0.rc2.261.g7f71774620-goog