Add default git hooks
This is a set of global, reusable git hooks that can be added to any git project
This commit is contained in:
1
git/hooks/recent.post-checkout
Symbolic link
1
git/hooks/recent.post-checkout
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
recent.post-merge
|
||||||
8
git/hooks/recent.post-merge
Executable file
8
git/hooks/recent.post-merge
Executable file
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
|
echo -e "\033[1m RECENT COMMITS \033[0m"
|
||||||
|
git log -n5 --graph --pretty=format:'%Cred%h%Creset %an: %s - %Creset %C(yellow)%d%Creset %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
|
||||||
|
echo ""
|
||||||
|
echo ""
|
||||||
1
git/templates/hooks/post-checkout
Symbolic link
1
git/templates/hooks/post-checkout
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
./run-hooks.sh
|
||||||
1
git/templates/hooks/post-merge
Symbolic link
1
git/templates/hooks/post-merge
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
./run-hooks.sh
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
EXIT_CODE=0
|
|
||||||
|
|
||||||
repo=$( git rev-parse --show-toplevel )
|
|
||||||
HOOKS=~/.dotfiles/git/hooks
|
|
||||||
|
|
||||||
echo "Executing PRE-COMMIT hook(s)"
|
|
||||||
|
|
||||||
for hook in $HOOKS/*.pre-commit; do
|
|
||||||
echo ""
|
|
||||||
echo "${COLOR_LIGHTPURPLE}Executing ${hook}${COLOR_NONE}"
|
|
||||||
${hook}
|
|
||||||
EXIT_CODE=$((${EXIT_CODE} + $?))
|
|
||||||
done
|
|
||||||
|
|
||||||
if [[ ${EXIT_CODE} -ne 0 ]]; then
|
|
||||||
echo ""
|
|
||||||
echo "${COLOR_RED}Commit Failed.${COLOR_NONE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
exit $((${EXIT_CODE}))
|
|
||||||
1
git/templates/hooks/pre-commit
Symbolic link
1
git/templates/hooks/pre-commit
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
./run-hooks.sh
|
||||||
23
git/templates/hooks/run-hooks.sh
Executable file
23
git/templates/hooks/run-hooks.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
EXIT_CODE=0
|
||||||
|
|
||||||
|
repo=$( git rev-parse --show-toplevel )
|
||||||
|
hook_type=$( basename $0 )
|
||||||
|
hooks=~/.dotfiles/git/hooks
|
||||||
|
|
||||||
|
echo "Executing $hook_type hook(s)"
|
||||||
|
|
||||||
|
for hook in $hooks/*.$hook_type; do
|
||||||
|
echo ""
|
||||||
|
echo "${COLOR_LIGHTPURPLE}Executing ${hook}${COLOR_NONE}"
|
||||||
|
${hook}
|
||||||
|
EXIT_CODE=$((${EXIT_CODE} + $?))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ ${EXIT_CODE} -ne 0 ]]; then
|
||||||
|
echo ""
|
||||||
|
echo "${COLOR_RED}Commit Failed.${COLOR_NONE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $((${EXIT_CODE}))
|
||||||
Reference in New Issue
Block a user