]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'ar/receive-pack-worktree-env' into jch
authorJunio C Hamano <gitster@pobox.com>
Fri, 29 May 2026 04:01:23 +0000 (13:01 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 May 2026 04:01:23 +0000 (13:01 +0900)
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

1  2 
builtin/receive-pack.c
t/t5516-fetch-push.sh

index 71e1f3dcd4a204bbd87f34b69776935f2e149dba,9fbfa15a516077f30035e8fd86490c2f13f09368..19eb6a1b61c3a73f9d87d54ff075b1fb12a0b5e3
@@@ -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";
index 4d1672de1e264bef660766333c72882786deae99,a85b1fbf8b5d479e276e3c9ba67b8f9803220e01..1b986349a86f3efd94a2a5d63233b81a67b98d4a
@@@ -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 &&