Fix infinite editor-hook recursion in git worktrees#33
Open
andrewhamon wants to merge 1 commit into
Open
Conversation
The editor integration escapes the repo (via `pushd /` in the shell wrapper, and `cwd='/'` in _get_global_git_editor) so that `git var GIT_EDITOR` resolves the global editor instead of the repo-local one, which pre-commit has pointed back at its own wrapper. In a git worktree, git sets GIT_DIR explicitly in the hook environment, so changing the working directory does not detach from the repo config. `git var GIT_EDITOR` keeps returning the wrapper, which re-invokes itself forever and hangs `git commit`. Strip the inherited GIT_* environment for the resolution in both places: `env -u GIT_DIR` in the shell wrapper, and the existing git.no_git_env() helper on the Python side. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Cap-Session-Id: 019f3ed5-00bf-792e-a4ae-fbe9e181c556 Cap-Coder-Workspace-Id: 6c634473-f454-4795-beeb-0e28b1b9ef56 Cap-Coder-Workspace-Name: cap-8c443581ea7d7050 Co-Authored-By: Andy Hamon <andrewhamon@users.noreply.github.com> Co-Authored-By: Clement Brisset <Atlante45@users.noreply.github.com>
denbeigh2000
approved these changes
Jul 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The editor integration escapes the repo (via
pushd /in the shell wrapper, andcwd='/'in _get_global_git_editor) so thatgit var GIT_EDITORresolves the global editor instead of the repo-local one, which pre-commit has pointed back at its own wrapper.In a git worktree, git sets GIT_DIR explicitly in the hook environment, so changing the working directory does not detach from the repo config.
git var GIT_EDITORkeeps returning the wrapper, which re-invokes itself forever and hangsgit commit.Strip the inherited GIT_* environment for the resolution in both places:
env -u GIT_DIRin the shell wrapper, and the existing git.no_git_env() helper on the Python side.