Skip to content

Commit 18057d9

Browse files
committed
Rewrite hook to javascript
1 parent 4a5006d commit 18057d9

File tree

1 file changed

+6
-25
lines changed
  • .githooks/pre-commit

1 file changed

+6
-25
lines changed

.githooks/pre-commit/test

+6-25
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,9 @@
1-
#!/bin/bash
2-
#
3-
# * Check changed js files using jshint and jscs.
4-
# * Runs tests.
5-
#
1+
#!/usr/bin/env node
62

7-
PATCH_FILE="working-tree.patch"
8-
NPM_BIN="./node_modules/.bin"
3+
var spawn = require('child_process').spawn;
4+
var exec = require('child_process').execSync;
5+
var gitCachedFiles = exec('git diff --cached --name-only --diff-filter=ACMR').toString().trim();
96

10-
function cleanup {
11-
exit_code=$?
12-
if [ -f "$PATCH_FILE" ]; then
13-
git apply "$PATCH_FILE" 2> /dev/null
14-
rm "$PATCH_FILE"
15-
fi
16-
exit $exit_code
7+
if (gitCachedFiles) {
8+
spawn('npm', ['test'], {stdio: 'inherit'}).on('close', process.exit.bind(process));
179
}
18-
19-
trap cleanup EXIT SIGINT SIGHUP
20-
21-
# Cancel any changes to the working tree that are not going to be committed
22-
git diff > "$PATCH_FILE"
23-
git checkout -- .
24-
25-
git_cached_files=$(git diff --cached --name-only --diff-filter=ACMR | grep "\.js$")
26-
if [ "$git_cached_files" ]; then
27-
npm test --silent || exit 1
28-
fi

0 commit comments

Comments
 (0)