python svn pre-commit hook

evil tabby cat eviltabbycat at
Mon Jul 2 15:12:07 CEST 2007

This is a python script which is fired off from a batchfile pre-
commit.bat on Windows2000 server.

Everything I've read says that it should work & each part does work
when tested individually.

But when it runs within subversion this statement always ends with
this log_msg being an empty string.
log_msg = os.popen(log_cmd, 'r').readline().rstrip('\n')

Help. :-)

rem pre-commit.bat
c:\python23\python c:\repository\hooks\ %1 %2

if errorlevel 1 goto :ERROR

exit 0


echo Error found in commit 1>&2

exit 1
import sys, os, string, re


# return true or false if this passed string is a valid comment
def check(comment):
    #define regular expression
    p = re.compile('\A[iI][sS][sS][uU][eE] \d+ - \w+')
    return (p.match(comment) != None) #returns false if doesn't match

def result(r):
   if r == 1:
      sys.stderr.write ("Comments must have the format of 'Issue X -
Comment text' where X is the issue number.")

def main(repos, txn):
    log_cmd = '%s log -t "%s" "%s"' % (SVNLOOK, txn, repos)
    log_msg = os.popen(log_cmd, 'r').readline().rstrip('\n')

    if check(log_msg):

if __name__ == '__main__':
    if len(sys.argv) < 3:
        sys.stderr.write("Usage: %s REPOS TXN\n" % (sys.argv[0]))
        main(sys.argv[1], sys.argv[2])

More information about the Python-list mailing list