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 collections | 7 import collections |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import posixpath | 10 import posixpath |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
462 self._CheckClean(rev_str) | 462 self._CheckClean(rev_str) |
463 self._CheckDetachedHead(rev_str, options) | 463 self._CheckDetachedHead(rev_str, options) |
464 self._Capture(['checkout', '--quiet', '%s' % revision]) | 464 self._Capture(['checkout', '--quiet', '%s' % revision]) |
465 if not printed_path: | 465 if not printed_path: |
466 print('\n_____ %s%s' % (self.relpath, rev_str)) | 466 print('\n_____ %s%s' % (self.relpath, rev_str)) |
467 elif current_type == 'hash': | 467 elif current_type == 'hash': |
468 # case 1 | 468 # case 1 |
469 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: | 469 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: |
470 # Our git-svn branch (upstream_branch) is our upstream | 470 # Our git-svn branch (upstream_branch) is our upstream |
471 self._AttemptRebase(upstream_branch, files, options, | 471 self._AttemptRebase(upstream_branch, files, options, |
472 newbase=revision, printed_path=printed_path) | 472 newbase=revision, printed_path=printed_path, |
473 merge=options.merge) | |
473 printed_path = True | 474 printed_path = True |
474 else: | 475 else: |
475 # Can't find a merge-base since we don't know our upstream. That makes | 476 # Can't find a merge-base since we don't know our upstream. That makes |
476 # this command VERY likely to produce a rebase failure. For now we | 477 # this command VERY likely to produce a rebase failure. For now we |
477 # assume origin is our upstream since that's what the old behavior was. | 478 # assume origin is our upstream since that's what the old behavior was. |
478 upstream_branch = self.remote | 479 upstream_branch = self.remote |
479 if options.revision or deps_revision: | 480 if options.revision or deps_revision: |
480 upstream_branch = revision | 481 upstream_branch = revision |
481 self._AttemptRebase(upstream_branch, files, options, | 482 self._AttemptRebase(upstream_branch, files, options, |
482 printed_path=printed_path) | 483 printed_path=printed_path, merge=options.merge) |
483 printed_path = True | 484 printed_path = True |
484 elif rev_type == 'hash': | 485 elif rev_type == 'hash': |
485 # case 2 | 486 # case 2 |
486 self._AttemptRebase(upstream_branch, files, options, | 487 self._AttemptRebase(upstream_branch, files, options, |
487 newbase=revision, printed_path=printed_path) | 488 newbase=revision, printed_path=printed_path, |
489 merge=options.merge) | |
488 printed_path = True | 490 printed_path = True |
489 elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch: | 491 elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch: |
490 # case 4 | 492 # case 4 |
491 new_base = revision.replace('heads', 'remotes/' + self.remote) | 493 new_base = revision.replace('heads', 'remotes/' + self.remote) |
492 if not printed_path: | 494 if not printed_path: |
493 print('\n_____ %s%s' % (self.relpath, rev_str)) | 495 print('\n_____ %s%s' % (self.relpath, rev_str)) |
494 switch_error = ("Switching upstream branch from %s to %s\n" | 496 switch_error = ("Switching upstream branch from %s to %s\n" |
495 % (upstream_branch, new_base) + | 497 % (upstream_branch, new_base) + |
496 "Please merge or rebase manually:\n" + | 498 "Please merge or rebase manually:\n" + |
497 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + | 499 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + |
(...skipping 12 matching lines...) Expand all Loading... | |
510 merge_args.append(upstream_branch) | 512 merge_args.append(upstream_branch) |
511 merge_output = scm.GIT.Capture(merge_args, cwd=self.checkout_path) | 513 merge_output = scm.GIT.Capture(merge_args, cwd=self.checkout_path) |
512 except subprocess2.CalledProcessError as e: | 514 except subprocess2.CalledProcessError as e: |
513 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): | 515 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): |
514 if not printed_path: | 516 if not printed_path: |
515 print('\n_____ %s%s' % (self.relpath, rev_str)) | 517 print('\n_____ %s%s' % (self.relpath, rev_str)) |
516 printed_path = True | 518 printed_path = True |
517 while True: | 519 while True: |
518 try: | 520 try: |
519 action = ask_for_data( | 521 action = ask_for_data( |
520 'Cannot fast-forward merge, attempt to rebase? ' | 522 'Cannot %s, attempt to rebase? ' |
521 '(y)es / (q)uit / (s)kip : ', options) | 523 '(y)es / (q)uit / (s)kip : ' % |
524 'merge' if options.merge else 'fast-forward merge', | |
iannucci
2013/12/16 21:01:15
Wouldn't we want to still fast-forward, even if me
Bernhard Bauer
2013/12/16 21:39:03
With this version (and --merge), we will still try
| |
525 options) | |
522 except ValueError: | 526 except ValueError: |
523 raise gclient_utils.Error('Invalid Character') | 527 raise gclient_utils.Error('Invalid Character') |
524 if re.match(r'yes|y', action, re.I): | 528 if re.match(r'yes|y', action, re.I): |
525 self._AttemptRebase(upstream_branch, files, options, | 529 self._AttemptRebase(upstream_branch, files, options, |
526 printed_path=printed_path) | 530 printed_path=printed_path, merge=False) |
527 printed_path = True | 531 printed_path = True |
528 break | 532 break |
529 elif re.match(r'quit|q', action, re.I): | 533 elif re.match(r'quit|q', action, re.I): |
530 raise gclient_utils.Error("Can't fast-forward, please merge or " | 534 raise gclient_utils.Error("Can't fast-forward, please merge or " |
531 "rebase manually.\n" | 535 "rebase manually.\n" |
532 "cd %s && git " % self.checkout_path | 536 "cd %s && git " % self.checkout_path |
533 + "rebase %s" % upstream_branch) | 537 + "rebase %s" % upstream_branch) |
534 elif re.match(r'skip|s', action, re.I): | 538 elif re.match(r'skip|s', action, re.I): |
535 print('Skipping %s' % self.relpath) | 539 print('Skipping %s' % self.relpath) |
536 return | 540 return |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 else: | 877 else: |
874 # Squelch git's very verbose detached HEAD warning and use our own | 878 # Squelch git's very verbose detached HEAD warning and use our own |
875 self._Run(['checkout', '--quiet', revision], options) | 879 self._Run(['checkout', '--quiet', revision], options) |
876 print( | 880 print( |
877 ('Checked out %s to a detached HEAD. Before making any commits\n' | 881 ('Checked out %s to a detached HEAD. Before making any commits\n' |
878 'in this repo, you should use \'git checkout <branch>\' to switch to\n' | 882 'in this repo, you should use \'git checkout <branch>\' to switch to\n' |
879 'an existing branch or use \'git checkout %s -b <branch>\' to\n' | 883 'an existing branch or use \'git checkout %s -b <branch>\' to\n' |
880 'create a new branch for your work.') % (revision, self.remote)) | 884 'create a new branch for your work.') % (revision, self.remote)) |
881 | 885 |
882 def _AttemptRebase(self, upstream, files, options, newbase=None, | 886 def _AttemptRebase(self, upstream, files, options, newbase=None, |
883 branch=None, printed_path=False): | 887 branch=None, printed_path=False, merge=False): |
884 """Attempt to rebase onto either upstream or, if specified, newbase.""" | 888 """Attempt to rebase onto either upstream or, if specified, newbase.""" |
885 if files is not None: | 889 if files is not None: |
886 files.extend(self._Capture(['diff', upstream, '--name-only']).split()) | 890 files.extend(self._Capture(['diff', upstream, '--name-only']).split()) |
887 revision = upstream | 891 revision = upstream |
888 if newbase: | 892 if newbase: |
889 revision = newbase | 893 revision = newbase |
894 action = 'merge' if merge else 'rebase' | |
890 if not printed_path: | 895 if not printed_path: |
891 print('\n_____ %s : Attempting rebase onto %s...' % ( | 896 print('\n_____ %s : Attempting %s onto %s...' % ( |
892 self.relpath, revision)) | 897 action, self.relpath, revision)) |
893 printed_path = True | 898 printed_path = True |
894 else: | 899 else: |
895 print('Attempting rebase onto %s...' % revision) | 900 print('Attempting %s onto %s...' % (action, revision)) |
901 | |
902 if merge: | |
903 merge_output = self._Capture(['merge', revision]) | |
904 if options.verbose: | |
905 print(merge_output) | |
906 return | |
896 | 907 |
897 # Build the rebase command here using the args | 908 # Build the rebase command here using the args |
898 # git rebase [options] [--onto <newbase>] <upstream> [<branch>] | 909 # git rebase [options] [--onto <newbase>] <upstream> [<branch>] |
899 rebase_cmd = ['rebase'] | 910 rebase_cmd = ['rebase'] |
900 if options.verbose: | 911 if options.verbose: |
901 rebase_cmd.append('--verbose') | 912 rebase_cmd.append('--verbose') |
902 if newbase: | 913 if newbase: |
903 rebase_cmd.extend(['--onto', newbase]) | 914 rebase_cmd.extend(['--onto', newbase]) |
904 rebase_cmd.append(upstream) | 915 rebase_cmd.append(upstream) |
905 if branch: | 916 if branch: |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1452 new_command.append('--force') | 1463 new_command.append('--force') |
1453 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1464 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1454 new_command.extend(('--accept', 'theirs-conflict')) | 1465 new_command.extend(('--accept', 'theirs-conflict')) |
1455 elif options.manually_grab_svn_rev: | 1466 elif options.manually_grab_svn_rev: |
1456 new_command.append('--force') | 1467 new_command.append('--force') |
1457 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1468 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1458 new_command.extend(('--accept', 'postpone')) | 1469 new_command.extend(('--accept', 'postpone')) |
1459 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1470 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1460 new_command.extend(('--accept', 'postpone')) | 1471 new_command.extend(('--accept', 'postpone')) |
1461 return new_command | 1472 return new_command |
OLD | NEW |