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

doesn't work in visual studio 2019 on Windows #2182

Closed
hushigome-visco opened this issue Jan 2, 2022 · 7 comments · Fixed by #2187
Closed

doesn't work in visual studio 2019 on Windows #2182

hushigome-visco opened this issue Jan 2, 2022 · 7 comments · Fixed by #2187

Comments

@hushigome-visco
Copy link

@hushigome-visco hushigome-visco commented Jan 2, 2022

describe your issue

When I try to commit from visual studio 2019, I get the following message:

/usr/bin/env: ‘bash’: No such file or directory

I have confirmed that it works from vscode and command prompt.
I rewrote the .git/hooks/pre-commit to below and it worked.

#!/usr/bin/env sh

As far as I can see, visual studio git hooks only support sh.
Are you aware of this problem?

thank you.

pre-commit --version

pre-commit 2.16.0

.pre-commit-config.yaml

repos:
  - repo: https://github.com/pre-commit/mirrors-clang-format
    rev: v13.0.0
    hooks:
      - id: clang-format

~/.cache/pre-commit/pre-commit.log (if present)

No response

@hushigome-visco hushigome-visco changed the title doesn't work in visual studio 2019 doesn't work in visual studio 2019 on Windows Jan 2, 2022
@asottile
Copy link
Member

@asottile asottile commented Jan 2, 2022

that's odd -- what version of git are you using? (it ships with bash because parts of git use bash)

@hushigome-visco
Copy link
Author

@hushigome-visco hushigome-visco commented Jan 4, 2022

git version is the latest git version 2.34.1.windows.1.


By the way, when shebang was changed to #!/bin/bash, the following message was output.

Your git-hook, '.git/hooks/pre-commit', is not supported, likely because the first line is not \"#!/bin/sh\".\r\nSee your administrator for additional assistance. 

From above messages, I guessed that Visual Studio 2019 only supports sh.

@asottile
Copy link
Member

@asottile asottile commented Jan 4, 2022

interesting, does #!/bin/bash work?

@hushigome-visco
Copy link
Author

@hushigome-visco hushigome-visco commented Jan 5, 2022

No. As far as I can see, only #!/usr/bin/env sh and #!/bin/sh work.

@asottile
Copy link
Member

@asottile asottile commented Jan 5, 2022

can you try the patch from #2187 ?

@hushigome-visco
Copy link
Author

@hushigome-visco hushigome-visco commented Jan 6, 2022

It worked fine in visual studio 2019.
But is it as expected that there are two shebang lines?

#!/bin/sh
#!/usr/bin/env bash
# File generated by pre-commit: https://pre-commit.com
# ID: 138fd403232d2ddd5efb44317e38bf03

...

@asottile
Copy link
Member

@asottile asottile commented Jan 6, 2022

yep -- the first one is the only one which matters -- I essentially override the second one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants