tarmolov / git-hooks-js

A tool to manage and run project git hooks
167 stars 30 forks source link

[GIT-HOOKS ERROR] callback is not a function #25

Closed marcelloromanelli closed 7 years ago

marcelloromanelli commented 7 years ago

After the latest update I'm getting this error:

[GIT-HOOKS ERROR] callback is not a function
/Users/marcello/Desktop/react-mypages/node_modules/git-hooks/lib/git-hooks.js:163
        callback(1, e);
        ^

TypeError: callback is not a function
    at runHooks (/Users/marcello/Desktop/react-mypages/node_modules/git-hooks/lib/git-hooks.js:163:9)
    at /Users/marcello/Desktop/react-mypages/node_modules/git-hooks/lib/git-hooks.js:131:17
    at /Users/marcello/Desktop/react-mypages/node_modules/git-hooks/lib/git-hooks.js:36:9
    at ChildProcess.exithandler (child_process.js:213:5)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:877:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:188:7)

I currently have two githooks:

commit-msg

#!/bin/bash

source .githooks/config.sh
h1 "GIT COMMIT-MSG HOOK"

BRANCH_NAME="$(branchName)"
BRANCH_PREFIX="$(branchPrefix)"
if [ $BRANCH_NAME = "master" ] || [ $BRANCH_NAME = "HEAD" ]
then
  success "Committing $(cat $1) on master"
  echo $1
  exit 0
elif [ -n "$BRANCH_PREFIX" ]
then
  PREFIXED_MSG="${BRANCH_PREFIX}: $(cat $1)"
  success "Committing ${PREFIXED_MSG} on ${BRANCH_NAME}"
  echo $PREFIXED_MSG > "$1"
  exit 0
else
  error "The name of your branch ($BRANCH_NAME) does not follow the conventions. To ignore this run git commit with -n or with --no-verify."
  exit 1
fi

pre-commit

#!/bin/bash

source .githooks/config.sh

h1 "GIT PRE-COMMIT HOOK"
scripts=(stylelint jslint test)

for script in "${scripts[@]}"
do
   h1 "RUNNING: npm run $script"
   npm run $script
   if [ $? -ne 0 ]; then
     error "There was a problem running: $script. To ignore this, run git commit with -n or with --no-verify."
     exit 1
   else
     success "npm run $script was executed successfully"
   fi
done
zakness commented 7 years ago

I too had this issue on v1.1.2. @TitanNano’s workaround fixed it for me: https://github.com/tarmolov/git-hooks-js/issues/22#issuecomment-246307819

tarmolov commented 7 years ago

Oh... Sorry guys for a such nasty bug. I've pushed 1.1.3 with a workaround for backward compatibility. It should fix the error. Please let me know if it help or doesn't :)

npm 3.x doesn't execute preuninstall during installation. That's why you've seen the error. https://github.com/npm/npm/issues/13963

zakness commented 7 years ago

Seems to work, thanks! I verified by...

npm uninstall git-hooks
npm install git-hooks@1.1.1
npm install git-hooks@1.1.2
// reproduced issue, then...
npm install git-hooks@1.1.3
// no issue!
marcelloromanelli commented 7 years ago

Same here @tarmolov. Thanks a lot for the quick fix.