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

Executable file not found #237

Open
bbodenmiller opened this issue Sep 30, 2021 · 7 comments
Open

Executable file not found #237

bbodenmiller opened this issue Sep 30, 2021 · 7 comments
Labels
question Further information is requested Windows Windows case

Comments

@bbodenmiller
Copy link
Contributor

Trying to run this simple command on Windows but getting the error exec: "if": executable file not found in %PATH%

pre-commit:
  commands:
    passwords:
      glob: "*.{config}"
      run: if grep -c 'password' {staged_files}; then exit 1; fi
@Envek
Copy link
Member

Envek commented Sep 30, 2021

Most probably command is run in Windows shell (cmd?) but your syntax is for Unix sh-compatible ones.

Try to wrap your command into shell like this:

run: bash -c "if grep -c 'password' {staged_files}; then exit 1; fi"

Haven't worked in Windows for years, so can't really suggest a specific solution.

Or try to move commands to scripts.

@Envek Envek added question Further information is requested Windows Windows case labels Sep 30, 2021
@bbodenmiller
Copy link
Contributor Author

bbodenmiller commented Sep 30, 2021

Most probably command is run in Windows shell (cmd?) but your syntax is for Unix sh-compatible ones.

I thought the same but run command of unix2dos {staged_files} works fine in config (and does not work in cmd).

@bbodenmiller
Copy link
Contributor Author

bbodenmiller commented Oct 1, 2021

I'm getting this error more when I try to run with GitHub Desktop. I think it's a GitHub Desktop problem in those cases but interested in others opinion: desktop/desktop#13052

@Envek
Copy link
Member

Envek commented Oct 1, 2021

Oh, yes, GUI tools have problems with PATH. See #178 for example (especially #178 (comment))

@bbodenmiller
Copy link
Contributor Author

@Envek can you pass {staged_files} to scripts? I couldn't figure out how to based on docs and experimentation.

@bbodenmiller
Copy link
Contributor Author

FYI

run: bash -c "if grep -c 'password' {staged_files}; then exit 1; fi"

Does not work. It throws

⠹ waiting bash: -c: line 0: syntax error near unexpected token `then'
bash: -c: line 0: `\if grep -c 'password' myfile.config; then exit 1; fi"'

@mrexox
Copy link
Member

mrexox commented Jul 29, 2024

Lefthook on Windows is not supposed to use bash. BTW you can just use grep here, it will exit 1 when no match found. So, no need for if statement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Windows Windows case
Projects
None yet
Development

No branches or pull requests

3 participants