20
20
import argparse
21
21
import hashlib
22
22
import subprocess
23
+ import sys
23
24
import json ,codecs
24
25
try :
25
26
from urllib .request import Request ,urlopen
@@ -158,11 +159,11 @@ def main():
158
159
if repo is None :
159
160
print ("ERROR: No repository configured. Use this command to set:" , file = stderr )
160
161
print ("git config githubmerge.repository <owner>/<repo>" , file = stderr )
161
- exit (1 )
162
+ sys . exit (1 )
162
163
if signingkey is None :
163
164
print ("ERROR: No GPG signing key set. Set one using:" ,file = stderr )
164
165
print ("git config --global user.signingkey <key>" ,file = stderr )
165
- exit (1 )
166
+ sys . exit (1 )
166
167
167
168
host_repo = host + ":" + repo # shortcut for push/pull target
168
169
@@ -173,7 +174,7 @@ def main():
173
174
# Receive pull information from github
174
175
info = retrieve_pr_info (repo ,pull )
175
176
if info is None :
176
- exit (1 )
177
+ sys . exit (1 )
177
178
title = info ['title' ].strip ()
178
179
body = info ['body' ].strip ()
179
180
# precedence order for destination branch argument:
@@ -194,27 +195,27 @@ def main():
194
195
subprocess .check_call ([GIT ,'checkout' ,'-q' ,branch ])
195
196
except subprocess .CalledProcessError as e :
196
197
print ("ERROR: Cannot check out branch %s." % (branch ), file = stderr )
197
- exit (3 )
198
+ sys . exit (3 )
198
199
try :
199
200
subprocess .check_call ([GIT ,'fetch' ,'-q' ,host_repo ,'+refs/pull/' + pull + '/*:refs/heads/pull/' + pull + '/*' ])
200
201
except subprocess .CalledProcessError as e :
201
202
print ("ERROR: Cannot find pull request #%s on %s." % (pull ,host_repo ), file = stderr )
202
- exit (3 )
203
+ sys . exit (3 )
203
204
try :
204
205
subprocess .check_call ([GIT ,'log' ,'-q' ,'-1' ,'refs/heads/' + head_branch ], stdout = devnull , stderr = stdout )
205
206
except subprocess .CalledProcessError as e :
206
207
print ("ERROR: Cannot find head of pull request #%s on %s." % (pull ,host_repo ), file = stderr )
207
- exit (3 )
208
+ sys . exit (3 )
208
209
try :
209
210
subprocess .check_call ([GIT ,'log' ,'-q' ,'-1' ,'refs/heads/' + merge_branch ], stdout = devnull , stderr = stdout )
210
211
except subprocess .CalledProcessError as e :
211
212
print ("ERROR: Cannot find merge of pull request #%s on %s." % (pull ,host_repo ), file = stderr )
212
- exit (3 )
213
+ sys . exit (3 )
213
214
try :
214
215
subprocess .check_call ([GIT ,'fetch' ,'-q' ,host_repo ,'+refs/heads/' + branch + ':refs/heads/' + base_branch ])
215
216
except subprocess .CalledProcessError as e :
216
217
print ("ERROR: Cannot find branch %s on %s." % (branch ,host_repo ), file = stderr )
217
- exit (3 )
218
+ sys . exit (3 )
218
219
subprocess .check_call ([GIT ,'checkout' ,'-q' ,base_branch ])
219
220
subprocess .call ([GIT ,'branch' ,'-q' ,'-D' ,local_merge_branch ], stderr = devnull )
220
221
subprocess .check_call ([GIT ,'checkout' ,'-q' ,'-b' ,local_merge_branch ])
@@ -236,30 +237,30 @@ def main():
236
237
except subprocess .CalledProcessError as e :
237
238
print ("ERROR: Cannot be merged cleanly." ,file = stderr )
238
239
subprocess .check_call ([GIT ,'merge' ,'--abort' ])
239
- exit (4 )
240
+ sys . exit (4 )
240
241
logmsg = subprocess .check_output ([GIT ,'log' ,'--pretty=format:%s' ,'-n' ,'1' ]).decode ('utf-8' )
241
242
if logmsg .rstrip () != firstline .rstrip ():
242
243
print ("ERROR: Creating merge failed (already merged?)." ,file = stderr )
243
- exit (4 )
244
+ sys . exit (4 )
244
245
245
246
symlink_files = get_symlink_files ()
246
247
for f in symlink_files :
247
248
print ("ERROR: File %s was a symlink" % f )
248
249
if len (symlink_files ) > 0 :
249
- exit (4 )
250
+ sys . exit (4 )
250
251
251
252
# Put tree SHA512 into the message
252
253
try :
253
254
first_sha512 = tree_sha512sum ()
254
255
message += '\n \n Tree-SHA512: ' + first_sha512
255
256
except subprocess .CalledProcessError as e :
256
257
printf ("ERROR: Unable to compute tree hash" )
257
- exit (4 )
258
+ sys . exit (4 )
258
259
try :
259
260
subprocess .check_call ([GIT ,'commit' ,'--amend' ,'-m' ,message .encode ('utf-8' )])
260
261
except subprocess .CalledProcessError as e :
261
262
printf ("ERROR: Cannot update message." ,file = stderr )
262
- exit (4 )
263
+ sys . exit (4 )
263
264
264
265
print_merge_details (pull , title , branch , base_branch , head_branch )
265
266
print ()
@@ -268,7 +269,7 @@ def main():
268
269
if testcmd :
269
270
if subprocess .call (testcmd ,shell = True ):
270
271
print ("ERROR: Running %s failed." % testcmd ,file = stderr )
271
- exit (5 )
272
+ sys . exit (5 )
272
273
273
274
# Show the created merge.
274
275
diff = subprocess .check_output ([GIT ,'diff' ,merge_branch + '..' + local_merge_branch ])
@@ -279,7 +280,7 @@ def main():
279
280
if reply .lower () == 'ignore' :
280
281
print ("Difference with github ignored." ,file = stderr )
281
282
else :
282
- exit (6 )
283
+ sys . exit (6 )
283
284
else :
284
285
# Verify the result manually.
285
286
print ("Dropping you on a shell so you can try building/testing the merged source." ,file = stderr )
@@ -292,7 +293,7 @@ def main():
292
293
second_sha512 = tree_sha512sum ()
293
294
if first_sha512 != second_sha512 :
294
295
print ("ERROR: Tree hash changed unexpectedly" ,file = stderr )
295
- exit (8 )
296
+ sys . exit (8 )
296
297
297
298
# Sign the merge commit.
298
299
print_merge_details (pull , title , branch , base_branch , head_branch )
@@ -306,7 +307,7 @@ def main():
306
307
print ("Error while signing, asking again." ,file = stderr )
307
308
elif reply == 'x' :
308
309
print ("Not signing off on merge, exiting." ,file = stderr )
309
- exit (1 )
310
+ sys . exit (1 )
310
311
311
312
# Put the result in branch.
312
313
subprocess .check_call ([GIT ,'checkout' ,'-q' ,branch ])
@@ -326,7 +327,7 @@ def main():
326
327
subprocess .check_call ([GIT ,'push' ,host_repo ,'refs/heads/' + branch ])
327
328
break
328
329
elif reply == 'x' :
329
- exit (1 )
330
+ sys . exit (1 )
330
331
331
332
if __name__ == '__main__' :
332
333
main ()
0 commit comments