From 6168c78bed1e3452c88aebbacc05cc8ce2f0f937 Mon Sep 17 00:00:00 2001 From: Janek Schleicher Date: Sun, 3 Mar 2019 12:37:32 +0100 Subject: [PATCH] Add some magit integration The non-interactive detection does not work when called from emacs magit. Also we'd like to force git-good-commit to commit a message, like when doing interactive. So added logic to detect whether we are inside emacs and that looks in the comment section of the commit message if there is somewhere a # gcc: y defined as comment and if, then it commits anyway. Otherwise it exits with an error message and also explaining what to do in case of forcing the commit. --- hook.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hook.sh b/hook.sh index f29b7c5..c94380c 100755 --- a/hook.sh +++ b/hook.sh @@ -115,6 +115,12 @@ read_commit_message() { [[ $REPLY == "# ------------------------ >8 ------------------------" ]] test $? -eq 1 || break + # look for an explicit + # gcc: y + # flag in the comment section of COMMIT_MSG + [[ $REPLY =~ ^#[[:blank:]]*ggc:[[:blank:]]*y ]] + test $? -eq 0 && GGC_YES=1 + # ignore comments [[ $REPLY =~ ^# ]] test $? -eq 0 || COMMIT_MSG_LINES+=("$REPLY") @@ -283,6 +289,9 @@ while true; do read_commit_message + # If there is a comment explicitly forcing ggc to commit + test $GGC_YES -eq 1 && exit 0; + validate_commit_message # if there are no WARNINGS are empty then we're good to break out of here @@ -290,6 +299,13 @@ while true; do display_warnings + if [[ -n $INSIDE_EMACS ]]; then + echo "Change the commit-msg or write" + echo "# ggc: y" + echo "in the comment area of the message to force this commit" + exit 1 # if not interactive terminal, exit with error message + fi + # if non-interactive don't prompt and exit with an error if [ ! -t 1 ] && [ -z ${FAKE_TTY+x} ]; then exit 1