From: Junio C Hamano Date: Wed, 3 Jun 2026 23:13:51 +0000 (+0900) Subject: Merge branch 'ar/receive-pack-worktree-env' into jch X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=b52a1785017abf4c750dddc6f92c4e922a70c4d8;p=thirdparty%2Fgit.git Merge branch 'ar/receive-pack-worktree-env' into jch The GIT_WORK_TREE variable prepared to invoke the push-to-checkout hook was leaking into the environment even when there was no hook used and broke the default push-to-deploy (i.e., let "git checkout" update the working tree only when the working tree is clean). * ar/receive-pack-worktree-env: receive-pack: fix updateInstead with core.worktree --- b52a1785017abf4c750dddc6f92c4e922a70c4d8 diff --cc builtin/receive-pack.c index 71e1f3dcd4,9fbfa15a51..19eb6a1b61 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@@ -1456,12 -1424,11 +1456,12 @@@ static const char *push_to_checkout(uns struct strvec *env, const char *work_tree) { - struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT; + struct run_hooks_opt opt = RUN_HOOKS_OPT_INIT_FORCE_SERIAL; + opt.invoked_hook = invoked_hook; - strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_pushv(&opt.env, env->v); + strvec_pushf(&opt.env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); strvec_push(&opt.args, hash_to_hex(hash)); if (run_hooks_opt(the_repository, push_to_checkout_hook, &opt)) return "push-to-checkout hook declined"; diff --cc t/t5516-fetch-push.sh index 4d1672de1e,a85b1fbf8b..1b986349a8 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@@ -1821,8 -1791,18 +1821,19 @@@ test_expect_success 'updateInstead wit ) ' + test_expect_success 'denyCurrentBranch and core.worktree' ' + test_when_finished "rm -fr cloned cloned.git" && + git clone --separate-git-dir cloned.git . cloned && + git --git-dir cloned.git config receive.denyCurrentBranch updateInstead && + git --git-dir cloned.git config core.worktree "$PWD/cloned" && + test_commit raspberry && + git push cloned.git HEAD:main && + test_path_exists cloned/raspberry.t && + test_must_fail git push --delete cloned.git main + ' + test_expect_success 'denyCurrentBranch and worktrees' ' + test_when_finished "rm -fr cloned && git worktree remove --force new-wt" && git worktree add new-wt && git clone . cloned && test_commit -C cloned first &&