Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bash scripts fails on Windows but work on WSL #551

Open
mrvonwyl opened this issue Sep 19, 2023 · 4 comments
Open

Bash scripts fails on Windows but work on WSL #551

mrvonwyl opened this issue Sep 19, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@mrvonwyl
Copy link

🔧 Summary

It looks like that bash scripts cannot be run with lefthook in a Windows environment.
The same config and script work fin in WSL and also with a js script and node.
But on Windows, there is a bash error: No such file or directory.
This is possibly due to a character escape issue.

I actually do not know if this should even be possible, but due to the nature of the error I think it should be, since node runs, but has a wrong path to the script.

Lefthook version

1.4.11

Steps to reproduce

  1. Checkout https://github.com/mrvonwyl/lefthook-playground
  2. Run npm i (which should also install the git hooks)
  3. Run npx lefthook -v run prepare-commit-msg

Expected results

The console should print "hello from bash".

Actual results

The console prints an error instead:
RUNNING HOOK: prepare-commit-msg
⠙ waiting: bash.sh/bin/bash: F:Devplaygroundlefthook.lefthookprepare-commit-msgbash.sh: No such file or directory
-> note the missing folder delimiters (/ or )

Possible Solution

Logs / Screenshots

PS F:\Dev\playground\lefthook> npx lefthook -v run prepare-commit-msg
[lefthook] cmd: [git rev-parse --show-toplevel]
[lefthook] err: <nil>
[lefthook] out: F:/Dev/playground/lefthook

[lefthook] cmd: [git rev-parse --git-path hooks]
[lefthook] err: <nil>
[lefthook] out: .git/hooks

[lefthook] cmd: [git rev-parse --git-path info]
[lefthook] err: <nil>
[lefthook] out: .git/info

[lefthook] cmd: [git rev-parse --git-dir]
[lefthook] err: <nil>
[lefthook] out: .git

Lefthook v1.4.11
RUNNING HOOK: prepare-commit-msg
/bin/bash: F:Devplaygroundlefthook.lefthookprepare-commit-msgbash.sh: No such file or directory

  EXECUTE > bash.sh

            127
  EXECUTE > node.js
hello from node?


SUMMARY: (done in 0.20 seconds)
✔️  node.js
🥊  bash.sh
@mrvonwyl mrvonwyl added the bug Something isn't working label Sep 19, 2023
@mrexox
Copy link
Member

mrexox commented Sep 20, 2023

Thank you for this catch! I will take a look at this issue this week.

@mrexox
Copy link
Member

mrexox commented Sep 20, 2023

BTW, could you remove the runner option from the config for bash.sh? It must call the script directly. Does the error persist then?

@mrvonwyl
Copy link
Author

mrvonwyl commented Sep 21, 2023

I changed the config like so (is this what you meant be removing the runner?):

prepare-commit-msg:
  scripts:
    "bash.sh":
    "node.js":
      runner: node

This results in the following error:

EXECUTE > bash.sh

            \Dev\playground\lefthook\.lefthook\prepare-commit-msg\bash.sh: %1 is not a valid Win32 application.

This is probably caused due to windows not containing bash!?

Note: I ran this on a different PC. I will check again later.
Update: I changed the path in the error to match the original issue report.

@avudnez
Copy link

avudnez commented Nov 15, 2023

I second this, having the same error where bash seems to be called with a windows-style path containing no slash (neither forward nor backward), when called from powershell.
This is unfortunately a blocker for lefthook adoption.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants