Skip to content

fix: disable lint-staged stash to prevent GPG-signed commit corruption - #2090

Open
gaspergrom wants to merge 1 commit into
mainfrom
fix/husky-lint-staged-gpg-commit-corruption
Open

fix: disable lint-staged stash to prevent GPG-signed commit corruption#2090
gaspergrom wants to merge 1 commit into
mainfrom
fix/husky-lint-staged-gpg-commit-corruption

Conversation

@gaspergrom

Copy link
Copy Markdown
Collaborator

Summary

  • The pre-commit hook's npx lint-staged step was silently turning GPG-signed commits (git commit -S) into pure deletions of every touched file — disk content stayed correct, but the recorded commit tree only contained deletions. Reproduced twice, deterministic under a real git commit -S, not reproducible running the hook script standalone.
  • Root cause: lint-staged's stash-based backup/restore mechanism was racing with git's own index handling during the commit transaction. The hook already force-stages every touched file via git add -u right before this step runs, so there's nothing partially-staged left for the stash to protect.
  • Fix: pass --no-stash to npx lint-staged, removing the race entirely.

Test plan

  • Reproduced the corruption on main with a real git commit -S touching frontend/, confirmed via git show --stat (pure deletions)
  • Applied --no-stash, repeated the same commit — confirmed correct tree via git show --stat (real insertions/deletions, no data loss)
  • Confirmed GPG signature still verifies (git log --format='%G? %h %s'G)

…ng into deletions

The pre-commit hook's final → No staged files match any configured task. step was silently turning
GPG-signed commits (git commit -S) into pure deletions of every touched
file — disk content stayed correct, but the recorded commit tree only
contained deletions. Reproduced twice, deterministic under a real
git commit -S but not when running the hook script standalone.

lint-staged's stash-based backup/restore mechanism (visible in its own
console output: backing up state, applying modifications, cleaning up)
was racing with git's index handling during the commit transaction.
The hook already force-stages every touched file via git add -u right
before this step runs, so there's no partially-staged state left for
the stash to protect — disabling it (--no-stash) removes the race
entirely without changing what gets committed.

Signed-off-by: Gašper Grom <gasper.grom@gmail.com>
Copilot AI balanced review requested due to automatic review settings August 15, 2026 04:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Disables lint-staged’s stash mechanism to prevent corruption of GPG-signed commits.

Changes:

  • Adds --no-stash to the lint-staged invocation.
  • Documents why stashing is unnecessary and unsafe in this hook.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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