Whamcloud - gitweb
LU-1053 build: allow deleted/chmod in commit-msg
authorAndreas Dilger <adilger@whamcloud.com>
Sun, 29 Jan 2012 07:20:45 +0000 (00:20 -0700)
committerOleg Drokin <green@whamcloud.com>
Wed, 8 Feb 2012 19:38:31 +0000 (14:38 -0500)
Allow files that were deleted or chmod when verifying a commit
message that contains a diff generated with "commit -v".  The
checks added for excluding the diff were previously too strict.
Add a test case for each of these situations, as well as a case
for a commit message that contains "diff" at the start of a line
in the middle of a commit message.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Change-Id: I74fe98682342e445da7fe64fd42e91df4564500c
Reviewed-on: http://review.whamcloud.com/2053
Reviewed-by: Bruce Korb <bruce_korb@xyratex.com>
Reviewed-by: James Simmons <uja.ornl@gmail.com>
Tested-by: Hudson
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
build/commit-msg
build/commit.ok_chmod [new file with mode: 0644]
build/commit.ok_deleted [new file with mode: 0644]
build/commit.ok_diff [new file with mode: 0644]
build/test-commit-msg.sh

index 02d704d..4edbac8 100755 (executable)
@@ -41,7 +41,6 @@ init() {
         HAS_BODY=false
         HAS_SIGNOFF=false
         HAS_CHANGEID=false
-        HAS_DIFF=false
 
         IS_WRAPPING_UP=false
 
@@ -135,7 +134,6 @@ function do_default_line() {
                 HAS_BODY=true
         fi
         HAS_LAST_BLANK=false
-        HAS_DIFF=false
 }
 
 # Add a new unique Change-Id
@@ -197,8 +195,10 @@ usage() {
        commit/submission.  Copy the one from the original commit.
 
        The "sign off section" may also include several other tag lines:
-       $(for T in $(tr '|' ' ' <<< "$INNOCUOUS"); do echo "  $T: <email>"; done
-       {Organization}-bug-id: associated ticket identifier
+       $(for T in $(tr '|' ' ' <<< "$INNOCUOUS"); do       \
+            echo "    $T: Some Person <email@domain.com>"; \
+         done)
+       {Organization}-bug-id: associated external change identifier
        EOF
 
         mv "$ORIGINAL" "$SAVE" &&
@@ -228,13 +228,18 @@ while IFS= read -u3 LINE; do
                 # there are diff and index lines, skip the rest of the input:
                 #   diff --git a/build/commit-msg b/build/commit-msg
                 #   index 80a3442..acb4c50 100755
-                # If a "diff --git" line is not followed by an index line,
-                # do the default line processing on both lines.
+                #   deleted file mode 100644
+                #   old mode 100644
+                # If a "diff --git" line is not followed by one of these
+                # lines, do the default line processing on both lines.
                 #
                 IFS= read -u3 INDEX || break
                 ((NUM += 1))
-                ln=$(echo "$INDEX" | grep "^index [0-9a-fA-F]\{6,\}\.\.")
-                (( ${#ln} > 1 )) && break
+                case "$INDEX" in
+                "index "[0-9a-fA-F]*) break ;;
+                "deleted file mode "*) break  ;;
+                "old mode "*) break ;;
+                esac
                 LINE=${LINE}$'\n'${INDEX}
                 do_default_line
                 ;;
@@ -242,12 +247,12 @@ while IFS= read -u3 LINE; do
         *)
                 if [[ "$LINE" =~ ^($INNOCUOUS): ]]; then
                         do_innocuous
-               elif [[ "$LINE" =~ ^[A-Za-z0-9_-]+-bug-id: ]]; then
-                       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.
+                elif [[ "$LINE" =~ ^[A-Za-z0-9_-]+-bug-id: ]]; then
+                        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/build/commit.ok_chmod b/build/commit.ok_chmod
new file mode 100644 (file)
index 0000000..46d0609
--- /dev/null
@@ -0,0 +1,15 @@
+LU-1030 build: allow diff/chmod/deleted in commit-msg
+
+message
+body
+
+Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
+Change-Id: I012345678901234567890123456789012345500c
+
+diff --git a/build/commit-msg b/build/commit-msg
+old mode 100755
+new mode 100644
+
+# total: 0 errors, 0 warnings, 36 lines checked
+#
+# Your patch has no obvious style problems and is ready for submission.
diff --git a/build/commit.ok_deleted b/build/commit.ok_deleted
new file mode 100644 (file)
index 0000000..b4e464b
--- /dev/null
@@ -0,0 +1,14 @@
+LU-1030 build: allow diff/chmod/deleted in commit-msg
+
+message
+body
+
+Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
+Change-Id: I012345678901234567890123456789012345500c
+
+diff --git a/build/commit-msg b/build/commit-msg
+deleted file mode 100755
+
+# total: 0 errors, 0 warnings, 36 lines checked
+#
+# Your patch has no obvious style problems and is ready for submission.
diff --git a/build/commit.ok_diff b/build/commit.ok_diff
new file mode 100644 (file)
index 0000000..09b8fde
--- /dev/null
@@ -0,0 +1,16 @@
+LU-1030 build: allow diff/chmod/deleted in commit-msg
+
+message
+body
+
+Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
+Change-Id: I012345678901234567890123456789012345500c
+
+diff --git a/build/commit-msg b/build/commit-msg
+index 02d704d..48323d1 100755
+--- a/build/commit-msg
++++ b/build/commit-msg
+
+# total: 0 errors, 0 warnings, 36 lines checked
+#
+# Your patch has no obvious style problems and is ready for submission.
index 899f366..facd9f3 100755 (executable)
@@ -15,15 +15,15 @@ trap "rm -f $TEMPFILE COMMIT*" EXIT
 
 test $# -eq 0 && set -- ${progdir}/commit.*
 
+export FAIL=""
 readonly report_fmt='%-20s %s\n'
-for f
-do
+for f; do
         case "$f" in
-        ( *.orig | *.rej ) continue ;;
+       ( *.orig | *.rej ) continue ;;
         esac
+
         cp $f $TEMPFILE
-        results=$(exec 2>&1
-                ${SHELL:-sh} $progdir/commit-msg $TEMPFILE)
+        results=$(exec 2>&1 ${SHELL:-sh} $progdir/commit-msg $TEMPFILE)
         case $'\n'"$results" in
         ( *$'\nerror:'* ) OK=0 ;;
         ( * ) OK=1 ;;
@@ -32,10 +32,15 @@ do
         f=$(basename $f)
         case $OK${f#*commit.} in
         1ok*)   printf "$report_fmt" $f: "PASS (was allowed)" ;;
-        0ok*)   printf "$report_fmt" $f: "FAIL (not 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)"    ;;
+        *)      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"
+fi
+
 rm -f $TEMPFILE $TEMPFILE.*