1
1
#!/usr/bin/env python3
2
- # Copyright (c) 2016 The Bitcoin Core developers
2
+ # Copyright (c) 2016-2017 Bitcoin Core Developers
3
3
# Distributed under the MIT software license, see the accompanying
4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
15
15
# In case of a clean merge that is accepted by the user, the local branch with
16
16
# name $BRANCH is overwritten with the merged result, and optionally pushed.
17
17
from __future__ import division ,print_function ,unicode_literals
18
- import os
18
+ import os , sys
19
19
from sys import stdin ,stdout ,stderr
20
20
import argparse
21
21
import hashlib
@@ -127,6 +127,9 @@ def tree_sha512sum(commit='HEAD'):
127
127
raise IOError ('Non-zero return value executing git cat-file' )
128
128
return overall .hexdigest ()
129
129
130
+ def print_merge_details (pull , title , branch , base_branch , head_branch ):
131
+ print ('%s#%s%s %s %sinto %s%s' % (ATTR_RESET + ATTR_PR ,pull ,ATTR_RESET ,title ,ATTR_RESET + ATTR_PR ,branch ,ATTR_RESET ))
132
+ subprocess .check_call ([GIT ,'log' ,'--graph' ,'--topo-order' ,'--pretty=format:' + COMMIT_FORMAT ,base_branch + '..' + head_branch ])
130
133
131
134
def parse_arguments ():
132
135
epilog = '''
@@ -171,7 +174,7 @@ def main():
171
174
info = retrieve_pr_info (repo ,pull )
172
175
if info is None :
173
176
exit (1 )
174
- title = info ['title' ]
177
+ title = info ['title' ]. strip ()
175
178
# precedence order for destination branch argument:
176
179
# - command line argument
177
180
# - githubmerge.branch setting
@@ -256,8 +259,7 @@ def main():
256
259
printf ("ERROR: Cannot update message." ,file = stderr )
257
260
exit (4 )
258
261
259
- print ('%s#%s%s %s %sinto %s%s' % (ATTR_RESET + ATTR_PR ,pull ,ATTR_RESET ,title ,ATTR_RESET + ATTR_PR ,branch ,ATTR_RESET ))
260
- subprocess .check_call ([GIT ,'log' ,'--graph' ,'--topo-order' ,'--pretty=format:' + COMMIT_FORMAT ,base_branch + '..' + head_branch ])
262
+ print_merge_details (pull , title , branch , base_branch , head_branch )
261
263
print ()
262
264
263
265
# Run test command if configured.
@@ -276,12 +278,6 @@ def main():
276
278
print ("Difference with github ignored." ,file = stderr )
277
279
else :
278
280
exit (6 )
279
- reply = ask_prompt ("Press 'd' to accept the diff." )
280
- if reply .lower () == 'd' :
281
- print ("Diff accepted." ,file = stderr )
282
- else :
283
- print ("ERROR: Diff rejected." ,file = stderr )
284
- exit (6 )
285
281
else :
286
282
# Verify the result manually.
287
283
print ("Dropping you on a shell so you can try building/testing the merged source." ,file = stderr )
@@ -290,29 +286,26 @@ def main():
290
286
if os .path .isfile ('/etc/debian_version' ): # Show pull number on Debian default prompt
291
287
os .putenv ('debian_chroot' ,pull )
292
288
subprocess .call ([BASH ,'-i' ])
293
- reply = ask_prompt ("Type 'm' to accept the merge." )
294
- if reply .lower () == 'm' :
295
- print ("Merge accepted." ,file = stderr )
296
- else :
297
- print ("ERROR: Merge rejected." ,file = stderr )
298
- exit (7 )
299
289
300
290
second_sha512 = tree_sha512sum ()
301
291
if first_sha512 != second_sha512 :
302
292
print ("ERROR: Tree hash changed unexpectedly" ,file = stderr )
303
293
exit (8 )
304
294
305
295
# Sign the merge commit.
306
- reply = ask_prompt ("Type 's' to sign off on the merge." )
307
- if reply == 's' :
308
- try :
309
- subprocess .check_call ([GIT ,'commit' ,'-q' ,'--gpg-sign' ,'--amend' ,'--no-edit' ])
310
- except subprocess .CalledProcessError as e :
311
- print ("Error signing, exiting." ,file = stderr )
296
+ print_merge_details (pull , title , branch , base_branch , head_branch )
297
+ while True :
298
+ reply = ask_prompt ("Type 's' to sign off on the above merge, or 'x' to reject and exit." ).lower ()
299
+ if reply == 's' :
300
+ try :
301
+ subprocess .check_call ([GIT ,'commit' ,'-q' ,'--gpg-sign' ,'--amend' ,'--no-edit' ])
302
+ break
303
+ except subprocess .CalledProcessError as e :
304
+ print ("Error signing, exiting." ,file = stderr )
305
+ exit (1 )
306
+ elif reply == 'x' :
307
+ print ("Not signing off on merge, exiting." ,file = stderr )
312
308
exit (1 )
313
- else :
314
- print ("Not signing off on merge, exiting." ,file = stderr )
315
- exit (1 )
316
309
317
310
# Put the result in branch.
318
311
subprocess .check_call ([GIT ,'checkout' ,'-q' ,branch ])
@@ -326,9 +319,13 @@ def main():
326
319
subprocess .call ([GIT ,'branch' ,'-q' ,'-D' ,local_merge_branch ],stderr = devnull )
327
320
328
321
# Push the result.
329
- reply = ask_prompt ("Type 'push' to push the result to %s, branch %s." % (host_repo ,branch ))
330
- if reply .lower () == 'push' :
331
- subprocess .check_call ([GIT ,'push' ,host_repo ,'refs/heads/' + branch ])
322
+ while True :
323
+ reply = ask_prompt ("Type 'push' to push the result to %s, branch %s, or 'x' to exit without pushing." % (host_repo ,branch )).lower ()
324
+ if reply == 'push' :
325
+ subprocess .check_call ([GIT ,'push' ,host_repo ,'refs/heads/' + branch ])
326
+ break
327
+ elif reply == 'x' :
328
+ exit (1 )
332
329
333
330
if __name__ == '__main__' :
334
331
main ()
0 commit comments