Skip to content

husky hooks failing to execute as latest RC depends on /bin/bash  #3860

Closed

Description

@markgoho-EDT

Description

Pre-commit/push hooks failing

Version

GitHub Desktop version: 1.0.12

OS version: Windows 10

Steps to Reproduce

  1. Install Husky (v0.15)
  2. Add pre-commit hook
  3. Try to commit from Desktop client

Expected behavior: Pre-commit hook would run

Actual behavior: I get this error message:
image
on pre-push I get this:
image

Reproduces how often: [What percentage of the time does it reproduce?]100%

Logs

I see no logs at the file paths mentioned in the comment.

Additional Information

The hooks work fine from the command line, just not from the client. This is why I believe it is an issue with Github Desktop.

Activity

  1. iAmWillShepherd commented on Jan 26, 2018

    @iAmWillShepherd
    Contributor

    You should be able to find your logs by clicking Help -> Show logs in explorer.

  2. shiftkey commented on Jan 28, 2018

    @shiftkey
    Member

    @markgoho-EDT we've had a couple of run-ins with Husky and pre-commits in the past (see #2518 and #1734) but that error message is new. Are you able to put together a more detailed repro of the issue, so we can ensure we're testing the right behaviour?

  3. added
    more-info-needed
    on Jan 28, 2018
  4. markgoho-EDT commented on Jan 31, 2018

    @markgoho-EDT
    Author

    @iAmWillShepherd logs:

    2018-01-31T23:15:50.435Z - info: [ui] [AppStore] adding account markgoho-EDT (Mark Goho) to store
    2018-01-31T23:16:00.567Z - info: [ui] Executing getRecentBranches: git log -g --no-abbrev-commit --pretty=oneline HEAD -n 2500 -- (took 1.451s)
    2018-01-31T23:16:03.685Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune origin (took 2.908s)
    2018-01-31T23:16:10.502Z - info: [ui] [AppStore.withAuthenticatingUser] account found for repository: app-copa - markgoho-EDT (has token)
    2018-01-31T23:16:13.144Z - info: [ui] Executing pull: git -c credential.helper= pull --no-rebase --progress origin (took 2.438s)
    2018-01-31T23:16:15.367Z - info: [ui] Executing getStatus: git status --untracked-files=all --branch --porcelain=2 -z (took 2.222s)
    2018-01-31T23:16:25.249Z - info: [ui] Executing getAheadBehind: git rev-list --left-right --count componentize-order-form...origin/componentize-order-form -- (took 6.022s)
    2018-01-31T23:16:26.449Z - info: [ui] Executing getAheadBehind: git rev-list --left-right --count in-mem-api...origin/in-mem-api -- (took 1.226s)
    2018-01-31T23:16:30.875Z - info: [ui] Executing getAheadBehind: git rev-list --left-right --count master...origin/master -- (took 3.554s)
    2018-01-31T23:16:32.752Z - info: [ui] Executing getAheadBehind: git rev-list --left-right --count ngrx-refactor...origin/ngrx-refactor -- (took 1.806s)
    2018-01-31T23:16:34.286Z - info: [ui] Executing getAheadBehind: git rev-list --left-right --count order-route...origin/order-route -- (took 1.537s)
    2018-01-31T23:21:36.766Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune origin (took 2.045s)
    2018-01-31T23:21:38.491Z - info: [ui] Executing getRecentBranches: git log -g --no-abbrev-commit --pretty=oneline HEAD -n 2500 -- (took 1.666s)
    2018-01-31T23:22:29.394Z - info: [ui] Executing getRecentBranches: git log -g --no-abbrev-commit --pretty=oneline HEAD -n 2500 -- (took 1.579s)
    2018-01-31T23:22:55.501Z - error: [ui] `git commit -F -` exited with an unexpected code: 1.
    error: cannot spawn .git/hooks/pre-commit: No such file or directory
    
    2018-01-31T23:27:11.738Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune origin (took 1.149s)
    2018-01-31T23:32:44.638Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune origin (took 1.047s)
    2018-01-31T23:38:17.602Z - info: [ui] Executing fetch: git -c credential.helper= fetch --progress --prune origin (took 2.013s)
    

    @shiftkey There's not much more to what I did besides install Husky, add the pre-push/pre-commit hooks and then try to commit and push via the Desktop client.

    Here are my pre-commit and pre-push files:

    pre-push:

    #!/bin/bash
    # husky
    # v0.15.0-rc.3
    
    hookname=`basename "$0"`
    [ -f package.json ] && cat package.json | grep -q "\"$hookname\"[[:space:]]*:"
    
    export GIT_PARAMS="$*"
    
    if [[ $? -eq 0 ]]; then
      node_modules/husky/node_modules/.bin/run-node ./node_modules/husky/lib/runner/bin $hookname
      exit $?
    fi

    pre-commit:

    #!/bin/bash
    # husky
    # v0.15.0-rc.3
    
    hookname=`basename "$0"`
    [ -f package.json ] && cat package.json | grep -q "\"$hookname\"[[:space:]]*:"
    
    export GIT_PARAMS="$*"
    
    if [[ $? -eq 0 ]]; then
      node_modules/husky/node_modules/.bin/run-node ./node_modules/husky/lib/runner/bin $hookname
      exit $?
    fi
  5. shiftkey commented on Feb 1, 2018

    @shiftkey
    Member

    @markgoho-EDT

    There's not much more to what I did besides install Husky, add the pre-push/pre-commit hooks and then try to commit and push via the Desktop client.

    I think the version of Husky here would have helped, which is thankfully embedded in the hook scripts.

    Here's a working package.json file for Husky:

    {
      "name": "hello-husky",
      "version": "1.0.0",
      "scripts": {
        "precommit": "echo precommit"
      },
      "devDependencies": {
        "husky": "^0.14.3"
      }
    }
    

    And here's one that doesn't:

    {
      "name": "hello-husky",
      "version": "1.0.0",
      "scripts": {
        "precommit": "echo precommit"
      },
      "devDependencies": {
        "husky": "^0.15.0-rc.3"
      }
    }
    

    I'm not sure why you're on the RC version of Husky here, but it looks like they've decided to force everyone to use #!/bin/bash to execute bash scripts. The version of Git we use in Desktop doesn't support Bash scripting (it's stripped back to the minimum that apps need, and bash.exe didn't make the cut). The previous stable version of Husky uses #!/bin/sh which doesn't trigger the error in Desktop.

    I'm not sure why Husky is forcing /bin/bash here, and I've not had a chance to test other shells like CMD and PowerShell to see if they're affected by this change.

  6. changed the title [-]Husky hooks failing[/-] [+]husky hooks failing to execute as latest RC depends on /bin/bash [/+] on Feb 1, 2018
  7. j-f1 commented on Feb 1, 2018

    @j-f1
    Contributor

    The blame shows that the #! was changed in October, in typicode/husky@48e3f88, which tells us that this change was to “Update hook.sh.”

  8. shiftkey commented on Feb 1, 2018

    @shiftkey
    Member

    I've cross-referenced this information in a related issue against the repository: typicode/husky#228

  9. shiftkey commented on Feb 2, 2018

    @shiftkey
    Member

    The husky maintainer has switched back to the stable release of husky for now which doesn't depend on /bin/bash, and I'm working with them to see if they can keep the next version running without requiring bash on Windows, so I'm going to close this out and track the upstream issue.

  10. millerf commented on May 3, 2018

    @millerf

    +1

  11. locked as resolved and limited conversation to collaborators on Jul 17, 2018
  12. 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

No one assigned

    Labels

    more-info-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions