summaryrefslogtreecommitdiff
path: root/infra/command/install-githooks
diff options
context:
space:
mode:
Diffstat (limited to 'infra/command/install-githooks')
-rw-r--r--infra/command/install-githooks68
1 files changed, 59 insertions, 9 deletions
diff --git a/infra/command/install-githooks b/infra/command/install-githooks
index e624aa6d7..909a16542 100644
--- a/infra/command/install-githooks
+++ b/infra/command/install-githooks
@@ -1,15 +1,65 @@
#!/usr/bin/env bash
+function Usage()
+{
+ echo "Usage: $0 $(basename ${BASH_SOURCE[0]}) [<OPTIONS>]"
+ echo ""
+ echo "Options:"
+ echo " --no-pre-push don't install pre-push hook"
+ echo " --no-pre-commit don't install pre-commit hook"
+}
+
+SKIP_PREPUSH_INSTALL="0"
+SKIP_PRECOMMIT_INSTALL="0"
+
+while [[ $# -gt 0 ]]
+do
+ arg="$1"
+ case $arg in
+ -h|--help|help)
+ Usage
+ exit 1
+ ;;
+ --no-pre-push)
+ SKIP_PREPUSH_INSTALL="1"
+ shift
+ ;;
+ --no-pre-commit)
+ SKIP_PRECOMMIT_INSTALL="1"
+ shift
+ ;;
+ *)
+ echo "ERROR: invalid option"
+ exit 255
+ ;;
+ esac
+done
+
REPO_HOOKS_PATH=$NNAS_PROJECT_PATH/infra/git-hooks
GIT_HOOKS_PATH=$NNAS_PROJECT_PATH/.git/hooks
-# Create symbolic links to hooks dir
-if [ -e $GIT_HOOKS_PATH/pre-push ]; then
- echo "Backup old $GIT_HOOKS_PATH/pre-push to $GIT_HOOKS_PATH/pre-push~"
- mv -v $GIT_HOOKS_PATH/pre-push $GIT_HOOKS_PATH/pre-push~
-elif [ -h $GIT_HOOKS_PATH/pre-push ]; then
- ls -l $GIT_HOOKS_PATH/pre-push
- echo "Remove broken symlink $GIT_HOOKS_PATH/pre-push"
- rm -v $GIT_HOOKS_PATH/pre-push
+if [ $SKIP_PREPUSH_INSTALL == "0" ]; then
+ # Create symbolic links to hooks dir
+ if [ -e $GIT_HOOKS_PATH/pre-push ]; then
+ echo "Backup old $GIT_HOOKS_PATH/pre-push to $GIT_HOOKS_PATH/pre-push~"
+ mv -v $GIT_HOOKS_PATH/pre-push $GIT_HOOKS_PATH/pre-push~
+ elif [ -h $GIT_HOOKS_PATH/pre-push ]; then
+ ls -l $GIT_HOOKS_PATH/pre-push
+ echo "Remove broken symlink $GIT_HOOKS_PATH/pre-push"
+ rm -v $GIT_HOOKS_PATH/pre-push
+ fi
+ ln -sv $REPO_HOOKS_PATH/pre-push.sh $GIT_HOOKS_PATH/pre-push
+fi
+
+if [ $SKIP_PRECOMMIT_INSTALL == "0" ]; then
+ # Create symbolic links to hooks dir
+ if [ -e $GIT_HOOKS_PATH/pre-commit ]; then
+ echo "Backup old $GIT_HOOKS_PATH/pre-commit to $GIT_HOOKS_PATH/pre-commit~"
+ mv -v $GIT_HOOKS_PATH/pre-commit $GIT_HOOKS_PATH/pre-commit~
+ elif [ -h $GIT_HOOKS_PATH/pre-commit ]; then
+ ls -l $GIT_HOOKS_PATH/pre-commit
+ echo "Remove broken symlink $GIT_HOOKS_PATH/pre-commit"
+ rm -v $GIT_HOOKS_PATH/pre-commit
+ fi
+ ln -sv $REPO_HOOKS_PATH/pre-commit.sh $GIT_HOOKS_PATH/pre-commit
fi
-ln -sv $REPO_HOOKS_PATH/pre-push.sh $GIT_HOOKS_PATH/pre-push