forked from techjoomla/maintenance-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
symlink_git_hooks.sh
72 lines (62 loc) · 2.45 KB
/
symlink_git_hooks.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
# Author : Manoj L
# Usage : This script creates symlinks of git hook files into all git repos
# Step1 : Edit this file to specify eg: git_root_dir="/home/manoj/GIT";
# Step2 : Save and execute this file
# Assumption: It assumes all of your git repos are in git_root_dir folder
# $ HOME = eg. /home/manoj
# eg. git_root_dir=$HOME"/GIT";
git_root_dir=$HOME"/GIT";
# Jump to git repos folder
cd $git_root_dir
# If hooks repo not found, clone it first
if [ ! -d "maintenance-scripts" ]; then
echo "PHPCS hooks repo not found"
echo "Cloning PHPCS hooks repo"
git clone [email protected]:techjoomla/maintenance-scripts.git
else
echo "PHPCS hooks repo found"
echo "Getting latest PHPCS hooks code"
cd maintenance-scripts
git pull
cd ..
fi
# Define hooks paths to symlink
hook_path_commit_msg="${git_root_dir}/maintenance-scripts/commit-msg"
hook_path_pre_commit="${git_root_dir}/maintenance-scripts/pre-commit"
hook_path_config="${git_root_dir}/maintenance-scripts/config"
# Get all git repos in git repos folder
for repo in $(ls -d */);
do
if [ $repo != "maintenance-scripts" ]; then
echo '\033[0;33m';
echo '>>> Setting up hooks in repo:' ${repo%%/} '\033[1;37m'
# Do this for all hook files - rename existing hook, symlink latest hook, set new hook as excutable
# Commit msg hook
echo 'Copying commit msg hook from' $hook_path_commit_msg
#mv "$repo".git/hooks/commit-msg "$repo".git/hooks/commit-msg"_old"
#rm "$repo".git/hooks/commit-msg"_old"
#ln -sf $hook_path_commit_msg "$repo".git/hooks/commit-msg
yes | cp $hook_path_commit_msg "$repo".git/hooks/commit-msg
chmod +x "$repo".git/hooks/commit-msg
# Pre-commit hook
echo 'Copying pre-commit hook from' $hook_path_pre_commit
#mv "$repo".git/hooks/pre-commit "$repo".git/hooks/pre-commit"_old"
#rm "$repo".git/hooks/pre-commit
#ln -sf $hook_path_pre_commit "$repo".git/hooks/pre-commit
yes | cp $hook_path_pre_commit "$repo".git/hooks/pre-commit
chmod +x "$repo".git/hooks/pre-commit
# Commit msg hook
echo 'Copying config file from ' $hook_path_config
if [ -e "$repo".git/hooks/config ]; then
#mv "$repo".git/hooks/config "$repo".git/hooks/config"_old"
#rm "$repo".git/hooks/config
# ln -sf $hook_path_config "$repo".git/hooks/config
yes | cp $hook_path_config "$repo".git/hooks/config
else
yes | cp $hook_path_config "$repo".git/hooks/config
fi
chmod +x "$repo".git/hooks/config
fi
done
echo "\033[0;32m############ Done! ############\033[0;39m"