1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
#!/usr/bin/env bash
#==========================================================================
#
# Copyright Insight Software Consortium
#
# 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
#
# http://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 JIRA issue XXXX, add " (#ITK-XXXX)" to the END of the FIRST line.'
# 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
|