-
Notifications
You must be signed in to change notification settings - Fork 75
/
git-push-status.py
executable file
·51 lines (41 loc) · 1.33 KB
/
git-push-status.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
#!/usr/bin/python3
import subprocess
""" more then likely git can do this itself, I don't know how though """
branch = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], encoding='utf8').strip()
removed_log = subprocess.check_output(["git", "log", "--oneline", branch + "..origin/" + branch], encoding='utf8').strip()
added_log = subprocess.check_output(["git", "log", "--oneline", "origin/" + branch + ".." + branch], encoding='utf8').strip()
removed = {}
rewritten = {}
added = {}
def print_commits(commits):
for commit, msg in commits.items():
print(commit + " " + msg)
if removed_log:
for line in removed_log.split("\n"):
commit = line.split(' ', 1)[0]
msg = line[len(commit):].strip()
removed[commit] = msg
if added_log != "":
for line in added_log.split("\n"):
commit = line.split(' ', 1)[0]
msg = line[len(commit):].strip()
if msg in removed.values():
rewritten[commit] = msg
del removed[removed.keys()[removed.values().index(msg)]]
else:
added[commit] = msg
if removed:
print("")
print("These will be removed:")
print("----------------------")
print_commits(removed)
if added:
print("")
print("These will be added:")
print("--------------------")
print_commits(added)
if rewritten:
print("")
print("These will get rewritten:")
print("-------------------------")
print_commits(rewritten)