-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_pre_commit_hook.sh
executable file
·34 lines (26 loc) · 1.04 KB
/
setup_pre_commit_hook.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
if [ "$1" == "" ]; then
echo "Please specify your git repo directory to install the hook"
exit 1
else
GIT_REPO_DIR="$1"
fi
echo "Enable git templates"
git config --global init.templatedir "$HOME/.git-templates"
echo -e "\nCreate a directory (~/.git-templates/hooks) to hold the global hoooks"
mkdir -p ~/.git-templates/hooks
cp pre-commit ~/.git-templates/hooks
cp pre-push ~/.git-templates/hooks
#DIR="~/" # for production
#DIR="/tmp/" # for testing
echo -e "\nFind all the git repos under $GIT_REPO_DIR directory"
#ALL_GIT_REPOS=$(find ~/ -name .git | sed 's/\.git//g')
#ALL_GIT_REPOS=$(find /tmp/ -name .git | sed 's/\.git//g')
ALL_GIT_REPOS=$(find $GIT_REPO_DIR -name .git | sed 's/\.git//g')
for repo in $ALL_GIT_REPOS; do
echo -e "\nRunning git init on $repo under $DIR to copy the global hook";
cd "$repo"; git init;
done;
# one liner
#for repo in `find ~/ -name .git | sed 's/\.git//g'`; do cd $repo; git init; done
echo -e "\n\nFor more information, see https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook"