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.

post checkout hook gives error when using desktop app, but fine in cmd line

See original GitHub issue

Description

I have a post-checkout hook.

When I use the command line the hook runs and the echo shows the message as expected

When I use the desktop I get an error message on checkout (see attached) image

Version

GitHub Desktop version: 1.0.4

OS version: Microsoft Windows [Version 10.0.15063]

Steps to Reproduce

  1. get a copy of https://github.com/MrAntix/github-desktop-hooks
  2. install the hook (run install-hooks.bat)
  3. open in desktop
  4. checkout the other branch

Expected behavior: hook is run

Actual behavior: error - hook is not run

Reproduces how often: 100%

Logs

2017-10-16T11:30:56.993Z - info: [ui] launching: 1.0.4 (Windows 10.0.15063) 2017-10-16T11:31:00.758Z - error: [ui] git checkout --progress master -- exited with an unexpected code: 1. Your branch is up-to-date with ‘origin/master’.

Switched to branch ‘master’ error: cannot spawn .git/hooks/post-checkout: No such file or directory

Additional Information

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
shiftkeycommented, Oct 17, 2017

This is an interesting side-effect of how we bundle Git in the app, and I needed to cast my mind back to this classic post.

Under the section “WHY WON’T GIT HOOKS WORK ON WINDOWS?”, we have this section:

On Unix-like OS’s, the #! tells the program loader that this is a script to be interpreted, and /bin/sh is the path to the interpreter you want to use, sh in this case. Windows is definitely not a Unix-like OS. Git for Windows supports Bash commands and shell scripts via Cygwin. By default, what does it find when it looks for sh.exe at /bin/sh? Yup, nothing; nothing at all.

What’s the fix?

Fix it by providing the path to the sh executable on your system.

As a workaround, these scripts can directly reference your Git installation, like so:

#!C:/Program\ Files/Git/usr/bin/sh.exe

That will work for you, but it’s not an actual solution. Git for Windows doesn’t set any other environment variables than the path to git.exe, so it might have some magic internals we need to mimic when we invoke Git inside the app (our version of Git is limited in features, but it does have sh.exe).

0reactions
shiftkeycommented, Oct 30, 2017

We can’t support bash.exe scripts on Windows currently because it’s not part of the Git installation we embed, but /bin/sh support should work once I get https://github.com/desktop/dugite/pull/141 merged and updated here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Git checkout in post-receive hook: "Not a git repository '.'"
When I run sh . git/hooks/post-receive, everything works fine. But when I push from my PC I get this error: remote: fatal: Not...
Read more >
Commit hooks are skipped due to PATH issues - Jira - Atlassian
At first I thought it's a problem with lint-staged or husky but eventually found that SourceTree on Mac just skips the commit hooks....
Read more >
Git Hooks - Git SCM
The post-rewrite hook is run by commands that replace commits, such as git commit --amend and git rebase (though not by git filter-branch...
Read more >
TortoiseSVN's Settings
On Windows Vista and later systems this controls whether dialogs use the Aero ... Subversion clients running on your PC, including the command...
Read more >
Code with Git - Azure DevOps - Microsoft Learn
Open the Git command window (Git Bash on Git for Windows). Go to the folder where you want the code from the repo...
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