lefthook icon indicating copy to clipboard operation
lefthook copied to clipboard

Every time getting `Couldn't restore hidden unstaged files: exit status 1` error

Open saneef opened this issue 2 years ago • 3 comments

: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

  1. Stage files on Git.
  2. 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(-)

saneef avatar Feb 09 '24 08:02 saneef

Is this due to some previously botched git commit? If that is the case, how would I clear those files?

saneef avatar Feb 09 '24 12:02 saneef

I deleted the file .git/info/lefthook-unstaged.patch and it worked fine.

saneef avatar Feb 09 '24 20:02 saneef

Thank you for creating this bug. This is indeed a real problem with lefthook, I will try to fix it with the next release.

mrexox avatar Feb 12 '24 08:02 mrexox

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?

technicalpickles avatar Mar 14 '24 19:03 technicalpickles