Every time getting `Couldn't restore hidden unstaged files: exit status 1` error
:wrench: Summary
I'm faced with error: Couldn't restore hidden unstaged files: exit status 1 on every commit.
Lefthook version
1.6.1 e69adc10c99fd8887673a8b18894082453c6ceaf
Steps to reproduce
- Stage files on Git.
- Do git commit
Expected results
Shouldn't see any errors.
Actual results
Error Couldn't restore hidden unstaged files: exit status 1, but Git commit continues.
Possible Solution
Nothing.
Logs / Screenshots
❯ LEFTHOOK_VERBOSE=true git commit -m "test"
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info
│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git
╭──────────────────────────────────────╮
│ 🥊 lefthook v1.6.1 hook: pre-commit │
╰──────────────────────────────────────╯
│ [lefthook] cmd: [git status --short]
│ [lefthook] dir: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] err: <nil>
│ [lefthook] out: M README.md
M package.json
M src/experiments.njk
│ [lefthook] cmd: [git diff --name-only --cached --diff-filter=ACMR]
│ [lefthook] dir: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] err: <nil>
│ [lefthook] out: package.json
src/experiments.njk
│ [lefthook] files before filters:
[package.json src/experiments.njk]
│ [lefthook] files after filters:
[]
│ eslint (skip) no files for inspection
│ [lefthook] cmd: [git diff --name-only --cached --diff-filter=ACMR]
│ [lefthook] dir: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] err: <nil>
│ [lefthook] out: package.json
src/experiments.njk
│ [lefthook] files before filters:
[package.json src/experiments.njk]
│ [lefthook] files after filters:
[package.json src/experiments.njk]
│ [lefthook] files after escaping:
[package.json src/experiments.njk]
│ [lefthook] executing: pnpm prettier --write package.json src/experiments.njk
┃ prettier ❯
package.json 19ms (unchanged)
src/experiments.njk 27ms (unchanged)
│ [lefthook] cmd: [git diff --name-only --cached --diff-filter=ACMR]
│ [lefthook] dir: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] err: <nil>
│ [lefthook] out: package.json
src/experiments.njk
│ [lefthook] files before filters:
[package.json src/experiments.njk]
│ [lefthook] files after filters:
[]
│ stylelint (skip) no files for inspection
│ [lefthook] cmd: [git apply -v --whitespace=nowarn --recount --unidiff-zero .git/info/lefthook-unstaged.patch]
│ [lefthook] dir: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] err: exit status 1
│ [lefthook] out: Checking patch eleventy/filters.js...
error: while searching for:
const urlObj = new URL(d["url"]);
error: patch failed: eleventy/filters.js:59
error: eleventy/filters.js: patch does not apply
Couldn't restore hidden unstaged files: exit status 1
────────────────────────────────────
summary: (done in 0.42 seconds)
✔️ prettier
│ [lefthook] cmd: [git rev-parse --show-toplevel]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: /Users/saneef/workspace/saneef/saneef.com
│ [lefthook] cmd: [git rev-parse --git-path hooks]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/hooks
│ [lefthook] cmd: [git rev-parse --git-path info]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git/info
│ [lefthook] cmd: [git rev-parse --git-dir]
│ [lefthook] dir:
│ [lefthook] err: <nil>
│ [lefthook] out: .git
╭──────────────────────────────────────────────╮
│ 🥊 lefthook v1.6.1 hook: prepare-commit-msg │
╰──────────────────────────────────────────────╯
│ [lefthook] skip: Hook prepare-commit-msg doesn't exist in the config
[main 34aab66] test
2 files changed, 1 insertion(+), 1 deletion(-)
Is this due to some previously botched git commit? If that is the case, how would I clear those files?
I deleted the file .git/info/lefthook-unstaged.patch and it worked fine.
Thank you for creating this bug. This is indeed a real problem with lefthook, I will try to fix it with the next release.
I've been seeing this as well. The way we say it exposed was that pre-commit was failing for files that weren't actually staged.
Confirmed that deleting it fixes it. Would it be worth deleting this file everytime a pre-commit hook runs?