From: Bruce Korb Date: Thu, 11 Jul 2013 18:16:06 +0000 (-0700) Subject: LU-3568 contrib: ignore initial comments X-Git-Tag: 2.4.53~72 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=a9c1d872bdfc8a8b7ecd43b3d2081a183c7bda7e LU-3568 contrib: ignore initial comments Sometimes, git likes to insert "git status" commentary at the top of an auto-generated commit message starter file. If the committer carelessly neglects to remove the stuff, the script thinks the message has a missing commit summary line. * contrib/tests/test-commit-msg.sh: pass through xtrace setting * contrib/tests/commit.ok_commit: This message with cruft * contrib/commit-msg: use a flag instead of a line number to see if we still need to process the summary line. Signed-off-by: Bruce Korb Reviewed-by: Cheng Shao Xyratex-bug-id: MRP-1160 Change-Id: I46e2951f2e28cbbf53bf2e96e420ddcea7c0d991 Reviewed-on: http://review.whamcloud.com/6921 Tested-by: Hudson Tested-by: Maloo Reviewed-by: Andreas Dilger --- diff --git a/contrib/git-hooks/commit-msg b/contrib/git-hooks/commit-msg index caf694c..33a840d 100755 --- a/contrib/git-hooks/commit-msg +++ b/contrib/git-hooks/commit-msg @@ -42,6 +42,7 @@ init() { HAS_BODY=false HAS_SIGNOFF=false HAS_CHANGEID=false + NEEDS_FIRST_LINE=true IS_WRAPPING_UP=false @@ -111,7 +112,7 @@ function do_default_line() { error "invalid signoff section line" return } - if (( NUM == 1 )); then + if ${NEEDS_FIRST_LINE}; then HAS_JIRA_COMPONENT=$(echo "$LINE" | grep "$JIRA_FMT_A") if (( ${#HAS_JIRA_COMPONENT} == 0 )); then @@ -126,6 +127,7 @@ function do_default_line() { else HAS_SUMMARY=true fi + NEEDS_FIRST_LINE=false elif (( ${#LINE} > WIDTH_REG )); then error "has line longer than $WIDTH_REG columns." @@ -219,7 +221,11 @@ while IFS= read -u3 LINE; do "") HAS_LAST_BLANK=true - $IS_WRAPPING_UP && continue + + # Do not emit blank lines before summary line or after + # the tag lines have begun. + # + ${NEEDS_FIRST_LINE} || ${IS_WRAPPING_UP} && continue ;; \#*) @@ -251,12 +257,13 @@ while IFS= read -u3 LINE; do *) if [[ "$LINE" =~ ^($INNOCUOUS): ]]; then do_innocuous + elif [[ "$LINE" =~ ^[A-Za-z0-9_-]+-bug-id: ]]; then + # Allow arbitrary external bug identifiers for tracking. + # ck_wrapup + else - # Allow arbitrary external bug identifiers for tracking. - # I can't seem to find a pattern for the "case" that - # checks for "*-bug-id", so this is checked here. do_default_line fi ;; diff --git a/contrib/git-hooks/tests/commit.ok_comment b/contrib/git-hooks/tests/commit.ok_comment new file mode 100644 index 0000000..3c00bab --- /dev/null +++ b/contrib/git-hooks/tests/commit.ok_comment @@ -0,0 +1,28 @@ +# On branch master +# Your branch is ahead of 'origin/master' by 1 commit. +# +# Changes to be committed: +# (use "git reset HEAD ..." to unstage) +# +# modified: contrib/git-hooks/commit-msg +# new file: contrib/git-hooks/tests/commit.ok_comment +# modified: contrib/git-hooks/tests/test-commit-msg.sh + +LU-3568 contrib: ignore initial comments + +Sometimes, git likes to insert "git status" commentary +at the top of an auto-generated commit message starter +file. If the committer carelessly neglects to remove +the stuff, the script thinks the message has a missing +commit summary line. + +* contrib/tests/test-commit-msg.sh: pass through xtrace setting +* contrib/tests/commit.ok_commit: This message with cruft +* contrib/commit-msg: use a flag instead of a line number to see + if we still need to process the summary line. + +Signed-off-by: Bruce Korb +Reviewed-by: Cheng Shao +Xyratex-bug-id: MRP-1160 +Change-Id: I46e2951f2e28cbbf53bf2e96e420ddcea7c0d991 + diff --git a/contrib/git-hooks/tests/test-commit-msg.sh b/contrib/git-hooks/tests/test-commit-msg.sh index 2f1c565..fed31a7 100755 --- a/contrib/git-hooks/tests/test-commit-msg.sh +++ b/contrib/git-hooks/tests/test-commit-msg.sh @@ -4,43 +4,57 @@ program=$0 progdir=$(\cd $(dirname $0) >/dev/null && pwd) die() { - exec 1>&2 - echo "$program fatal error: $*" - exit 1 -} + echo "$program fatal error: $*" + exit 1 +} 1>&2 TEMPFILE=$(mktemp ${TMPDIR:-.}/commit-XXXXXX) test -f "$TEMPFILE" || die "mktemp fails" trap "rm -f $TEMPFILE COMMIT*" EXIT +# Pass through xtrace setting to commit-msg script +# +SHELL=${SHELL:-sh} +shopt -qo xtrace && SHELL+=' -x' + test $# -eq 0 && set -- ${progdir}/commit.* export FAIL="" readonly report_fmt='%-20s %s\n' for f; do - case "$f" in + case "$f" in ( *.orig | *.rej ) continue ;; - esac - - cp $f $TEMPFILE - results=$(exec 2>&1 ${SHELL:-sh} $progdir/../commit-msg $TEMPFILE) - case $'\n'"$results" in - ( *$'\nerror:'* ) OK=0 ;; - ( * ) OK=1 ;; - esac - - f=$(basename $f) - case $OK${f#*commit.} in - 1ok*) printf "$report_fmt" $f: "PASS (was allowed)" ;; - 0ok*) printf "$report_fmt" $f: "FAIL (not allowed)"; FAIL="$FAIL $f";; - 0*) printf "$report_fmt" $f: "PASS (found error)" ;; - *) printf "$report_fmt" $f: "FAIL (no error)" ; FAIL="$FAIL $f";; - esac + esac + + cp $f $TEMPFILE + results=$(exec 2>&1 ${SHELL} $progdir/../commit-msg $TEMPFILE) + case $'\n'"$results" in + ( *$'\nerror:'* ) OK=0 ;; + ( * ) OK=1 ;; + esac + + f=$(basename $f) + case $OK${f#*commit.} in + 1ok*) printf "$report_fmt" $f: "PASS (was allowed)" ;; + 0ok*) printf "$report_fmt" $f: "FAIL (not allowed)"; FAIL="$FAIL $f";; + 0*) printf "$report_fmt" $f: "PASS (found error)" ;; + *) printf "$report_fmt" $f: "FAIL (no error)" ; FAIL="$FAIL $f";; + esac done if [ -n "$FAIL" ]; then echo -e "\nerror: commit-msg test(s) failed!" 1>&2 - echo " $FAIL" + echo " $FAIL" fi rm -f $TEMPFILE $TEMPFILE.* + +## Local Variables: +## Mode: shell-script +## sh-basic-offset: 8 +## sh-indent-after-do: 8 +## sh-indentation: 8 +## sh-indent-for-case-label: 0 +## sh-indent-for-case-alt: 8 +## indent-tabs-mode: t +## End: