Skip to content
Snippets Groups Projects
Commit 5b92b29d authored by squidfunk's avatar squidfunk Committed by Martin Donath
Browse files

Refactored output of git hooks

parent c59d7760
Branches
Tags
No related merge requests found
......@@ -25,6 +25,6 @@ CHANGED="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
# Perform install and prune of NPM dependencies if package.json changed
if $(echo "$CHANGED" | grep --quiet package.json); then
echo "Hook[post-merge]: Updating dependencies"
echo -e "\x1B[33m!\x1B[0m Updating dependencies"
npm install && npm prune
fi
......@@ -22,12 +22,14 @@
# Determine current branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
echo "Hook[pre-commit]: Checking branch"
MESSAGE="Commits on master are only allowed via Pull Requests. Aborting."
# If we're on master, abort commit
if [[ "$BRANCH" == "master" ]]; then
echo "Commits on master are only allowed via Pull Requests. Aborting."
echo -e "\x1B[31m✗\x1B[0m Branch: $BRANCH - \x1B[31m$MESSAGE\x1B[0m"
exit 1
else
echo -e "\x1B[32m✓\x1B[0m Branch: $BRANCH"
fi
# We're good
......
......@@ -22,6 +22,7 @@
# Patch file to store unindexed changes
PATCH_FILE=".working-tree.patch"
MESSAGE="Terminated with errors"
# Revert changes that have been registered in the patch file
function cleanup {
......@@ -46,6 +47,16 @@ FILES=$(git diff --cached --name-only --diff-filter=ACMR | \
# Run the check and print indicator
if [ "$FILES" ]; then
echo "Hook[pre-commit]: Running linter"
npm run lint --silent || exit 1
npm run lint --silent
# If we're on master, abort commit
if [ $? -gt 0 ]; then
echo -e "\x1B[31m✗\x1B[0m Linter - \x1B[31m$MESSAGE\x1B[0m"
exit 1
else
echo -e "\x1B[32m✓\x1B[0m Linter"
fi
fi
# We're good
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment