forked from xenatt/Minimalism-Gnome-Shell
-
Notifications
You must be signed in to change notification settings - Fork 3
/
pre-commit.hook
executable file
·51 lines (44 loc) · 1.55 KB
/
pre-commit.hook
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
#!/bin/sh
#
# The hook should exit with non-zero status after issuing
# an appropriate message if it wants to stop the commit.
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
# If there are whitespace errors, print the offending file names and fail.
git diff-index --check --cached $against -- 1>&2
[[ $? != "0" ]] && echo -e "\033[0;31mThis commit contains whitespace issues!\033[0m"
# Usefull hooks for Gnome Shell Extensions
# Fix environment of githooks
unset GIT_DIR
# Allow to read user input below, assigns stdin to keyboard
exec < /dev/tty
# Iterate through folders with a metadata.json
for path in $(git diff --name-only --cached); do
if [[ -f "$(dirname ${path})/metadata.json" ]]; then
echo -e "\033[1;32m==>\e[39;1m Entering $(dirname ${path})...\e[0m"
# Ask whether creating a zip file is desired
zip_cmd="zip -FSr ../$(dirname ${path}).zip ."
echo -en "\e[34;1m ->\e[39;1m Do you want to zip $(dirname ${path}) using '${zip_cmd}'? [Y/n] \e[0m"
read -n1 user_input
echo
if [[ ${user_input} =~ (Y|y) ]]; then
(cd $(dirname ${path}) && ${zip_cmd})
# Ask to abort the commit in case the build fails
if [[ $? != 0 ]]; then
echo -en "\n\e[34;1m ->\e[39;1m A failure occured while zipping $(dirname ${path}). Do you want to abort this commit? [Y/n] \e[0m"
read -n1 user_input_two
echo
if [[ ${user_input_two} =~ (Y|y) ]]; then
exit 2
fi
else
echo
fi
fi
unset user_input
fi
done