Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all:</p> <ul> <li>Only messages to STDERR are printed and only if the exit of the pre-commit script is something other than zero. Otherwise, there's no print out at all.</li> <li>Commit messages are for the entire commit. That means you don't check the commit message of every single file. It's the same for them all.</li> <li>You can find the commit message by looking at the revision property <code>svn:log</code>. You don't have to look at the message.</li> </ul> <p>Try this completely untested rewrite:</p> <pre><code>#!/bin/bash REPOS="$1" TXN="$2" SVNLOOK="/usr/bin/svnlook" AWK="/usr/bin/awk" GREP="/bin/egrep" SED="/bin/sed" if "$SVNLOOK" changed -t $TXN | grep -q "^ *[UAM].*\.cpp$" then MESSAGE=$("$SVNLOOK" pget -t $TXN --revprop "$REPOS" svn:log) if [ -z ${MESSAGE:16} ] then echo "Committing a *.cpp file, but didn't put a comment!" &gt;&amp;2 exit 1 #CPP, but message too short else exit 0 #CPP Files but message is long enough fi exit 0 #No CPP files </code></pre> <p>Here are some of the changes:</p> <p>You had this:</p> <pre><code>CHANGED=`$SVNLOOK changed -t "$TXN" "$REPOS" | $GREP "^[U|A|M]" | $AWK '{print $2}' | $GREP \\.cpp$` </code></pre> <p>You push it through a grep, through an awk, and then through another grep. Instead, why not do the entire line at once?</p> <pre><code>"$SVNLOOK" changed -t $TXN "$REPOS" | $GREP -q "^ *[UAM].*\.cpp$" </code></pre> <ul> <li>The <code>[UAM]</code> means either a <code>U</code> or a <code>M</code> or a <code>A</code>. You don't need the <code>|</code> between each. </li> <li>The <code>$GREP -q</code> means do the grep quietly. If you found something, it returns a 0, otherwise, it returns a 1. You can put this directly into your <code>if</code> statement without the <code>[...]</code> testing braces.</li> <li>The <code>.*\.cpp$</code> means I'm looking at the rest of the line and seeing if it ends with <code>.\.cpp</code> No need for the <code>grep|awk|grep</code> pipe.</li> <li>There's only a single log message, so all I have to do is check it once. No need for a loop.</li> <li>Notice I use the <code>$(...)</code> instead of back ticks. It does the same thing, but is easier to see.</li> <li>I use <code>${MESSAGE:16}</code>. In BASH, this does a 16 character offset of my message. If my message is shorter than 16 characters, then <code>${MESSAGE:16}</code> is blank. I can then use <code>-z</code> to see if the offset string is empty or not. Saves you the pipe to sed, then grep.</li> </ul> <p>See if this works a bit better. In fact, run this as a regular shell script outside the hook. You can change the <code>-t</code> to a <code>-r</code> and put in various revision numbers. This way, you can verify the script first before trying it as a hook. Then, make sure this is called <code>pre-commit</code> and that you have the permissions set to <code>rwxr-xr-x</code>.</p> <p>Even better, try my <a href="https://github.com/qazwart/SVN-Precommit-Kitchen-Sink-Hook" rel="nofollow">pre-commit hook</a>. It's battle tested, and can do more. It's a Perl script, but it should run in any Perl version greater than 5.8, and you probably already have Perl on your system. You can check the svn:log for length, but my hook script doesn't allow you to specify it based upon what is committed. However, why should you allow any blank commit message anyway -- whether or not a <code>*.cpp</code> file was committed?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload