From 227c9d884b669ce80b7ac2271a8e52361cb30859 Mon Sep 17 00:00:00 2001 From: Vahagn Khachatryan Date: Mon, 22 Jun 2020 10:22:34 -0400 Subject: [PATCH] Got golden hooks. --- config/.gitconfig | 5 +++- git/hooks/commit-msg | 42 ++++++++++++++++++++++++++++++++++ git/hooks/prepare-commit-msg | 44 ++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100755 git/hooks/commit-msg create mode 100755 git/hooks/prepare-commit-msg diff --git a/config/.gitconfig b/config/.gitconfig index 219816c..05d245b 100644 --- a/config/.gitconfig +++ b/config/.gitconfig @@ -13,7 +13,10 @@ br = branch co = checkout ci = commit - svnsync = "!f(){ git co master && git pull && ssh devgit svnsync $(git config --get remote.origin.url | cut -d : -f 2 );}; f" + upload = "!f(){ git push $@ origin $(git rev-parse --abbrev-ref HEAD); }; f" + faxm = "!f(){ git fetch upstream master && git checkout -b ENG1FAXM-$1 upstream/master; }; f" + drqs = "!f(){ git fetch upstream master && git checkout -b DRQS-$1 upstream/master; }; f" + install-hooks = "!f(){ GIT_HOOKS=\"$(git rev-parse --git-dir)/hooks/\"; GOLDEN_HOOKS=\"$HOME/devel/scripts/git/hooks\"; [ -d \"$GIT_HOOKS\" ] && [ -d \"$GOLDEN_HOOKS\" ] && cp -r \"$GOLDEN_HOOKS/.\" \"$GIT_HOOKS\"; }; f" [merge] tool = vimdiff conflictstyle = diff3 diff --git a/git/hooks/commit-msg b/git/hooks/commit-msg new file mode 100755 index 0000000..28e5f1f --- /dev/null +++ b/git/hooks/commit-msg @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +#test "" = "$(grep '^Signed-off-by: ' "$1" | +# sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { +# echo >&2 Duplicate Signed-off-by lines. +# exit 1 +#} + +# +# SPELL CHECK +# +# 1. Install hunspell +# 2. Download a dictionary +# $ open http://wiki.services.openoffice.org/wiki/Dictionaries +# 3. Move this file into your repository +# $ mv commit-msg /path/to/repo/.git/hooks +# $ chmod +x /path/to/repo/.git/hooks/commit-msg +# +CHECK=$(cat $1 | hunspell -d en_US -l) +if [ "${CHECK}" != "" ]; then + echo "Spell Check Error: ${CHECK}" + echo "Message: $(cat $1)" + exit 1 +fi + diff --git a/git/hooks/prepare-commit-msg b/git/hooks/prepare-commit-msg new file mode 100755 index 0000000..ea60dfb --- /dev/null +++ b/git/hooks/prepare-commit-msg @@ -0,0 +1,44 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# +# Extract ticket id from the branch name and Append to commit message. +# Pattern NAME-NUMBER. e.g. ERROR-234 +# +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +MESSAGE=$(cat $COMMIT_MSG_FILE) +TICKET=$(git rev-parse --abbrev-ref HEAD | grep -Eo '^(\w+/)?(\w+[-_])[0-9]+' | grep -Eo '(\w+[-])[0-9]+' | tr "[:lower:]" "[:upper:]"): + +if [[ $TICKET == ":" || "$MESSAGE" == "$TICKET"* ]];then + exit 0; +fi + +echo "$TICKET $MESSAGE" > $COMMIT_MSG_FILE + +#/opt/bb/bin/perl5.16 -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /opt/bb/bin/perl5.16 -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /opt/bb/bin/perl5.16 -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi