summaryrefslogtreecommitdiff
path: root/builtin/worktree.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-02-28 21:37:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-02-28 21:37:53 (GMT)
commit619e5218cbb9c9751d92cc5e090731bc55793cb0 (patch)
tree49697257ac603ded6e39c9b6411979599b92dee4 /builtin/worktree.c
parentc22c624a9de3576d6e66f81c3a1edc6dfcfb08bb (diff)
parenta4bf1e3c2e4d0583a1822419fb54a566e6e46162 (diff)
downloadgit-619e5218cbb9c9751d92cc5e090731bc55793cb0.zip
git-619e5218cbb9c9751d92cc5e090731bc55793cb0.tar.gz
git-619e5218cbb9c9751d92cc5e090731bc55793cb0.tar.bz2
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/worktree.c')
-rw-r--r--builtin/worktree.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 9efdc22..4e7c987 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);