forked from calimarkus/XcodeAutocompleteSnippets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.installPrecommitHook.sh
52 lines (43 loc) · 1.09 KB
/
.installPrecommitHook.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
#!/bin/sh
#
# Installs the pre-commit git hook
# which will automatically update the README.md
# and stage it for the current commit right before
# every actual commit
#
hookfile=".pre-commit.hook"
target=".git/hooks/pre-commit"
backupTarget=".git/hooks/pre-commit.backup"
# file existing options
cancel=false
overwrite=false
backup=false
echo "Installing pre-commit hook to update the README on every commit"
# ask what to do with existing file
if [ -e "$target" ] || [ -h "$target" ]; then
echo "A pre-commit hook already exists!"
echo "[c]ancel, [o]verwrite or [b]ackup"
while true; do
read answer
case $answer in
"c" ) cancel=true; break;;
"o" ) overwrite=true; break;;
"b" ) backup=true; break;;
* ) continue ;;
esac
done
if $overwrite; then
rm $target
fi
if $backup; then
mv $target $backupTarget
echo "Saved old hook as $backupTarget"
fi
fi
# cancel or install
if $cancel; then
echo "Canceled"
else
cp $hookfile $target
echo "Installed hook: $target"
fi