-
Notifications
You must be signed in to change notification settings - Fork 0
/
pre-commit.hook
executable file
·45 lines (38 loc) · 1.41 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
#!/bin/bash
#
# 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 || >&2 echo -e "\\033[0;31mThis commit contains whitespace issues!\\033[0m"
# Usefull hooks for Chrome Extensions
# Retrieve the name of the Porject through the git root directory name
project_root="$(basename "$(git rev-parse --show-toplevel)")"
# Fix environment of githooks
unset GIT_DIR
# Allow to read user input below, assigns stdin to keyboard
exec < /dev/tty
# Ask whether a zipping is desired
zip_cmd="zip -FSr ../${project_root}.zip ."
echo -en "\\e[34;1m ->\\e[39;1m Do you want to zip the Project using '${zip_cmd}'? [Y/n] \\e[0m"
read -rn1 user_input
echo
if [[ "${user_input}" =~ (Y|y) ]]; then
# Ask to abort the commit in case the build fails
if ! (cd "$(git rev-parse --show-toplevel)/${project_root}" && ${zip_cmd}); then
echo -en "\\n\\e[34;1m ->\\e[39;1m A failure occured while zipping the package. Do you want to abort this commit? [Y/n] \\e[0m"
read -rn1 user_input_two
echo
if [[ "${user_input_two}" =~ (Y|y) ]]; then
exit 2
fi
else
echo
fi
fi
unset user_input