You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Note that I've already ran into some trouble with getting Prettier to actually run on staged_files, hence the need to double-quote them. This was inferred from the issue on Windows escaping issues - #314.
Run git status and you will see that [slug].js has been modified, but the commit doesn't contain Prettier's fixes.
Optional steps:
Repeat formatting changes with index.js.
Commit again and fixes to index.js will be part of the commit.
Expected results
Files with patterns like [slug].js should be committed when they are fixed by a hook using tools like Prettier.
Actual results
The fixes are not committed, but the commit itself still succeeds.
Possible Solution
It seems like filenames are being passed to git add using single-quotes (see detailed log below), however, this doesn't work in Windows.
I think a simple fix for this would be to just use always use double-quotes to escape filenames, or at least use them when Windows is detected as the OS?
Perhaps some of the changes from #314 may also be useful for fixing this?
Logs / Screenshots
Running with LEFTHOOK_VERBOSE=true, I get the following log when changing [slug].js:
RUNNING HOOK: pre-commit
[lefthook] cmd: [git status --short]
[lefthook] err: <nil>
[lefthook] out: M [slug].js
[lefthook] cmd: [git diff --name-only --cached --diff-filter=ACMR]
[lefthook] err: <nil>
[lefthook] out: [slug].js
[lefthook] files before filters:
[[slug].js]
[lefthook] files after filters:
[[slug].js]
[lefthook] files after escaping:
['[slug].js']
[lefthook] executing: npx prettier --write "[slug].js"
EXECUTE > prettier
[slug].js 48ms
[lefthook] cmd: [git add '[slug].js']
[lefthook] err: exit status 128
[lefthook] out: fatal: pathspec ''[slug].js'' did not match any files
Couldn't stage fixed files:exit status 128
[lefthook] cmd: [git stash list]
[lefthook] err: <nil>
[lefthook] out: stash@{0}: WIP on main: 5f16ae5 Initial commit
SUMMARY: (done in 1.63 seconds)
鉁旓笍 prettier
The text was updated successfully, but these errors were encountered:
Hey! Thank you for reporting. I could reproduce this bug on my Linux machine, so I'll try to fix it. Unfortunately, I don't have an access to Windows machine right now, so the fix might not work for you. If so, please come back to this issue and add a comment about it.
馃敡 Summary
When using the
stage_fixed
option in Windows, Lefthook will fail to commit files with that have been fixed.This only occurs when trying to commit with file patterns that need escaping like
[slug].js
(a common Next.js filename convention).Here is my config:
Note that I've already ran into some trouble with getting Prettier to actually run on
staged_files
, hence the need to double-quote them. This was inferred from the issue on Windows escaping issues - #314.Lefthook version
1.4.2
Steps to reproduce
npm ci
[slug].js
in some way.git status
and you will see that[slug].js
has been modified, but the commit doesn't contain Prettier's fixes.Optional steps:
index.js
.index.js
will be part of the commit.Expected results
Files with patterns like
[slug].js
should be committed when they are fixed by a hook using tools like Prettier.Actual results
The fixes are not committed, but the commit itself still succeeds.
Possible Solution
It seems like filenames are being passed to
git add
using single-quotes (see detailed log below), however, this doesn't work in Windows.I think a simple fix for this would be to just use always use double-quotes to escape filenames, or at least use them when Windows is detected as the OS?
Perhaps some of the changes from #314 may also be useful for fixing this?
Logs / Screenshots
Running with
LEFTHOOK_VERBOSE=true
, I get the following log when changing[slug].js
:The text was updated successfully, but these errors were encountered: