Skip to content

bugfix: Also skip the gitcache script run by a Python interpreter - #167

Open
Bilb wants to merge 1 commit into
seeraven:masterfrom
Bilb:fix/find-git-skip-pip-entry-point
Open

Bilb wants to merge 1 commit into
seeraven:masterfrom
Bilb:fix/find-git-skip-pip-entry-point

Conversation

@Bilb

@Bilb Bilb commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

find_git() skips a PATH candidate only when it is the same file as sys.executable. That holds for the frozen builds, where sys.executable is the gitcache binary. In a pip installation, sys.executable is the Python interpreter, and the gitcache entry point is a script run by it, so a git symlink to that script is not skipped.

As long as ~/.gitcache/config sets RealGit, the default is never used and nothing happens. But when no config is found, e.g. with HOME pointing to a fresh/tmp directory, the default wins: find_git() returns the wrapper itself, and every git call starts another git that waits on its child. On my machine this grew to about 2,000 processes and 86 GB of memory before the OOM killer took down the desktop.

Reproduce with a pip/venv install and ~/.local/bin/git -> gitcache:

HOME=$(mktemp -d) python -c 'from git_cache.config import find_git; print(find_git())'
# prints ~/.local/bin/git instead of /usr/bin/git

The fix also compares each candidate with sys.argv[0], the script being run, ignoring it when it is empty or does not exist.

Tests: test_skip_git_symlink_to_script covers a git symlink to a script run by a separate interpreter and fails without the fix. test_skip_without_argv0 covers an empty sys.argv[0].

find_git() skipped candidates matching sys.executable, which is the
gitcache binary only in a frozen build. In a pip installation it is the
Python interpreter, so a git symlink to the gitcache entry point script
was returned as the real git command whenever RealGit was not configured
(e.g. HOME pointing to a fresh directory). Every git call then spawned
itself until the system ran out of memory.

Also compare candidates with sys.argv[0], the script being run.
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.

1 participant