#!/usr/bin/python3 """ Subversion pre-commit hook which currently checks that the card-index information is consistent and correctly given. """ #Author: Alain Hebert, Ecole Polytechnique, 2006. import os, sys, pysvn def main(repos, txn): # Recover the transaction data: print("pre-commit: repos=",repos) t = pysvn.Transaction( repos, txn ) all_props = t.revproplist() message = t.revproplist()['svn:log'] # # Validate the commit message: if message[:5] != 'issue': sys.stderr.write ("Please begin your commit message with 'issue' characters. message=%s...\n"% \ message[:15]) sys.exit(1) try: cardIndexNumber = int(message[5:11]) except: sys.stderr.write ("Please begin your commit message with 'issue' characters followed" \ +" by a six-digit index. message=%s...\n"%message[:15]) sys.exit(1) fileName = message[:11] # # List of card-index client = pysvn.Client() myls = client.ls('file://'+repos+'/'+'/issues/') maxIssue = -1 for k in range(len(myls)): maxIssue=max(maxIssue, int(myls[k]['name'].split('/')[-1][5:])) if int(fileName[5:]) > maxIssue+1: sys.stderr.write ("The six-digit index (%d) must be <= %d. message=%s...\n"% \ (int(fileName[5:]), maxIssue+1, message[:15])) sys.exit(1) sys.exit(0) 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])