diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-03-16 17:53:09 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-03-16 17:53:09 -0700 |
commit | 7431379a9c5ed4006603114b1991c6c6e98d5dca (patch) | |
tree | fcc981d9556302ae47199fa9cc7c932ccd157bdc /builtin/receive-pack.c | |
parent | Merge branch 'ab/keep-git-exit-codes-in-tests' (diff) | |
parent | hooks: fix an obscure TOCTOU "did we just run a hook?" race (diff) | |
download | tgif-7431379a9c5ed4006603114b1991c6c6e98d5dca.tar.xz |
Merge branch 'ab/racy-hooks'
Code clean-up to allow callers of run_commit_hook() to learn if it
got "success" because the hook succeeded or because there wasn't
any hook.
* ab/racy-hooks:
hooks: fix an obscure TOCTOU "did we just run a hook?" race
merge: don't run post-hook logic on --no-verify
Diffstat (limited to 'builtin/receive-pack.c')
-rw-r--r-- | builtin/receive-pack.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 380259869d..6d6a8bbbae 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1408,10 +1408,12 @@ static const char *push_to_deploy(unsigned char *sha1, static const char *push_to_checkout_hook = "push-to-checkout"; static const char *push_to_checkout(unsigned char *hash, + int *invoked_hook, struct strvec *env, const char *work_tree) { struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + opt.invoked_hook = invoked_hook; strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_pushv(&opt.env, env->v); @@ -1426,6 +1428,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w { const char *retval, *git_dir; struct strvec env = STRVEC_INIT; + int invoked_hook; if (!worktree || !worktree->path) BUG("worktree->path must be non-NULL"); @@ -1436,10 +1439,9 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); - if (!hook_exists(push_to_checkout_hook)) + retval = push_to_checkout(sha1, &invoked_hook, &env, worktree->path); + if (!invoked_hook) retval = push_to_deploy(sha1, &env, worktree->path); - else - retval = push_to_checkout(sha1, &env, worktree->path); strvec_clear(&env); return retval; |