From 2812d5accf5428596e25f9e95376321416ee3e4c Mon Sep 17 00:00:00 2001 From: Viktor Ashirov Date: Feb 26 2026 10:49:25 +0000 Subject: pre_push_check: unset GIT_DIR to fix worktree support When running inside a git hook from a worktree, git sets GIT_DIR to the worktree's git directory. If inherited by subprocess calls, it causes git commands to operate on the worktree instead of the temporary clone, detaching its HEAD. Remove GIT_DIR from the environment before running git commands in the temporary clone and restore it afterward. Fixes: #769 Signed-off-by: Viktor Ashirov --- diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py index 359c09b..2e49132 100644 --- a/pyrpkg/__init__.py +++ b/pyrpkg/__init__.py @@ -4582,6 +4582,7 @@ class Commands(object): try: clone_dir = tempfile.mkdtemp(prefix="pre_push_hook_") + saved_git_dir = os.environ.pop('GIT_DIR', None) for cmd in [ ('git', 'clone', self.path, clone_dir), ('git', 'checkout', ref), @@ -4628,6 +4629,8 @@ class Commands(object): self.log.warning(show_hint) sys.exit(3) finally: + if saved_git_dir is not None: + os.environ['GIT_DIR'] = saved_git_dir self._cleanup_tmp_dir(clone_dir) source_files = []