Skip to content

Support hook side effects without stashing repository changes - #939

Merged
sds merged 3 commits into
mainfrom
implement-hook-side-effects
Nov 11, 2026
Merged

sds merged 3 commits into
mainfrom
implement-hook-side-effects

Conversation

@sds

@sds sds commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Pre-commit and commit-msg hooks can now modify, create, remove, and stage files without losing their changes during cleanup. Unstaged edits are saved to a durable binary patch and hidden with a reverse application; cleanup reapplies that patch without changing HEAD, the index, the stash, or merge/cherry-pick metadata. Hooks retain native Git behavior: only edits they explicitly stage enter the commit, and their edits survive failed or interrupted runs.

If restoration conflicts with hook edits, the commit fails while preserving both the hook changes and a patch with recovery instructions. Patches survive garbage collection and forced termination, and successful cleanup removes them. File modification times are restored for unchanged files while hook edits remain visible to watchers.

The existing behavior tests remain, including deletion/rename and configuration-error recovery regressions. Tests tied to stash commands and legacy stash emulation were replaced with patch failure and recovery tests. New regression coverage includes actual commits, first commits, hook failures/exceptions/interruptions, index changes, alternate indexes, worktrees, binary files, unusual paths, symlinks/type changes, CRLF conversion, executable modes, conflicting edits, and shell-safe recovery commands. Interrupt messages now describe patch recovery instead of pointing to the stash. AGENTS.md and contributor guidance require 100% line coverage; CI now enforces it after combining all shard/platform reports.

Validation:

  • Complete local suite: 2,169 examples, 0 failures.
  • Local exact coverage gate: 3,844/3,844 executable lines (100%).
  • bundle exec overcommit --run: passed, including RuboCop.
  • All 21 GitHub checks passed, including Ruby 3.3/3.4/4.0 on Linux and Windows, the final CI gate, and Coveralls. Combined CI coverage: 3,846/3,846 executable lines (100%).

This removes the stash/reset mechanisms behind reports such as #65, #80, #135, #168, #372, #524, and #669. lint-staged's current backup/revert workflow still uses stashes and hard resets, so it was not copied.

Closes #238.

@sds
sds merged commit a5bdc87 into main Nov 11, 2026
21 checks passed
@sds
sds deleted the implement-hook-side-effects branch November 11, 2026 05:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for pre-commit hooks that have file changing side-effects

1 participant