-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-add-and-commit.py
executable file
·57 lines (46 loc) · 1.3 KB
/
git-add-and-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
#!/usr/bin/env python3
import subprocess
import datetime
import os
import sys
def repo_home():
p = subprocess.Popen(['git', 'rev-parse', '--show-toplevel'], stdout=subprocess.PIPE)
p.wait()
return p.stdout.read().decode().strip()
def get_uncommit_changes():
p = subprocess.Popen(['git', 'status', '--porcelain'], stdout=subprocess.PIPE)
p.wait()
return p.stdout.read().decode().strip()
def update_version():
version_template = '''
return {{
version = function()
return "{}.{:02d}.{:02d}"
end,
}}
'''
now = datetime.datetime.now()
version_str = version_template.format(now.year, now.month, now.day)
with open(os.path.join(repo_home(), 'lua/dotvim/version.lua'), 'w') as fp:
fp.write(version_str)
if len(sys.argv) <= 1:
print('Require commit message!')
exit(1)
update_version()
uncommit_changes = get_uncommit_changes().splitlines()
if not uncommit_changes:
print('Working tree is clean...')
else:
now = datetime.datetime.now()
print(' Today: {}.{}.{}'.format(now.year, now.month, now.day))
print(' Changes:')
for c in uncommit_changes:
print(c)
continue_ask = input('Continue? [y/N] ')
if continue_ask != 'y':
print('Abort')
exit(1)
else:
subprocess.run(['git', 'add', '--all'])
subprocess.run(['git', 'commit', '-m', sys.argv[1]])
# vim: sw=2 ts=2