question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to commit when git hooks use bash syntax.

See original GitHub issue

Describe the feature or problem you’d like to solve

Our project have git hooks that were written for Mac and Linux but I am in windows. WSL is my dev env and can run these hooks but Github desktop will not run any git commands in WSL behind the scenes.

Github desktop is unusable by many devs using WSL.

When a git hook is run via GitHub desktop we see: Commit failed - exit code 1 received, with output: ‘’.’ is not recognized as an internal or external command, operable program or batch file.’

Also tried using bash as my shell. Also tried adding “bash -c” etc into the git hooks that run but then I get “bash is not a recognized command” even tho it IS recognized by all my shells.

Proposed solution

Please add WSL integration || or actually use the shell to run already working git cli so that desktop is just an interface running git commands behind the scenes would be nice.

Additional context

Some context… the hooks are php files with #!/usr/bin/env php

<?php They run additional commands also with shell executions/passthrough. I tried editing those to add `bash -c` etc however and see "bash is not a recognized command" Even who it IS a recognized command in windows and works for all my shells. 🤷‍♀️ I have seen people talking about editing the source to add custom shells but its easier to just not use Github. I don't have the option of not using WSL or editing the git hooks to support windows at this stage.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
b-hayescommented, Jun 29, 2022

Oops, I totally blanked on the recognizing it was a Windows env, as I was thrown off with the Mac and Linux comment. 😝

But I do think this could fix a lot of things across all systems if the git commands were run in the user’s shell of choice.

I do think you are in luck as I just spotted this: #8863 which was just released today!

I see that issue says “Fixed not being able to run the GitHub command from the WSL CLI” which is not what I am talking about. I meant that git commands are run in the user’s shell behind the scenes to avoid all the issues.

Example: In Github desktop, I click commit and it runs WSL "git commit -m \"the commit message\""

Running git itself in the users chosen shell means it bypasses having to add special support for the bash syntax or detecting and running git hooks in the appropriate manner according to the shebang lines in the script. Doing it this way means what shell is installed or what version of bash.exe is used doesn’t matter. The correct version of PHP or node or anything else needed to be run by a shebang line will be of no concern if native git command is run in the wsl ditrol.

Just bypass all of it and use Github desktop to execute commands for you as if you were in the terminal.

0reactions
b-hayescommented, Jun 28, 2022

added git hooks to WSL project so guess I need to move on from github desktop then?

yeah pretty much. 2 years later and we still cant use github desktop with wsl at all.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git Hooks - Git SCM
To enable a hook script, put a file in the hooks subdirectory of your .git ... The pre-commit hook is run first, before...
Read more >
Git Hooks | Atlassian Git Tutorial
Git Hooks are scripts that run automatically every time a particular event occurs in a Git repository. Learn what they do and how...
Read more >
unable to use post-commit hook if it includes 'git push' command
The issue is when a post-commit hook includes git push command, the application's commit process gets stuck. Version & OS Github Desktop: ...
Read more >
Committing fails in Git hooks pre-commit because the node ...
For me, I use bash as default shell and my ~/.bashrc has got a whole bunch of paths set, whereas my .git/hooks/pre-commit was...
Read more >
How to use git pre-commit hooks, the hard way and the easy ...
The hook runs before a commit is accepted to git, and if the hook script fails (ie if it returns a non-zero exit...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found