summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Bayer <bbayer@multitech.com>2016-09-29 16:25:31 -0500
committerBrandon Bayer <bbayer@multitech.com>2016-09-29 16:25:31 -0500
commit3ffa09de192d81305acd2233167eae91de856e3f (patch)
treee4efdb2eb869e5e98db73eabc0469e1632707374
parent58cde28b59eb65dc34c0a36b6ab30f42128c6df6 (diff)
downloadmlinux-3ffa09de192d81305acd2233167eae91de856e3f.tar.gz
mlinux-3ffa09de192d81305acd2233167eae91de856e3f.tar.bz2
mlinux-3ffa09de192d81305acd2233167eae91de856e3f.zip
chore: add pre-commit/pre-push hooks to prevent GitLab submodules on master
-rwxr-xr-xscripts/git-hooks/pre-commit18
-rwxr-xr-xscripts/git-hooks/pre-push18
-rwxr-xr-xsetup.sh5
3 files changed, 41 insertions, 0 deletions
diff --git a/scripts/git-hooks/pre-commit b/scripts/git-hooks/pre-commit
new file mode 100755
index 0000000..f930ca7
--- /dev/null
+++ b/scripts/git-hooks/pre-commit
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+currentBranch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
+
+if [ "$currentBranch" == "master" ]; then
+ gitlabOccurances=$(grep -c -m1 gitlab .gitmodules)
+
+ if [ $gitlabOccurances -eq 1 ]; then
+ echo "COMMIT INVALID: You can't commit anything to the master branch that pulls
+from GitLab because outsiders won't be able to build it.
+
+If you need to use a submodule from GitLab, do so from a branch."
+ exit 1
+ fi
+fi
+
+exit 0 # Everything is good
+
diff --git a/scripts/git-hooks/pre-push b/scripts/git-hooks/pre-push
new file mode 100755
index 0000000..85b5095
--- /dev/null
+++ b/scripts/git-hooks/pre-push
@@ -0,0 +1,18 @@
+#!/bin/bash
+
+currentBranch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
+
+if [ "$currentBranch" == "master" ]; then
+ gitlabOccurances=$(grep -c -m1 gitlab .gitmodules)
+
+ if [ $gitlabOccurances -eq 1 ]; then
+ echo "PUSH ERROR: You can't push anything to the master branch that pulls
+from GitLab because outsiders won't be able to build it.
+
+If you need to use a submodule from GitLab, do so from a branch."
+ exit 1
+ fi
+fi
+
+exit 0 # Everything is good
+
diff --git a/setup.sh b/setup.sh
index 6f090cf..ec460f5 100755
--- a/setup.sh
+++ b/setup.sh
@@ -3,6 +3,11 @@
set -e
echo ""
+echo "Setting up git hooks..."
+ln -s ../../scripts/git-hooks/pre-commit .git/hooks/pre-commit
+ln -s ../../scripts/git-hooks/pre-push .git/hooks/pre-push
+
+echo ""
echo "Updating git submodules..."
git submodule update --init