diff --git a/Utilities/Hooks/commit-msg b/Utilities/Hooks/commit-msg deleted file mode 100755 index a215bf8718a..00000000000 --- a/Utilities/Hooks/commit-msg +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -#========================================================================== -# -# Copyright NumFOCUS -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# https://www.apache.org/licenses/LICENSE-2.0.txt -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# -#==========================================================================*/ - -egrep-q() { - egrep "$@" >/dev/null 2>/dev/null -} - -# Prepare a copy of the message: -# - strip comment lines -# - stop at "diff --git" (git commit -v) -commit_msg="$GIT_DIR/COMMIT_MSG" -sed -n -e '/^#/d' -e '/^diff --git/q' -e 'p;d' "$1" > "$commit_msg" - -die() { - echo 'commit-msg hook failure' 1>&2 - echo '-----------------------' 1>&2 - echo '' 1>&2 - echo "$@" 1>&2 - echo ' -To continue editing, run the command - git commit -e -F '"$commit_msg"' -(assuming your working directory is at the top).' 1>&2 - exit 1 -} - -# Check the first line for a standard prefix. -cat "$commit_msg" | -while IFS='' read line; do - # Look for the first non-empty line. - len=$(echo -n "$line" | wc -c) - if test $len -gt 0; then - # Look for valid prefixes. - echo "$line" | - egrep-q '^(Merge|Revert|BUG:|COMP:|DOC:|ENH:|PERF:|STYLE:|WIP:) ' || - die 'Start ITK commit messages with a standard prefix (and a space): - BUG: - fix for runtime crash or incorrect result - COMP: - compiler error or warning fix - DOC: - documentation change - ENH: - new functionality - PERF: - performance improvement - STYLE: - no logic impact (indentation, comments) - WIP: - Work In Progress not ready for merge -To reference GitHub issue XXXX, add "Issue #XXXX" to the commit message. -If the issue addresses an open issue, add "Closes #XXXX" to the message.' - - # Reject bug number reference that CDash rejects. - echo "$line" | - egrep-q '^BUG: [0-9][0-9]*\.' && - die 'Do not put a "." after the bug number: - - '"$line" - - # Done. Skip rest of lines. - break - fi -done && -rm -f "$commit_msg" || exit 1 diff --git a/Utilities/Hooks/kw-commit-msg b/Utilities/Hooks/kw-commit-msg index b1c6b9aec62..723763d35f5 100755 --- a/Utilities/Hooks/kw-commit-msg +++ b/Utilities/Hooks/kw-commit-msg @@ -15,6 +15,12 @@ # limitations under the License. #============================================================================= +# Ensure that the first arguement is a valid file for processing +if [ ! -f "$1" ]; then + echo "Missing input commit message file for the kw-commit-msg processing" + exit 1 +fi + # Prepare a copy of the message: # - strip comment lines # - stop at "diff --git" (git commit -v) @@ -29,8 +35,8 @@ To continue editing, run the command die() { echo 'commit-msg hook failure' 1>&2 echo '-----------------------' 1>&2 - echo '' 1>&2 echo "$@" 1>&2 + echo '-----------------------' 1>&2 test -n "$die_advice" && echo "$die_advice" 1>&2 exit 1 } @@ -48,7 +54,10 @@ msg_is_revert() { msg_first() { len=$(echo -n "$line" | wc -c) - max_len=$(hooks_config --get hooks.commit-msg.maxLength || echo 78) && + # Use one of the following git commands to set the enforced subject maximum length. + # git config --global hooks.commit-msg.ITKCommitSubjectMaxLength 78 + # git config --local hooks.commit-msg.ITKCommitSubjectMaxLength 78 + max_len=$(git config --get hooks.commit-msg.ITKCommitSubjectMaxLength || echo 78) && if test $len -eq 0; then # not yet first line return @@ -65,6 +74,26 @@ msg_first() { elif echo "$line" | grep "^[ ]\|[ ]$" >/dev/null 2>&1; then die 'The first line may not have leading or trailing space: ['"$line"']' + + # Look for valid prefixes. + elif ! echo "$line" | egrep -q '^(Merge|Revert|BUG:|COMP:|DOC:|ENH:|PERF:|STYLE:|WIP:) ' > /dev/null 2>&1; then + die 'Start ITK commit messages with a standard prefix (and a space): + BUG: - fix for runtime crash or incorrect result + COMP: - compiler error or warning fix + DOC: - documentation change + ENH: - new functionality + PERF: - performance improvement + STYLE: - no logic impact (indentation, comments) + WIP: - Work In Progress not ready for merge +To reference GitHub issue XXXX, add "Issue #XXXX" to the commit message. +If the issue addresses an open issue, add "Closes #XXXX" to the message.' + + # Reject bug number reference that CDash rejects. + elif echo "$line" | egrep -q '^BUG: [0-9][0-9]*\.'> /dev/null 2>&1; then + die 'Do not put a "." after the bug number: + + '"$line" + else # first line okay state=second @@ -74,8 +103,14 @@ msg_first() { msg_second() { if test "x$line" != "x"; then die 'The second line must be empty: -'"$line" +'"\"$line\"" fi + state=third +} + +msg_third() { + #Do nothing for 3rd -> Nth line + state=third } # Pipe commit message into the state machine. @@ -84,5 +119,5 @@ cat "$commit_msg" | while IFS='' read line; do msg_$state || break done && -rm -f "$commit_msg" || exit 1 +#rm -f "$commit_msg" || exit 1 die_advice='' # No more temporary message file.