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

Ouverte Adaptée aux débutants
#909 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
62/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
git, ruby
Domaine
cli, devtools

Piste de recherche

Commence dans GitRepo.all_files, qui exécute deux commandes git ls-files avec des backticks non vérifiés, et compare-la avec GitRepo.list_files, qui vérifie déjà le résultat de la commande et lève une erreur Overcommit. Vérifie les deux résultats d'énumération et échoue avec un statut non nul lorsque Git ne peut pas lire l'index. C'est terminé lorsqu'un index corrompu produit une sortie non nulle, tandis qu'un index valide vide, une violation normale et les fichiers suivis supprimés se comportent comme auparavant. La question du périmètre reste ouverte pour un mainteneur.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Ruby
Étoiles
4k
Forks
288
Merge moyen
2 j 4 h
PR mergées (30 j)
18

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de sds/overcommit

Toutes les issues de sds/overcommit

Issues similaires

Plus d'issues Ruby

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.