diff options
| author | Emily Shaffer <emilyshaffer@google.com> | 2021-12-22 04:59:36 +0100 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2022-01-07 15:19:34 -0800 |
| commit | 1a3017d908824ab42ca7a5af7073f4cdc5c88fbf (patch) | |
| tree | 1b6711e0a4033c7688eca8e909b307f8ea7e0f43 /builtin/worktree.c | |
| parent | 72ddf34d7c62a0b272d5cdd8f62fcfc782bb3a45 (diff) | |
| download | git-1a3017d908824ab42ca7a5af7073f4cdc5c88fbf.tar.gz | |
hooks: convert worktree 'post-checkout' hook to hook library
Move the running of the 'post-checkout' hook away from run-command.h
to the new hook.h library in builtin/worktree.c. For this special case
we need a change to the hook API to teach it to run the hook from a
given directory.
We cannot skip the "absolute_path" flag and just check if "dir" is
specified as we'd then fail to find our hook in the new dir we'd
chdir() to. We currently don't have a use-case for running a hook not
in our "base" repository at a given absolute path, so let's have "dir"
imply absolute_path(find_hook(hook_name)).
Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Emily Shaffer <emilyshaffer@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/worktree.c')
| -rw-r--r-- | builtin/worktree.c | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c index a396cfdc64..6f03afad97 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -382,21 +382,17 @@ done: * is_junk is cleared, but do return appropriate code when hook fails. */ if (!ret && opts->checkout) { - const char *hook = find_hook("post-checkout"); - if (hook) { - const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL }; - struct child_process cp = CHILD_PROCESS_INIT; - cp.no_stdin = 1; - cp.stdout_to_stderr = 1; - cp.dir = path; - strvec_pushv(&cp.env_array, env); - cp.trace2_hook_name = "post-checkout"; - strvec_pushl(&cp.args, absolute_path(hook), - oid_to_hex(null_oid()), - oid_to_hex(&commit->object.oid), - "1", NULL); - ret = run_command(&cp); - } + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + + strvec_pushl(&opt.env, "GIT_DIR", "GIT_WORK_TREE", NULL); + strvec_pushl(&opt.args, + oid_to_hex(null_oid()), + oid_to_hex(&commit->object.oid), + "1", + NULL); + opt.dir = path; + + ret = run_hooks_opt("post-checkout", &opt); } strvec_clear(&child_env); |
