-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathllvm-commit
executable file
·96 lines (76 loc) · 2.62 KB
/
llvm-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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/python3
import subprocess
import sys
import time
my_mail = "[email protected]"
def git_cmd(args):
cmd = "git " + " ".join(args)
st = subprocess.run(['git'] + args, stdout=subprocess.PIPE)
if st.returncode != 0:
print("Error running " + cmd + "\n" + st.stdout.decode('utf-8'))
sys.exit(1)
return st.stdout.decode('utf-8')
git_cmd(['status'])
branch = git_cmd(["rev-parse", "--abbrev-ref", "HEAD"]).strip()
if branch != "main":
print("Not on main branch but on branch " + branch)
sys.exit(1)
class Remote:
def __init__(self, name, url, kind):
self.name = name
self.url = url
self.kind = kind
def __repr__(self):
return self.name + " " + self.url + " " + self.kind
remotes = []
for remote in git_cmd(['remote', '--verbose']).strip().splitlines():
parts = remote.split("\t")
remote_name = parts[0].strip()
remote_url = parts[1].split(" ")[0]
remote_kind = parts[1].split(" ")[1]
remotes.append(Remote(remote_name, remote_url, remote_kind))
def has_remote_with_name(remotes, name):
for remote in remotes:
if remote.name == name:
return True
return False
push_origin_name = "LLVM_UPSTREAM_PUSH"
if not has_remote_with_name(remotes, push_origin_name):
print("Adding missing push remote for LLVM upstream")
git_cmd(['remote', 'add', push_origin_name, '[email protected]:llvm/llvm-project'])
sys.stdout.write("Fetching push remote... ")
sys.stdout.flush()
git_cmd(['fetch', '-q', push_origin_name])
print("Done!")
different_commits = git_cmd(['log', '--format=%ce', push_origin_name + '/main..main']).strip().splitlines()
different_commits_to_show = git_cmd(['log', '--format=%ce %s %cd\n%b', push_origin_name + '/main..main'])
if len(different_commits) == 0:
print("No commits to push?")
sys.exit(1)
if len(different_commits) > 1:
print("Trying to push more than one commit?")
print(different_commits_to_show)
sys.exit(1)
assert len(different_commits) == 1
if different_commits[0] != my_mail:
print("Trying to push someone else's commit?")
print(different_commits)
sys.exit(1)
print("Pushing following commit:")
print("###############################################")
sys.stdout.write(different_commits_to_show)
print("###############################################")
def confirm():
answer = ""
while answer not in ["yes", "no"]:
answer = input("Pushing commits to remote. OK? [yes/no] ").lower()
return answer == "yes"
if not confirm():
print("Aborting...")
sys.exit(1)
print("Waiting 5 seconds to let you double check")
time.sleep(5)
sys.stdout.write("Pushing commit...")
sys.stdout.flush()
git_cmd(['push', push_origin_name, 'main'])
print("Done!")