Skip to content

Fix infinite editor-hook recursion in git worktrees#33

Open
andrewhamon wants to merge 1 commit into
mainfrom
cap/worktree-editor-git-dir
Open

Fix infinite editor-hook recursion in git worktrees#33
andrewhamon wants to merge 1 commit into
mainfrom
cap/worktree-editor-git-dir

Conversation

@andrewhamon

Copy link
Copy Markdown

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.

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>
@andrewhamon andrewhamon requested a review from denbeigh2000 July 9, 2026 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants