pre-commit hook doesn't work when using #!/bin/bash on windows
See original GitHub issueDescription
Basically if a pre-commit hook uses #!/bin/bash
rather than #!/bin/sh
then it works on the command line (in all of cmd
, git bash
and powershell
) but causes this error in the github app:
Commit failed - exit code 1 received, with output: 'error: cannot spawn
C:/Users/Public/github-desktop-issue/githooks/pre-commit: No such file or directory'
Version
- GitHub Desktop: 1.4.0
- Operating system: Microsoft Windows [Version 10.0.17134.285]
Steps to Reproduce
- Clone this repository: https://bitbucket.org/Jamesernator/github-desktop-issue
- Change the githooks directory using
git config core.gitHooks githooks
while in the repo directory - Change the example file somehow
- Try to commit in Github Desktop
- Error occurs because of #!/bin/bash
- EXTRA: Try committing in a regular shell, this works per normal
Expected Behavior
I expected the git hook to work like it did in all three regular shells.
Actual Behavior
The error mentioned in the top of the post occurs.
Additional Information
Logs
2018-09-12.desktop.production.log
Non-Solutions Tried:
Although #!/bin/sh
works on windows (as it uses bash
) it’s a non-solution for user’s on other operating systems as #!/bin/sh
does not in general point to #!/bin/bash
.
Creating a trivial #!/bin/sh
file that uses bash ./pre-commit.bash
doesn’t work Windows as bash
isn’t found when run in the github app pre-commit hook.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Git pre-commit hook is not running on Windows - Stack Overflow
A Git hook is an executable script; however, you are using a command prompt script ( . cmd ) and not a shell...
Read more >pre-commit
Run pre-commit install to install pre-commit into your git hooks. pre-commit will now run on every commit. Every time you clone a project...
Read more >Learn How to Setup Git Hooks in GitKraken Client
Once the terminal windows is open, change directory to .git/hooks . Then use the command chmod +x pre-commit to make the pre-commit file...
Read more >Git hooks, practical uses (yes, even on Windows) - tygertec
sample . To enable it, just rename it to pre-commit by removing the .sample extension and make the script executable ( chmod + ......
Read more >Commit hooks are skipped due to PATH issues - Jira - Atlassian
Committing from the command line or IDE works ok (pre-commit runs). ... despite Sourcetree being a "git GUI", it is still running shell...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@maystar, add
%LOCALAPPDATA%\Programs\Git\bin
to your user’s path viaSettings (Win + I) > Edit environment variables for your account > User variables for … > Path > Edit…
.%LOCALAPPDATA%
expands toC:\Users\<user>\AppData\Local\
.This script worked for me on Windows 10 without a Git for Windows installation on the path:
Setting
.git/hooks/precommit
to this script and making a commit would error (as intended) but with the expected message:I think
uname -s
is a fine enough approach here, but maybe older versions of Windows report the numbers differently: