Skip to content

overcommit --run reports success when Git cannot read the index #909

Closed

Description

@Osraka

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

  1. In a new disposable repository, configure only TrailingWhitespace with include: ['**/*.rb'] and on_warn: fail, and approve the fixture configuration with overcommit --sign.
  2. Create and stage normal.rb containing a trailing-space violation. Confirm overcommit --run exits 65.
  3. Replace only that disposable repository's .git/index with invalid synthetic bytes. No user repository or live index is needed.
  4. 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

  1. added a commit that references this issue on Nov 10, 2026
    3bf9d27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions