bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#19337: [PATCH] Improve git hook checking commit message.


From: Michal Nazarewicz
Subject: bug#19337: [PATCH] Improve git hook checking commit message.
Date: Wed, 10 Dec 2014 18:24:09 +0100

From: Michal Nazarewicz <mina86@mina86.com>

* build-aux/git-hooks/commit-msg: Do not validate commit message if it
starts with “fixup!” or “squash!”.  Those are special markers used by
git when doing auto squashing and as a result the commit message will
not be used in the final commit.

* build-aux/git-hooks/commit-msg: Make the massages somehow more
ambiguous by mentioning that they error has been found in the commit
message.  Otherwise, user may be left wondering what the error is
referring to.
---
 build-aux/git-hooks/commit-msg | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/build-aux/git-hooks/commit-msg b/build-aux/git-hooks/commit-msg
index 6a09edd..f3b05db 100755
--- a/build-aux/git-hooks/commit-msg
+++ b/build-aux/git-hooks/commit-msg
@@ -42,7 +42,7 @@ exec awk '
   /^#/ { next }
 
   !/^.*$/ {
-    print "Invalid character (not UTF-8)"
+    print "Commit message contains invalid character (not UTF-8)"
     status = 1
   }
 
@@ -51,38 +51,47 @@ exec awk '
   { nlines++ }
 
   nlines == 1 && /^[[:space:]]/ {
-    print "White space at start of first line"
+    print "Commit message contains white space at start of first line"
     status = 1
   }
 
+  nlines == 1 && /^(fixup|squash)! / {
+    exit status
+  }
+
   nlines == 2 && /[^[:space:]]/ {
-    print "Nonempty second line"
+    print "Commit message must have an empty second line"
+    status = 1
+  }
+
+  /\t/ {
+    print "Use use spaces instead of tabs in commit message"
     status = 1
   }
 
   /[[:cntrl:]]/ {
-    print "Text contains control character; please use spaces instead of tabs"
+    print "Commit message contains control character"
     status = 1
   }
 
   72 < length && /[[:space:]]/ {
-    print "Line longer than 72 characters"
+    print "Commit message contains line longer than 72 characters"
     status = 1
   }
 
   140 < length {
-    print "Word longer than 140 characters"
+    print "Commit message contains word longer than 140 characters"
     status = 1
   }
 
   /^Signed-off-by: / {
-    print "'Signed-off-by:' present"
+    print "'Signed-off-by:' present in the commit message"
     status = 1
   }
 
   END {
     if (nlines == 0) {
-      print "Empty change log entry"
+      print "Empty commit message"
       status = 1
     }
     exit status
-- 
2.2.0.rc0.207.ga3a616c






reply via email to

[Prev in Thread] Current Thread [Next in Thread]