summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2018-09-26 16:50:07 +0200
committerKonstantin Käfer <mail@kkaefer.com>2018-09-26 20:43:21 +0200
commit4e16e2b17961075cd698ee5380941d5593a74e1a (patch)
tree4a729ae76f2e5677adca0b790e9da6f97eac67b4
parent8556019d203785f75795b1973a0ed380235cd954 (diff)
downloadqtlocation-mapboxgl-4e16e2b17961075cd698ee5380941d5593a74e1a.tar.gz
[build] add pre-push hook for checking code formatting
-rw-r--r--scripts/hooks/common.sh23
-rwxr-xr-xscripts/hooks/pre-push25
2 files changed, 48 insertions, 0 deletions
diff --git a/scripts/hooks/common.sh b/scripts/hooks/common.sh
new file mode 100644
index 0000000000..4d333689f8
--- /dev/null
+++ b/scripts/hooks/common.sh
@@ -0,0 +1,23 @@
+if [ "$1" = '--install' ]; then
+ mkdir -p ".git/hooks"
+ if [ -e ".git/hooks/$HOOK" ] || [ -L ".git/hooks/$HOOK" ]; then
+ if [ "$(readlink .git/hooks/$HOOK)" != "scripts/hooks/$HOOK" ]; then
+ echo "Can't install $HOOK because it has custom content"
+ else
+ echo "$HOOK hook is already installed"
+ fi
+ exit 1
+ fi
+ echo "Installing $HOOK hook"
+ ln -s ../../scripts/hooks/$HOOK .git/hooks/$HOOK
+ exit 0
+elif [ "$1" = '--uninstall' ]; then
+ if [ "$(readlink .git/hooks/$HOOK)" = "scripts/hooks/$HOOK" ]; then
+ echo "Removing $HOOK hook"
+ rm .git/hooks/$HOOK
+ exit 0
+ else
+ echo "$HOOK hook is not installed"
+ exit 1
+ fi
+fi
diff --git a/scripts/hooks/pre-push b/scripts/hooks/pre-push
new file mode 100755
index 0000000000..84bdafd70e
--- /dev/null
+++ b/scripts/hooks/pre-push
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+cd "$(git rev-parse --show-toplevel 2>/dev/null)"
+HOOK=$(basename "${BASH_SOURCE[0]}")
+source "scripts/hooks/common.sh"
+
+echo -n "Checking code formatting..."
+RESULT=$(scripts/nitpick/format.js)
+if [ ! -z "$RESULT" ]; then
+ echo -e " \033[1;31mChanged\033[0m"
+ echo -e -n "\033[1mDo you want to see the diff [y/N]?\033[0m "
+ read < /dev/tty
+ if [[ $REPLY =~ ^[Yy]$ ]]; then
+ echo "$RESULT"
+ echo ""
+ fi
+
+ echo -e -n "\033[1mContinue to push? [Y/n]?\033[0m "
+ read < /dev/tty
+ if [[ $REPLY =~ ^[Nn]$ ]]; then
+ exit 1
+ fi
+else
+ echo -e " \033[32mOK\033[0m"
+fi