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

pre-commit hook does not work in Visual Studio #467

Closed
3 tasks
agateau-gg opened this issue Feb 1, 2023 · 2 comments · Fixed by #476
Closed
3 tasks

pre-commit hook does not work in Visual Studio #467

agateau-gg opened this issue Feb 1, 2023 · 2 comments · Fixed by #476
Labels
status:new This issue needs to be reviewed type:bug Something isn't working

Comments

@agateau-gg
Copy link
Collaborator

agateau-gg commented Feb 1, 2023

Environment

  • ggshield version: 1.14.2
  • Operating system (Linux, macOS, Windows): Windows
  • Operating system version: 11
  • Python version: any

Describe the bug

Visual Studio (Not VS Code!) fails to execute our pre-commit hook because it cannot execute our shebang (#!/usr/bin/env bash).

Steps to reproduce:

  1. Install a global pre-commit hook with ggshield install -t pre-commit -m global
  2. Start Visual Studio
  3. Try to commit from within Visual Studio

Actual result:

Visual Studio error message

Expected result:

Pre-commit hook should run and commit should be scanned.

One can workaround that by replacing the shebang with #!/bin/sh. However it's not a correct fix because the hook uses bash-specific syntax so it would fail on OS where /bin/sh is not bash, such as Ubuntu.

TODO

  • Replace all our hook shebangs with #!/bin/sh. Note that using #!/usr/bin/env sh does not fix the problem
  • Fix the bashims
  • If possible, setup a check like checkbashisms or shellcheck in the CI

Related issue on pre-commit: pre-commit/pre-commit#2182

@agateau-gg agateau-gg added type:bug Something isn't working status:new This issue needs to be reviewed labels Feb 1, 2023
@pierrelalanne
Copy link
Collaborator

I am not sure to understand why this issue is limited to Visual Studio users ?
From my understanding, any user with the global pre-commit hook installed but without bash available will fail to execute the hook ?

@agateau-gg
Copy link
Collaborator Author

I think that's because VS ships with its own version of Git, which wrongly assumes that a script to be executed with bash must be Linux only, so it must go through WSL.

agateau-gg added a commit that referenced this issue Feb 8, 2023
Visual Studio thinks a script starting with "#!/usr/bin/env bash" (or
"#!/usr/bin/bash" or "#!/bin/bash") must be run using WSL. Work-around
this by using Posix shell only and a "#!/bin/sh" shebang.

Fixes #467
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:new This issue needs to be reviewed type:bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants