blob: 2d9e8b9ddc959f4e477a988e68ebd1c239f8e3ba (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#!/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])
|