Skip to content

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

Closed

Description

@MrAntix

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

Activity

  1. added
    bug
    on Oct 16, 2017
  2. shiftkey commented on Oct 17, 2017

    @shiftkey
    Member

    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).

  3. MrAntix commented on Oct 17, 2017

    @MrAntix
    Author

    The work around does work for me, but not for my colleague, who doesn't have a C: drive

    For now we can manage this, thanks for the explanation.

  4. technoweenie commented on Oct 17, 2017

    @technoweenie

    Those hooks are likely written by LFS, so it's possible that it could be taught to write the correct #! line. I'm not sure how feasible it is to figure out that it should use #!C:/Program\ Files/Git/usr/bin/sh.exe, without asking users to configure it manually. Any suggestions?

  5. shiftkey commented on Oct 17, 2017

    @shiftkey
    Member

    @technoweenie nah, I wouldn't worry about a fix for this in Git LFS right now. Imagine a scenario where we only have Desktop installed - Git will live under %LOCALAPPDATA% at a version-specific location, and I can think of a few ways this is going to make your life hell.

    We'll teach our Git to be smarter about this, as that's much more malleable (and our responsibility ultimately).

  6. self-assigned this
    on Oct 29, 2017
  7. shiftkey commented on Oct 30, 2017

    @shiftkey
    Member

    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 desktop/dugite#141 merged and updated here.

  8. locked as resolved and limited conversation to collaborators on Jul 19, 2018
  9. unlocked this conversation on Sep 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions