python svn pre-commit hook

E

evil tabby cat

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\check-comments.py %1 %2

if errorlevel 1 goto :ERROR

exit 0



:ERROR

echo Error found in commit 1>&2

exit 1



#check-comments.py
import sys, os, string, re

SVNLOOK='c:\\subversion\\bin\\svnlook.exe'

# 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.")
sys.exit(r)

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):
result(0)
else:
result(1)

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top