lmi
[Top][All Lists]
Advanced

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

[lmi] Detecting a non-empty second line in commit-msg hook


From: Greg Chicares
Subject: [lmi] Detecting a non-empty second line in commit-msg hook
Date: Sat, 10 Dec 2016 00:22:08 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.4.0

I've committed a new hooks/commit-msg that seems to work well, e.g.:

/opt/lmi/src/lmi[0]$git commit --all -m'Fix defect introduced 20161108T2203Z: 
duplicated comment.' 
checking...okay
checking commit message...
Do not end first line with period
COMMIT ABORTED
/opt/lmi/src/lmi[1]$

except that it doesn't seem to diagnose a non-empty second line if
that line consists entirely of blank spaces. Does git automatically
remove whitespace in that context?

The hook's sed script works correctly when tested in isolation:

/opt/lmi/src/lmi[0]$cat >eraseme <<EOF
heredoc> This line is okay
heredoc>    
heredoc> This line is okay too.
heredoc> EOF
/opt/lmi/src/lmi[0]$od -t a eraseme 
0000000   T   h   i   s  sp   l   i   n   e  sp   i   s  sp   o   k   a
0000020   y  nl  sp  sp  sp  nl   T   h   i   s  sp   l   i   n   e  sp
0000040   i   s  sp   o   k   a   y  sp   t   o   o   .  nl
0000055
/opt/lmi/src/lmi[0]$sed -n -e '2{/^$/!{s/\(^.*$\)/Second line "\1" not 
empty./p}}' eraseme 
Second line "   " not empty.

However, with this experimental change:

----------8<----------8<----------8<----------8<----------
/opt/lmi/src/lmi[0]$git diff
diff --git a/hooks/commit-msg b/hooks/commit-msg
index 324e199..3e2405e 100755
--- a/hooks/commit-msg
+++ b/hooks/commit-msg
@@ -33,6 +33,8 @@ printf "checking commit message..."
 
 z=$(sed -n -e "$sed_script" "$1")
 
+cp "$1" msg
+
 if [ -n "$z" ]; then
     printf '\n%b\n' "$z"
     printf "COMMIT ABORTED\n"
----------8<----------8<----------8<----------8<----------

if I try the following, typing several spaces on the second line:

/opt/lmi/src/lmi[0]$git commit --all -m'Bogus period at end.
quote>    
quote> This line is okay.'
checking...okay
checking commit message...
Do not end first line with period
COMMIT ABORTED

I expect the output to include
  Second line "   " not empty.
but it does not.

However, a non-empty second line is properly diagnosed as long as it
contains a non-whitespace character:

/opt/lmi/src/lmi[1]$rm msg
/opt/lmi/src/lmi[0]$git commit --all -m'Bogus period at end.
   x
This line is okay.'
checking...okay
checking commit message...
Do not end first line with period
Second line "   x" not empty.
COMMIT ABORTED

Is git silently removing trailing blanks from commit messages?



reply via email to

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