Posted on July 24, 2008 in Python, Quality, subversion by adamNo Comments »

I’m going to be implementing the buddy system for changes to only part of our subversion repository. Essentially, anything in trunk needs to be buddied which resulted in needing to modify the buddy precommit script to something more robust than bash. This version will let developers work in their own private branch and be able to do lots of little commits without needing to have a buddy session but as soon as they try to merge into trunk they will need to be buddied.

#!/usr/bin/python
""" Make sure that the log message contains a buddy message """

import sys, os

REPOS = sys.argv[1]
TXN = sys.argv[2]
SVNLOOK = sys.argv[3]
care = "false"
found = "false"
projects = ["our_project_1", "our_project_2", "our_project_3", "our_project_4"]

log_stream = os.popen('%s dirs-changed -t "%s" "%s"' % (SVNLOOK, TXN, REPOS))
for line in log_stream.readlines():
    for project in projects:
        if line.lower().find("software_projects/%s/source/trunk" % project) != -1:
            care = "true"
            break
log_stream.close()

if care == "true":
    log_stream = os.popen('%s log -t "%s" "%s"' % (SVNLOOK, TXN, REPOS))
    for line in log_stream.readlines():
        if line.lower().startswith("buddy:"):
            found = "true"
            break
else:
    sys.exit(0)
log_stream.close()

if found == "true":
    sys.exit(0)
else:
    sys.exit("All commits need to have been buddied. Syntax:\nbuddy: buddy name")

It is certainly not an airtight policing solution and can be easily gamed, but it is not supposed to be. It is just a nice little nudge along the direction we want to be going in.