OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Gclient-specific SCM-specific operations.""" | 5 """Gclient-specific SCM-specific operations.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import posixpath | 9 import posixpath |
10 import re | 10 import re |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 index_string = "diff --git " | 62 index_string = "diff --git " |
63 | 63 |
64 def SetCurrentFile(self, current_file): | 64 def SetCurrentFile(self, current_file): |
65 # Get filename by parsing "a/<filename> b/<filename>" | 65 # Get filename by parsing "a/<filename> b/<filename>" |
66 self._current_file = current_file[:(len(current_file)/2)][2:] | 66 self._current_file = current_file[:(len(current_file)/2)][2:] |
67 | 67 |
68 def _Replace(self, line): | 68 def _Replace(self, line): |
69 return re.sub("[a|b]/" + self._current_file, self._replacement_file, line) | 69 return re.sub("[a|b]/" + self._current_file, self._replacement_file, line) |
70 | 70 |
71 | 71 |
72 def ask_for_data(prompt): | 72 def ask_for_data(prompt, options): |
| 73 if options.jobs > 1: |
| 74 raise gclient_utils.Error("Background task requires input. Rerun " |
| 75 "gclient with --jobs=1 so that\n" |
| 76 "interaction is possible.") |
73 try: | 77 try: |
74 return raw_input(prompt) | 78 return raw_input(prompt) |
75 except KeyboardInterrupt: | 79 except KeyboardInterrupt: |
76 # Hide the exception. | 80 # Hide the exception. |
77 sys.exit(1) | 81 sys.exit(1) |
78 | 82 |
79 | 83 |
80 ### SCM abstraction layer | 84 ### SCM abstraction layer |
81 | 85 |
82 # Factory Method for SCM wrapper creation | 86 # Factory Method for SCM wrapper creation |
(...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 # case 3 - the default case | 451 # case 3 - the default case |
448 files = self._Capture(['diff', upstream_branch, '--name-only']).split() | 452 files = self._Capture(['diff', upstream_branch, '--name-only']).split() |
449 if verbose: | 453 if verbose: |
450 print('Trying fast-forward merge to branch : %s' % upstream_branch) | 454 print('Trying fast-forward merge to branch : %s' % upstream_branch) |
451 try: | 455 try: |
452 merge_args = ['merge'] | 456 merge_args = ['merge'] |
453 if not options.merge: | 457 if not options.merge: |
454 merge_args.append('--ff-only') | 458 merge_args.append('--ff-only') |
455 merge_args.append(upstream_branch) | 459 merge_args.append(upstream_branch) |
456 merge_output = scm.GIT.Capture(merge_args, cwd=self.checkout_path) | 460 merge_output = scm.GIT.Capture(merge_args, cwd=self.checkout_path) |
457 except subprocess2.CalledProcessError, e: | 461 except subprocess2.CalledProcessError as e: |
458 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): | 462 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): |
459 if not printed_path: | 463 if not printed_path: |
460 print('\n_____ %s%s' % (self.relpath, rev_str)) | 464 print('\n_____ %s%s' % (self.relpath, rev_str)) |
461 printed_path = True | 465 printed_path = True |
462 while True: | 466 while True: |
463 try: | 467 try: |
464 # TODO(maruel): That can't work with --jobs. | |
465 action = ask_for_data( | 468 action = ask_for_data( |
466 'Cannot fast-forward merge, attempt to rebase? ' | 469 'Cannot fast-forward merge, attempt to rebase? ' |
467 '(y)es / (q)uit / (s)kip : ') | 470 '(y)es / (q)uit / (s)kip : ', options) |
468 except ValueError: | 471 except ValueError: |
469 raise gclient_utils.Error('Invalid Character') | 472 raise gclient_utils.Error('Invalid Character') |
470 if re.match(r'yes|y', action, re.I): | 473 if re.match(r'yes|y', action, re.I): |
471 self._AttemptRebase(upstream_branch, files, options, | 474 self._AttemptRebase(upstream_branch, files, options, |
472 printed_path=printed_path) | 475 printed_path=printed_path) |
473 printed_path = True | 476 printed_path = True |
474 break | 477 break |
475 elif re.match(r'quit|q', action, re.I): | 478 elif re.match(r'quit|q', action, re.I): |
476 raise gclient_utils.Error("Can't fast-forward, please merge or " | 479 raise gclient_utils.Error("Can't fast-forward, please merge or " |
477 "rebase manually.\n" | 480 "rebase manually.\n" |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) | 751 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) |
749 except subprocess2.CalledProcessError, e: | 752 except subprocess2.CalledProcessError, e: |
750 if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or | 753 if (re.match(r'cannot rebase: you have unstaged changes', e.stderr) or |
751 re.match(r'cannot rebase: your index contains uncommitted changes', | 754 re.match(r'cannot rebase: your index contains uncommitted changes', |
752 e.stderr)): | 755 e.stderr)): |
753 while True: | 756 while True: |
754 rebase_action = ask_for_data( | 757 rebase_action = ask_for_data( |
755 'Cannot rebase because of unstaged changes.\n' | 758 'Cannot rebase because of unstaged changes.\n' |
756 '\'git reset --hard HEAD\' ?\n' | 759 '\'git reset --hard HEAD\' ?\n' |
757 'WARNING: destroys any uncommitted work in your current branch!' | 760 'WARNING: destroys any uncommitted work in your current branch!' |
758 ' (y)es / (q)uit / (s)how : ') | 761 ' (y)es / (q)uit / (s)how : ', options) |
759 if re.match(r'yes|y', rebase_action, re.I): | 762 if re.match(r'yes|y', rebase_action, re.I): |
760 self._Run(['reset', '--hard', 'HEAD'], options) | 763 self._Run(['reset', '--hard', 'HEAD'], options) |
761 # Should this be recursive? | 764 # Should this be recursive? |
762 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) | 765 rebase_output = scm.GIT.Capture(rebase_cmd, cwd=self.checkout_path) |
763 break | 766 break |
764 elif re.match(r'quit|q', rebase_action, re.I): | 767 elif re.match(r'quit|q', rebase_action, re.I): |
765 raise gclient_utils.Error("Please merge or rebase manually\n" | 768 raise gclient_utils.Error("Please merge or rebase manually\n" |
766 "cd %s && git " % self.checkout_path | 769 "cd %s && git " % self.checkout_path |
767 + "%s" % ' '.join(rebase_cmd)) | 770 + "%s" % ' '.join(rebase_cmd)) |
768 elif re.match(r'show|s', rebase_action, re.I): | 771 elif re.match(r'show|s', rebase_action, re.I): |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 new_command.append('--force') | 1279 new_command.append('--force') |
1277 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1280 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1278 new_command.extend(('--accept', 'theirs-conflict')) | 1281 new_command.extend(('--accept', 'theirs-conflict')) |
1279 elif options.manually_grab_svn_rev: | 1282 elif options.manually_grab_svn_rev: |
1280 new_command.append('--force') | 1283 new_command.append('--force') |
1281 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1284 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1282 new_command.extend(('--accept', 'postpone')) | 1285 new_command.extend(('--accept', 'postpone')) |
1283 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1286 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1284 new_command.extend(('--accept', 'postpone')) | 1287 new_command.extend(('--accept', 'postpone')) |
1285 return new_command | 1288 return new_command |
OLD | NEW |