summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2018-02-28 13:37:53 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2018-02-28 13:37:53 -0800
commit619e5218cbb9c9751d92cc5e090731bc55793cb0 (patch)
tree49697257ac603ded6e39c9b6411979599b92dee4 /builtin
parentMerge branch 'nd/am-quit' (diff)
parentworktree: add: fix 'post-checkout' not knowing new worktree location (diff)
downloadtgif-619e5218cbb9c9751d92cc5e090731bc55793cb0.tar.xz
Merge branch 'es/worktree-add-post-checkout-hook'
"git worktree add" learned to run the post-checkout hook, just like "git clone" runs it upon the initial checkout. * es/worktree-add-post-checkout-hook: worktree: add: fix 'post-checkout' not knowing new worktree location
Diffstat (limited to 'builtin')
-rw-r--r--builtin/worktree.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 9efdc22466..4e7c98758f 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -345,9 +345,23 @@ done:
* Hook failure does not warrant worktree deletion, so run hook after
* is_junk is cleared, but do return appropriate code when hook fails.
*/
- if (!ret && opts->checkout)
- ret = run_hook_le(NULL, "post-checkout", oid_to_hex(&null_oid),
- oid_to_hex(&commit->object.oid), "1", NULL);
+ if (!ret && opts->checkout) {
+ const char *hook = find_hook("post-checkout");
+ if (hook) {
+ const char *env[] = { "GIT_DIR", "GIT_WORK_TREE", NULL };
+ cp.git_cmd = 0;
+ cp.no_stdin = 1;
+ cp.stdout_to_stderr = 1;
+ cp.dir = path;
+ cp.env = env;
+ cp.argv = NULL;
+ argv_array_pushl(&cp.args, absolute_path(hook),
+ oid_to_hex(&null_oid),
+ oid_to_hex(&commit->object.oid),
+ "1", NULL);
+ ret = run_command(&cp);
+ }
+ }
argv_array_clear(&child_env);
strbuf_release(&sb);