Skip to content

Commit

Permalink
add remove option to hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
snopoke committed Jun 25, 2014
1 parent 05d4e0d commit 7fa40c1
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions git-hooks/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,25 @@ This script installs CommCare HQ's default git hooks on all submodules
OPTIONS:
-h Show this message
-f don't ask before overwriting your current git hooks
-r remove existing hooks but do not add the new ones
EOF
}

CP_OPT='-i'
OPT='-i'
FUNC='copy_hooks'

while getopts "hf" OPTION
while getopts "hfr" OPTION
do
case $OPTION in
h)
usage
exit
;;
f)
CP_OPT='-f'
OPT='-f'
;;
r)
FUNC='remove_hooks'
;;
?)
usage
Expand All @@ -32,6 +37,17 @@ do
esac
done

function copy_hooks() {
hook=$1
base_path=$2
cp $OPT git-hooks/$hook.sh $base_path/hooks/$hook
}

function remove_hooks() {
hook=$1
base_path=$2
rm $OPT $base_path/hooks/$hook
}

function git-submodule-list() {
git submodule | sed 's/^+/ /' | cut -f3 -d' '
Expand All @@ -40,9 +56,9 @@ function git-submodule-list() {
for hook in 'pre-commit' 'post-checkout'
do

cp $CP_OPT git-hooks/$hook.sh .git/hooks/$hook
${FUNC} $hook '.git'
for submodule in $(git-submodule-list)
do
cp $CP_OPT git-hooks/$hook.sh .git/modules/$submodule/hooks/$hook
${FUNC} $hook ".git/modules/$submodule"
done
done

0 comments on commit 7fa40c1

Please sign in to comment.