Repository navigation
fix: fail the hook when staging fixed files errors - #1484
Merged
mrexox merged 2 commits intoAug 28, 2026
Merged
Conversation
When stage_fixed is enabled and the git add that stages the fixed files fails, the error was only logged: the hook still reported success and exited 0, so the commit went through with the unfixed content. Join the AddFiles error into the result at both call sites so the run is marked as a failure.
AddFiles returns the bare git error, so a joined hook failure gave no clue which operation broke when the warning output isn't visible.
Contributor
Author
|
Anything I can do to help get this reviewed? |
Member
|
Hey @teddytennant! Sorry for a long delay. I'm going to merge the changes, thank you for preparing the PR! |
eleboucher
pushed a commit
to eleboucher/memini
that referenced
this pull request
Aug 31, 2026
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [lefthook](https://github.com/evilmartians/lefthook) | tools | patch | `2.1.11` β `2.1.12` | --- >β οΈ **Warning** > > Some dependencies could not be looked up. Check the [Dependency Dashboard](issues/3) for more information. --- ### Release Notes <details> <summary>evilmartians/lefthook (lefthook)</summary> ### [`v2.1.12`](https://github.com/evilmartians/lefthook/blob/HEAD/CHANGELOG.md#2112-2026-08-28) [Compare Source](evilmartians/lefthook@v2.1.11...v2.1.12) - fix: fail the hook when staging fixed files errors ([#​1484](evilmartians/lefthook#1484)) by [@​teddytennant](https://github.com/teddytennant) - fix: LEFTHOOK\_OUTPUT precedence ([#​1506](evilmartians/lefthook#1506)) by [@​Yuki9814](https://github.com/Yuki9814) - ci: fix npm publishing by bumping Node to 24 ([#​1508](evilmartians/lefthook#1508)) by [@​mariokresic](https://github.com/mariokresic) </details> --- ### Configuration π **Schedule**: (UTC) - Branch creation - Between 12:00 AM and 03:59 AM, only on Monday (`* 0-3 * * 1`) - Automerge - At any time (no schedule defined) π¦ **Automerge**: Disabled because a matching PR was automerged previously. β» **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. π **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC41Mi4wIiwidXBkYXRlZEluVmVyIjoiNDQuNTIuMCIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiZGVwZW5kZW5jaWVzIl19--> Reviewed-on: https://git.erwanleboucher.dev/eleboucher/memini/pulls/242
This was referenced Sep 1, 2026
Contributor
|
I was on 2.1.10, and I noticed the changes suddenly got disappeared from history altogether when the hook failed and had to use reflog for an emergency restore. Does this PR address that issue potentially? @teddytennant |
Contributor
Author
|
No. This is not in 2.1.10, and a failing hook does not move HEAD. The only reflog entry lefthook writes is the |
This was referenced Oct 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1471
Context
With
stage_fixed: true,guard.withHiddenUnstagedChangescallsgit.AddFilesto stage the files a job has fixed. When thatgit addfails, the error is only logged:resErris the wrapped result of the jobs, so the staging failure never reaches the caller.Lefthook.runseeserr == nil, prints a green summary and exits 0 β the commit is created with the pre-fix content while nothing in the exit status tells the wrapper or CI that the formatter gate did not actually do its job.Reproducer from the issue: run the hook without
GIT_INDEX_FILEduringgit commit -a, so the staginggit addcollides with theindex.lockgit holds:Changes
errors.JointheAddFileserror into the returned error at both call sites β thelen(partiallyStagedFiles) == 0early return and theCanRestoreUnstagedChanges()branch. The warning is kept as is, so the immediate output does not change; only the returned error does.Lefthook.runthen reportsfailed to run the hook: ...and exits non-zero.AddFilesreturnsnilfor an empty file list, so hooks that stage nothing are unaffected β the join only happens on a real error.Added
Test_guard_wrap_stageFixedtoguard_test.gocovering both call sites, plus the two non-failing paths (nothing to stage, and a successfulgit add) so the change cannot start failing hooks that used to pass.cmdtest.Outgrew anErrfield so the ordered command double can simulate a failing git call; it is a new field with a nil zero value, existing expectations behave exactly as before.Verification
Before the fix (test only,
guard.goreverted):After:
make testandmake lint(golangci-lint 2.11.4, 0 issues) pass.make test-integrationpasses 57/57;tests/integration/run_interrupt.txtis flaky on my machine but fails the same way on an unmodifiedmaster, so it is unrelated.Not changed
stage_fixedalready fails the hook for every other error in this path. Happy to put it behind a flag instead if you prefer to keep the old behaviour available.elsebranch (CanRestoreUnstagedChanges()false) is untouched: it already overwriteswrappedErrwitherrRestorationConflict, so those runs fail regardless.git addfail deterministically inside testscript needs an index lock dance that would be more fragile than what it verifies.Confidence Score: 5/5
The PR appears safe to merge.
No blocking failure remains.
Reviews (2): Last reviewed commit: "fix: add context to the staging error" | Re-trigger Greptile