Skip to content

Wrap commands in Git bash on Windows #953

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

Closed
ianzone opened this issue Feb 17, 2025 · 11 comments · Fixed by #979 · May be fixed by #965
Closed

Wrap commands in Git bash on Windows #953

ianzone opened this issue Feb 17, 2025 · 11 comments · Fixed by #979 · May be fixed by #965
Labels
feature request A new lefthook feature description

Comments

@ianzone
Copy link

ianzone commented Feb 17, 2025

⚡ Summary

According to docs, run commands behave differently on Linux and Windows. This is not ideal.

We can wrap commands in git bash, which is located in C:\Program Files\Git\bin\sh.exe.

Value

Provide command consistency.

Behavior and configuration changes

commands should behave the same on Linux and Windows.

@ianzone ianzone added the feature request A new lefthook feature description label Feb 17, 2025
@ianzone
Copy link
Author

ianzone commented Feb 17, 2025

lefthook should pass Windows env to git bash though

@mrexox
Copy link
Member

mrexox commented Feb 18, 2025

Hey! I like your suggestion. I will try to play with it on Windows, but I think lefthook should first check if there's sh available because AFAIK you can install git without installing sh on Windows.

@ianzone
Copy link
Author

ianzone commented Feb 18, 2025

Hey! I like your suggestion. I will try to play with it on Windows, but I think lefthook should first check if there's sh available because AFAIK you can install git without installing sh on Windows.

and print error msg if it's not installed

@mrexox
Copy link
Member

mrexox commented Mar 25, 2025

Not printing an error yet, but implemented wrapping with sh -c. I'll be glad to get some feedback if you have time to test this feature :)

@ianzone
Copy link
Author

ianzone commented Mar 25, 2025

Have you passed params when running git hooks?

post-checkout:
  commands:
    check-pnpm-lock:
      run: |
        if [ "$3" -eq 1 ]; then
          if git diff --quiet "$1" "$2" -- pnpm-lock.yaml; then
            echo pnpm-lock.yaml changed! Run pnpm install ...
            pnpm install
          fi
        fi

it throws /usr/bin/bash: line 1: [: -eq: unary operator expected

@ianzone
Copy link
Author

ianzone commented Mar 25, 2025

BTW, are you using single or double quotes to wrap commands?

@mrexox
Copy link
Member

mrexox commented Mar 25, 2025

BTW, are you using single or double quotes to wrap commands?

Using double quotes, so the actual command becomes sh -c "<your command>"

@mrexox
Copy link
Member

mrexox commented Mar 25, 2025

Have you passed params when running git hooks?

Could you run this with LEFTHOOK_VERBOSE env variable set to true? It shall print the final command it runs. The hook arguments must be substituted, but they are in a format of {1}, {2}, see https://lefthook.dev/configuration/run.html

@ianzone
Copy link
Author

ianzone commented Mar 26, 2025

{1}, {2} works, thank you!

@ianzone
Copy link
Author

ianzone commented Mar 26, 2025

Another issue is that the stdout does not seem piped. The echo message won't show until pnpm install is finished.

@ianzone
Copy link
Author

ianzone commented Mar 26, 2025

Another issue is that the stdout does not seem piped. The echo message won't show until pnpm install is finished.

just found
follow: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A new lefthook feature description
Projects
None yet
2 participants