This repository has been archived by the owner on Jun 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpre-commit.py
75 lines (60 loc) · 1.56 KB
/
pre-commit.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/python
import sys
from sets import Set
from svnlook import SvnLook
import assets
InvalidFiles = Set(["Thumbs.db"])
def EnforceMetadata(changes):
ret = True
files = Set()
metas = Set()
for change in changes:
change = assets.RemoveTrailingSlash(change)
if assets.IsAsset(change):
if assets.IsMetaData(change):
metas.add(change)
else:
files.add(change)
for file in files:
metaName = assets.GetMetaDataName(file)
if (not metaName in metas):
print "Change for " + file + " commited but .meta missing!"
ret = False
else:
metas.remove(metaName)
for meta in metas:
ret = False
print "Change for " + meta + " commited but file missing!"
return ret
def ValidateFiles(changes):
ret = True
for change in changes:
slashIdx = change.rfind("/")
if slashIdx >= 0:
fileName = change[slashIdx + 1:]
if fileName in InvalidFiles:
print fileName + " is not allowed, don't commit it!"
ret = False
return ret
def main(repo, txn):
ret = True
svnlook = SvnLook(repo, txn)
if not svnlook.CheckBypass():
added = svnlook.GetChanges(SvnLook.AddMarker)
if not EnforceMetadata(added):
ret = False
if not ValidateFiles(added):
ret = False
deleted = svnlook.GetChanges(SvnLook.DeleteMarker)
if not EnforceMetadata(deleted):
ret = False
if not ret:
print "If you believe these are not real errors, add \"bypass-hook\" to the commit message."
return 1
return 0
if __name__ == "__main__":
sys.stdout = sys.stderr
if len(sys.argv) != 3:
print "invalid args"
sys.exit(1)
sys.exit(main(sys.argv[1], sys.argv[2]))