From f81ce29bda678b2a267eca99aaac88a4e19567ee Mon Sep 17 00:00:00 2001 From: "James D. Forrester" Date: Fri, 14 Mar 2014 13:44:21 -0700 Subject: [PATCH] Add a clean-up script for use as a pre-commit hook Change-Id: I0e87cbd2d653f4125e2a3d40cda30a3464a7a287 --- CONTRIBUTING.md | 15 +++++++++++++++ bin/pre-commit.sh | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100755 bin/pre-commit.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 97dbf00ee5..e57316d1ed 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -20,3 +20,18 @@ $wgEnableJavaScriptTest = true; Then open `http://URL_OF_MEDIAWIKI/index.php/Special:JavaScriptTest/qunit` (for example, ). + +Node-based code linting tests can be run locally using npm – run: + +
+npm install && npm test
+
+ + +## Pre-commit hook + +A pre-commit git hook script exists which will help flag up any issues and avoid irritating code review steps for you and reviewers. Simply do: + +
+ln -s bin/pre-commit.sh ../.git/hooks/pre-commit
+
diff --git a/bin/pre-commit.sh b/bin/pre-commit.sh new file mode 100755 index 0000000000..393cb149c6 --- /dev/null +++ b/bin/pre-commit.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# If the VE core sub-module was touched +if git diff --quiet --cached lib/ve; then + + GITBRANCH=`git rev-parse --abbrev-ref HEAD`; + + # … and it doesn't look like + if [[ $GITBRANCH != "sync-repos" ]]; then + echo "VE core sub-module was touched but commit isn't from 'sync-repos'."; + exit 1; + fi + +fi + +# Stash any uncommited changes +git stash -q --keep-index + +npm install || git stash pop -q && exit 1 +npm test && git add -u .docs/* || git stash pop -q && exit 1 + +# Re-apply any uncommited changes +git stash pop -q