-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit
executable file
·70 lines (48 loc) · 1.79 KB
/
commit
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
#!/usr/bin/env python3
'''
This script is not used by Subsyncit itself.
It is used when I check in Subsyncit so that there's a version number in the
source file. This is relevant as Python is a language that leaps into being
based on source files (unlike Java an its .class files), and I wanted to
have a version number in there just in case I'm supporting something.
'''
import hashlib
from datetime import datetime
import sh
import sys
import subprocess
x = sys.argv
changeset = sh.git("status")
changes_to_be_committed = False
changes_not_staged_for_commit = False
subsyncit_modified = False
for line in changeset.splitlines():
if line == "Changes not staged for commit:":
changes_not_staged_for_commit = True
if "modified: subsyncit.py" in line:
if changes_not_staged_for_commit and sys.argv[1] != "-am":
print("subsyncit.py modified, but you need to git-add it. Not committing")
exit(1)
subsyncit_modified = True
print ("subsyncit_modified " + str(subsyncit_modified))
if subsyncit_modified:
with open("subsyncit.py", 'r') as f:
get_all = f.readlines()
for_sha = ""
for line in get_all:
if "# Version" not in line:
for_sha += line + "\n"
hash = hashlib.sha1(for_sha.encode('utf-8')).hexdigest()
print("hash: " + hash)
with open("subsyncit.py", 'r') as f:
get_all = f.readlines()
newlines = []
for i, line in enumerate(get_all):
if line.startswith("# Version: "):
newlines.append("# Version: " + str(datetime.today().strftime('%Y.%m.%d.')) + hash + "\n")
else:
newlines.append(line)
with open("subsyncit.py", 'w') as f:
f.writelines(newlines)
sh.git("add", "subsyncit.py")
subprocess.call(["git", "commit"] + sys.argv[1:])