You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
overcommit --run reports success when Git cannot read the index #909
Reproduced separately on main 50f3e866bef75e3c3be7f92b47b1c45b6e7436ba (0.74.0), macOS 15.6.1, Ruby 4.0.7, Apple Git 2.50.1.
GitRepo.all_files does not check the exit status of either git ls-files command. If Git cannot read the index, both commands fail, but their empty stdout is treated as a valid empty file list. In a scratch repository with a configured TrailingWhitespace hook, the CLI prints Git's fatal errors followed by All pre-commit hooks passed, and exits 0.
Reproduction
In a new disposable repository, configure only TrailingWhitespace with include: ['**/*.rb'] and on_warn: fail, and approve the fixture configuration with overcommit --sign.
Create and stage normal.rb containing a trailing-space violation. Confirm overcommit --run exits 65.
Replace only that disposable repository's.git/index with invalid synthetic bytes. No user repository or live index is needed.
Run overcommit --run again.
Observed stderr:
fatal: .git/index: index file smaller than expected
fatal: .git/index: index file smaller than expected
Observed stdout ends with:
All pre-commit hooks passed
Exit status is 0. A valid empty index also exits 0, so callers cannot distinguish the two states using the process status.
Expected behavior and scope question
When Git cannot enumerate the files to check, --run should report an enumeration error and return a nonzero status rather than success. GitRepo.list_files already checks command success and raises an Overcommit error; all_files currently uses unchecked backticks.
I checked #524: it concerned restoring the working tree/stash after normal pre-commit execution and did not provide a reproducible cause of index corruption. This report neither attributes index corruption to Overcommit nor asks it to repair a broken index. It is specifically about the standalone --run exit status once enumeration fails.
Would a separate change checking both enumeration command results be in scope? The controls would cover a valid empty index, normal violation, deleted tracked files, and Git enumeration failure. I would not combine it with filename parsing, stash handling, or index recovery.
Activity
Fail when Git cannot enumerate tracked files (sds#923)