Skip to content
Merged
28 changes: 28 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 20 additions & 4 deletions hook
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions install.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.
Expand Down