From 32e2d1f363a1d96f683b39867c96aa722ba0f494 Mon Sep 17 00:00:00 2001 From: Nick Nisi Date: Sat, 27 Jul 2013 10:58:35 -0500 Subject: [PATCH] Add default git hooks This is a set of global, reusable git hooks that can be added to any git project --- git/hooks/recent.post-checkout | 1 + git/hooks/recent.post-merge | 8 ++++++++ git/templates/hooks/post-checkout | 1 + git/templates/hooks/post-merge | 1 + git/templates/hooks/pre-commit | 23 +---------------------- git/templates/hooks/run-hooks.sh | 23 +++++++++++++++++++++++ 6 files changed, 35 insertions(+), 22 deletions(-) create mode 120000 git/hooks/recent.post-checkout create mode 100755 git/hooks/recent.post-merge create mode 120000 git/templates/hooks/post-checkout create mode 120000 git/templates/hooks/post-merge mode change 100755 => 120000 git/templates/hooks/pre-commit create mode 100755 git/templates/hooks/run-hooks.sh diff --git a/git/hooks/recent.post-checkout b/git/hooks/recent.post-checkout new file mode 120000 index 0000000..3e9bd2c --- /dev/null +++ b/git/hooks/recent.post-checkout @@ -0,0 +1 @@ +recent.post-merge \ No newline at end of file diff --git a/git/hooks/recent.post-merge b/git/hooks/recent.post-merge new file mode 100755 index 0000000..5901f0e --- /dev/null +++ b/git/hooks/recent.post-merge @@ -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 "" diff --git a/git/templates/hooks/post-checkout b/git/templates/hooks/post-checkout new file mode 120000 index 0000000..975266c --- /dev/null +++ b/git/templates/hooks/post-checkout @@ -0,0 +1 @@ +./run-hooks.sh \ No newline at end of file diff --git a/git/templates/hooks/post-merge b/git/templates/hooks/post-merge new file mode 120000 index 0000000..975266c --- /dev/null +++ b/git/templates/hooks/post-merge @@ -0,0 +1 @@ +./run-hooks.sh \ No newline at end of file diff --git a/git/templates/hooks/pre-commit b/git/templates/hooks/pre-commit deleted file mode 100755 index 80fb830..0000000 --- a/git/templates/hooks/pre-commit +++ /dev/null @@ -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})) diff --git a/git/templates/hooks/pre-commit b/git/templates/hooks/pre-commit new file mode 120000 index 0000000..975266c --- /dev/null +++ b/git/templates/hooks/pre-commit @@ -0,0 +1 @@ +./run-hooks.sh \ No newline at end of file diff --git a/git/templates/hooks/run-hooks.sh b/git/templates/hooks/run-hooks.sh new file mode 100755 index 0000000..30f6615 --- /dev/null +++ b/git/templates/hooks/run-hooks.sh @@ -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}))