2020import argparse
2121import hashlib
2222import subprocess
23+ import sys
2324import json ,codecs
2425try :
2526 from urllib .request import Request ,urlopen
@@ -158,11 +159,11 @@ def main():
158159 if repo is None :
159160 print ("ERROR: No repository configured. Use this command to set:" , file = stderr )
160161 print ("git config githubmerge.repository <owner>/<repo>" , file = stderr )
161- exit (1 )
162+ sys . exit (1 )
162163 if signingkey is None :
163164 print ("ERROR: No GPG signing key set. Set one using:" ,file = stderr )
164165 print ("git config --global user.signingkey <key>" ,file = stderr )
165- exit (1 )
166+ sys . exit (1 )
166167
167168 host_repo = host + ":" + repo # shortcut for push/pull target
168169
@@ -173,7 +174,7 @@ def main():
173174 # Receive pull information from github
174175 info = retrieve_pr_info (repo ,pull )
175176 if info is None :
176- exit (1 )
177+ sys . exit (1 )
177178 title = info ['title' ].strip ()
178179 body = info ['body' ].strip ()
179180 # precedence order for destination branch argument:
@@ -194,27 +195,27 @@ def main():
194195 subprocess .check_call ([GIT ,'checkout' ,'-q' ,branch ])
195196 except subprocess .CalledProcessError as e :
196197 print ("ERROR: Cannot check out branch %s." % (branch ), file = stderr )
197- exit (3 )
198+ sys . exit (3 )
198199 try :
199200 subprocess .check_call ([GIT ,'fetch' ,'-q' ,host_repo ,'+refs/pull/' + pull + '/*:refs/heads/pull/' + pull + '/*' ])
200201 except subprocess .CalledProcessError as e :
201202 print ("ERROR: Cannot find pull request #%s on %s." % (pull ,host_repo ), file = stderr )
202- exit (3 )
203+ sys . exit (3 )
203204 try :
204205 subprocess .check_call ([GIT ,'log' ,'-q' ,'-1' ,'refs/heads/' + head_branch ], stdout = devnull , stderr = stdout )
205206 except subprocess .CalledProcessError as e :
206207 print ("ERROR: Cannot find head of pull request #%s on %s." % (pull ,host_repo ), file = stderr )
207- exit (3 )
208+ sys . exit (3 )
208209 try :
209210 subprocess .check_call ([GIT ,'log' ,'-q' ,'-1' ,'refs/heads/' + merge_branch ], stdout = devnull , stderr = stdout )
210211 except subprocess .CalledProcessError as e :
211212 print ("ERROR: Cannot find merge of pull request #%s on %s." % (pull ,host_repo ), file = stderr )
212- exit (3 )
213+ sys . exit (3 )
213214 try :
214215 subprocess .check_call ([GIT ,'fetch' ,'-q' ,host_repo ,'+refs/heads/' + branch + ':refs/heads/' + base_branch ])
215216 except subprocess .CalledProcessError as e :
216217 print ("ERROR: Cannot find branch %s on %s." % (branch ,host_repo ), file = stderr )
217- exit (3 )
218+ sys . exit (3 )
218219 subprocess .check_call ([GIT ,'checkout' ,'-q' ,base_branch ])
219220 subprocess .call ([GIT ,'branch' ,'-q' ,'-D' ,local_merge_branch ], stderr = devnull )
220221 subprocess .check_call ([GIT ,'checkout' ,'-q' ,'-b' ,local_merge_branch ])
@@ -236,30 +237,30 @@ def main():
236237 except subprocess .CalledProcessError as e :
237238 print ("ERROR: Cannot be merged cleanly." ,file = stderr )
238239 subprocess .check_call ([GIT ,'merge' ,'--abort' ])
239- exit (4 )
240+ sys . exit (4 )
240241 logmsg = subprocess .check_output ([GIT ,'log' ,'--pretty=format:%s' ,'-n' ,'1' ]).decode ('utf-8' )
241242 if logmsg .rstrip () != firstline .rstrip ():
242243 print ("ERROR: Creating merge failed (already merged?)." ,file = stderr )
243- exit (4 )
244+ sys . exit (4 )
244245
245246 symlink_files = get_symlink_files ()
246247 for f in symlink_files :
247248 print ("ERROR: File %s was a symlink" % f )
248249 if len (symlink_files ) > 0 :
249- exit (4 )
250+ sys . exit (4 )
250251
251252 # Put tree SHA512 into the message
252253 try :
253254 first_sha512 = tree_sha512sum ()
254255 message += '\n \n Tree-SHA512: ' + first_sha512
255256 except subprocess .CalledProcessError as e :
256257 printf ("ERROR: Unable to compute tree hash" )
257- exit (4 )
258+ sys . exit (4 )
258259 try :
259260 subprocess .check_call ([GIT ,'commit' ,'--amend' ,'-m' ,message .encode ('utf-8' )])
260261 except subprocess .CalledProcessError as e :
261262 printf ("ERROR: Cannot update message." ,file = stderr )
262- exit (4 )
263+ sys . exit (4 )
263264
264265 print_merge_details (pull , title , branch , base_branch , head_branch )
265266 print ()
@@ -268,7 +269,7 @@ def main():
268269 if testcmd :
269270 if subprocess .call (testcmd ,shell = True ):
270271 print ("ERROR: Running %s failed." % testcmd ,file = stderr )
271- exit (5 )
272+ sys . exit (5 )
272273
273274 # Show the created merge.
274275 diff = subprocess .check_output ([GIT ,'diff' ,merge_branch + '..' + local_merge_branch ])
@@ -279,7 +280,7 @@ def main():
279280 if reply .lower () == 'ignore' :
280281 print ("Difference with github ignored." ,file = stderr )
281282 else :
282- exit (6 )
283+ sys . exit (6 )
283284 else :
284285 # Verify the result manually.
285286 print ("Dropping you on a shell so you can try building/testing the merged source." ,file = stderr )
@@ -292,7 +293,7 @@ def main():
292293 second_sha512 = tree_sha512sum ()
293294 if first_sha512 != second_sha512 :
294295 print ("ERROR: Tree hash changed unexpectedly" ,file = stderr )
295- exit (8 )
296+ sys . exit (8 )
296297
297298 # Sign the merge commit.
298299 print_merge_details (pull , title , branch , base_branch , head_branch )
@@ -306,7 +307,7 @@ def main():
306307 print ("Error while signing, asking again." ,file = stderr )
307308 elif reply == 'x' :
308309 print ("Not signing off on merge, exiting." ,file = stderr )
309- exit (1 )
310+ sys . exit (1 )
310311
311312 # Put the result in branch.
312313 subprocess .check_call ([GIT ,'checkout' ,'-q' ,branch ])
@@ -326,7 +327,7 @@ def main():
326327 subprocess .check_call ([GIT ,'push' ,host_repo ,'refs/heads/' + branch ])
327328 break
328329 elif reply == 'x' :
329- exit (1 )
330+ sys . exit (1 )
330331
331332if __name__ == '__main__' :
332333 main ()
0 commit comments