diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..a82ea4a --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,28 @@ +environment: + matrix: + - nodejs_version: "0.8" + - nodejs_version: "0.10" + - nodejs_version: "0.12" + - nodejs_version: "1.0" + +matrix: + fast_finish: true + allow_failures: + - platform: x86 + - platform: x64 + +platform: + - x86 + - x64 + +install: + - ps: Install-Product node $env:nodejs_version $env:platform + - npm install -g npm@2.x.x + - npm install + +test_script: + - node --version + - npm --version + - npm test + +build: off diff --git a/hook b/hook index b849890..66debda 100755 --- a/hook +++ b/hook @@ -16,13 +16,29 @@ NODE=`which node 2> /dev/null` NODEJS=`which nodejs 2> /dev/null` IOJS=`which iojs 2> /dev/null` LOCAL="/usr/local/bin/node" +BINARY= +# +# Figure out which binary we need to use for our script execution. +# if [[ -n "$NODE" ]]; then - "$NODE" $("$NODE" -e "console.log(require.resolve('pre-commit'))") + BINARY="$NODE" elif [[ -n "$NODEJS" ]]; then - "$NODEJS" $("$NODEJS" -e "console.log(require.resolve('pre-commit'))") + BINARY="$NODEJS" elif [[ -n "$IOJS" ]]; then - "$IOJS" $("$IOJS" -e "console.log(require.resolve('pre-commit'))") + BINARY="$IOJS" elif [[ -x "$LOCAL" ]]; then - "$LOCAL" $("$LOCAL" -e "console.log(require.resolve('pre-commit'))") + BINARY="$LOCAL" +fi + +# +# Add --dry-run cli flag support so we can execute this hook without side affects +# and see if it works in the current environment +# +if [[ $* == *--dry-run* ]]; then + if [[ -z "$BINARY" ]]; then + exit 1 + fi +else + "$BINARY" $("$BINARY" -e "console.log(require.resolve('pre-commit'))") fi diff --git a/install.js b/install.js index 3624b25..323753b 100644 --- a/install.js +++ b/install.js @@ -5,6 +5,7 @@ // var fs = require('fs') , path = require('path') + , shelly = require('shelljs') , hook = path.join(__dirname, './hook') , root = path.resolve(__dirname, '../..') , exists = fs.existsSync || path.existsSync; @@ -19,6 +20,18 @@ var git = path.resolve(root, '.git') , hooks = path.resolve(git, 'hooks') , precommit = path.resolve(hooks, 'pre-commit'); +// +// Make sure that we can execute the hook without any issues before continuing. +// +if (shelly.exec(hook +' --dry-run', { silent: true }).code !== 0) { + console.error('pre-commit:'); + console.error('pre-commit: The --dry-run of the pre-commit hook failed to execute.'); + console.error('pre-commit:'); + console.error('pre-commit: The hook was not installed.'); + console.error('pre-commit:'); + return; +} + // // Bail out if we don't have an `.git` directory as the hooks will not get // triggered. If we do have directory create a hooks folder if it doesn't exist.