| 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 from __future__ import print_function | 7 from __future__ import print_function |
| 8 | 8 |
| 9 import errno | 9 import errno |
| 10 import logging | 10 import logging |
| (...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 # Check again for a revision in case an initial ref was specified | 370 # Check again for a revision in case an initial ref was specified |
| 371 # in the url, for example bla.git@refs/heads/custombranch | 371 # in the url, for example bla.git@refs/heads/custombranch |
| 372 revision = deps_revision | 372 revision = deps_revision |
| 373 managed = False | 373 managed = False |
| 374 if not revision: | 374 if not revision: |
| 375 revision = default_rev | 375 revision = default_rev |
| 376 | 376 |
| 377 if managed: | 377 if managed: |
| 378 self._DisableHooks() | 378 self._DisableHooks() |
| 379 | 379 |
| 380 files = [] if file_list is not None else None | |
| 381 | |
| 382 printed_path = False | 380 printed_path = False |
| 383 verbose = [] | 381 verbose = [] |
| 384 if options.verbose: | 382 if options.verbose: |
| 385 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) | 383 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) |
| 386 verbose = ['--verbose'] | 384 verbose = ['--verbose'] |
| 387 printed_path = True | 385 printed_path = True |
| 388 | 386 |
| 389 remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) | 387 remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) |
| 390 if remote_ref: | 388 if remote_ref: |
| 391 # Rewrite remote refs to their local equivalents. | 389 # Rewrite remote refs to their local equivalents. |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 if not printed_path: | 554 if not printed_path: |
| 557 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) | 555 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) |
| 558 elif current_type == 'hash': | 556 elif current_type == 'hash': |
| 559 # case 1 | 557 # case 1 |
| 560 # Can't find a merge-base since we don't know our upstream. That makes | 558 # Can't find a merge-base since we don't know our upstream. That makes |
| 561 # this command VERY likely to produce a rebase failure. For now we | 559 # this command VERY likely to produce a rebase failure. For now we |
| 562 # assume origin is our upstream since that's what the old behavior was. | 560 # assume origin is our upstream since that's what the old behavior was. |
| 563 upstream_branch = self.remote | 561 upstream_branch = self.remote |
| 564 if options.revision or deps_revision: | 562 if options.revision or deps_revision: |
| 565 upstream_branch = revision | 563 upstream_branch = revision |
| 566 self._AttemptRebase(upstream_branch, files, options, | 564 self._AttemptRebase(upstream_branch, file_list, options, |
| 567 printed_path=printed_path, merge=options.merge) | 565 printed_path=printed_path, merge=options.merge) |
| 568 printed_path = True | 566 printed_path = True |
| 569 elif rev_type == 'hash': | 567 elif rev_type == 'hash': |
| 570 # case 2 | 568 # case 2 |
| 571 self._AttemptRebase(upstream_branch, files, options, | 569 self._AttemptRebase(upstream_branch, file_list, options, |
| 572 newbase=revision, printed_path=printed_path, | 570 newbase=revision, printed_path=printed_path, |
| 573 merge=options.merge) | 571 merge=options.merge) |
| 574 printed_path = True | 572 printed_path = True |
| 575 elif remote_ref and ''.join(remote_ref) != upstream_branch: | 573 elif remote_ref and ''.join(remote_ref) != upstream_branch: |
| 576 # case 4 | 574 # case 4 |
| 577 new_base = ''.join(remote_ref) | 575 new_base = ''.join(remote_ref) |
| 578 if not printed_path: | 576 if not printed_path: |
| 579 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) | 577 self.Print('_____ %s at %s' % (self.relpath, revision), timestamp=False) |
| 580 switch_error = ("Could not switch upstream branch from %s to %s\n" | 578 switch_error = ("Could not switch upstream branch from %s to %s\n" |
| 581 % (upstream_branch, new_base) + | 579 % (upstream_branch, new_base) + |
| (...skipping 16 matching lines...) Expand all Loading... |
| 598 self.Print("Switching upstream branch from %s to %s" % | 596 self.Print("Switching upstream branch from %s to %s" % |
| 599 (upstream_branch, new_base)) | 597 (upstream_branch, new_base)) |
| 600 switch_branch = 'gclient_' + remote_ref[1] | 598 switch_branch = 'gclient_' + remote_ref[1] |
| 601 self._Capture(['branch', '-f', switch_branch, new_base]) | 599 self._Capture(['branch', '-f', switch_branch, new_base]) |
| 602 self._Checkout(options, switch_branch, force=True, quiet=True) | 600 self._Checkout(options, switch_branch, force=True, quiet=True) |
| 603 else: | 601 else: |
| 604 # case 4c | 602 # case 4c |
| 605 raise gclient_utils.Error(switch_error) | 603 raise gclient_utils.Error(switch_error) |
| 606 else: | 604 else: |
| 607 # case 3 - the default case | 605 # case 3 - the default case |
| 608 if files is not None: | 606 rebase_files = self._Capture( |
| 609 files = self._Capture(['diff', upstream_branch, '--name-only']).split() | 607 ['diff', upstream_branch, '--name-only']).split() |
| 610 if verbose: | 608 if verbose: |
| 611 self.Print('Trying fast-forward merge to branch : %s' % upstream_branch) | 609 self.Print('Trying fast-forward merge to branch : %s' % upstream_branch) |
| 612 try: | 610 try: |
| 613 merge_args = ['merge'] | 611 merge_args = ['merge'] |
| 614 if options.merge: | 612 if options.merge: |
| 615 merge_args.append('--ff') | 613 merge_args.append('--ff') |
| 616 else: | 614 else: |
| 617 merge_args.append('--ff-only') | 615 merge_args.append('--ff-only') |
| 618 merge_args.append(upstream_branch) | 616 merge_args.append(upstream_branch) |
| 619 merge_output = self._Capture(merge_args) | 617 merge_output = self._Capture(merge_args) |
| 620 except subprocess2.CalledProcessError as e: | 618 except subprocess2.CalledProcessError as e: |
| 619 rebase_files = [] |
| 621 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): | 620 if re.match('fatal: Not possible to fast-forward, aborting.', e.stderr): |
| 622 files = [] | |
| 623 if not printed_path: | 621 if not printed_path: |
| 624 self.Print('_____ %s at %s' % (self.relpath, revision), | 622 self.Print('_____ %s at %s' % (self.relpath, revision), |
| 625 timestamp=False) | 623 timestamp=False) |
| 626 printed_path = True | 624 printed_path = True |
| 627 while True: | 625 while True: |
| 628 if not options.auto_rebase: | 626 if not options.auto_rebase: |
| 629 try: | 627 try: |
| 630 action = self._AskForData( | 628 action = self._AskForData( |
| 631 'Cannot %s, attempt to rebase? ' | 629 'Cannot %s, attempt to rebase? ' |
| 632 '(y)es / (q)uit / (s)kip : ' % | 630 '(y)es / (q)uit / (s)kip : ' % |
| 633 ('merge' if options.merge else 'fast-forward merge'), | 631 ('merge' if options.merge else 'fast-forward merge'), |
| 634 options) | 632 options) |
| 635 except ValueError: | 633 except ValueError: |
| 636 raise gclient_utils.Error('Invalid Character') | 634 raise gclient_utils.Error('Invalid Character') |
| 637 if options.auto_rebase or re.match(r'yes|y', action, re.I): | 635 if options.auto_rebase or re.match(r'yes|y', action, re.I): |
| 638 self._AttemptRebase(upstream_branch, files, options, | 636 self._AttemptRebase(upstream_branch, rebase_files, options, |
| 639 printed_path=printed_path, merge=False) | 637 printed_path=printed_path, merge=False) |
| 640 printed_path = True | 638 printed_path = True |
| 641 break | 639 break |
| 642 elif re.match(r'quit|q', action, re.I): | 640 elif re.match(r'quit|q', action, re.I): |
| 643 raise gclient_utils.Error("Can't fast-forward, please merge or " | 641 raise gclient_utils.Error("Can't fast-forward, please merge or " |
| 644 "rebase manually.\n" | 642 "rebase manually.\n" |
| 645 "cd %s && git " % self.checkout_path | 643 "cd %s && git " % self.checkout_path |
| 646 + "rebase %s" % upstream_branch) | 644 + "rebase %s" % upstream_branch) |
| 647 elif re.match(r'skip|s', action, re.I): | 645 elif re.match(r'skip|s', action, re.I): |
| 648 self.Print('Skipping %s' % self.relpath) | 646 self.Print('Skipping %s' % self.relpath) |
| (...skipping 20 matching lines...) Expand all Loading... |
| 669 if not printed_path: | 667 if not printed_path: |
| 670 self.Print('_____ %s at %s' % (self.relpath, revision), | 668 self.Print('_____ %s at %s' % (self.relpath, revision), |
| 671 timestamp=False) | 669 timestamp=False) |
| 672 printed_path = True | 670 printed_path = True |
| 673 self.Print(merge_output.strip()) | 671 self.Print(merge_output.strip()) |
| 674 if not verbose: | 672 if not verbose: |
| 675 # Make the output a little prettier. It's nice to have some | 673 # Make the output a little prettier. It's nice to have some |
| 676 # whitespace between projects when syncing. | 674 # whitespace between projects when syncing. |
| 677 self.Print('') | 675 self.Print('') |
| 678 | 676 |
| 679 if file_list is not None: | 677 file_list.extend( |
| 680 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 678 [os.path.join(self.checkout_path, f) for f in rebase_files]) |
| 681 | 679 |
| 682 # If the rebase generated a conflict, abort and ask user to fix | 680 # If the rebase generated a conflict, abort and ask user to fix |
| 683 if self._IsRebasing(): | 681 if self._IsRebasing(): |
| 684 raise gclient_utils.Error('\n____ %s at %s\n' | 682 raise gclient_utils.Error('\n____ %s at %s\n' |
| 685 '\nConflict while rebasing this branch.\n' | 683 '\nConflict while rebasing this branch.\n' |
| 686 'Fix the conflict and run gclient again.\n' | 684 'Fix the conflict and run gclient again.\n' |
| 687 'See man git-rebase for details.\n' | 685 'See man git-rebase for details.\n' |
| 688 % (self.relpath, revision)) | 686 % (self.relpath, revision)) |
| 689 | 687 |
| 690 if verbose: | 688 if verbose: |
| (...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 kwargs.setdefault('cwd', self.checkout_path) | 1165 kwargs.setdefault('cwd', self.checkout_path) |
| 1168 kwargs.setdefault('stdout', self.out_fh) | 1166 kwargs.setdefault('stdout', self.out_fh) |
| 1169 kwargs['filter_fn'] = self.filter | 1167 kwargs['filter_fn'] = self.filter |
| 1170 kwargs.setdefault('print_stdout', False) | 1168 kwargs.setdefault('print_stdout', False) |
| 1171 env = scm.GIT.ApplyEnvVars(kwargs) | 1169 env = scm.GIT.ApplyEnvVars(kwargs) |
| 1172 cmd = ['git'] + args | 1170 cmd = ['git'] + args |
| 1173 if show_header: | 1171 if show_header: |
| 1174 gclient_utils.CheckCallAndFilterAndHeader(cmd, env=env, **kwargs) | 1172 gclient_utils.CheckCallAndFilterAndHeader(cmd, env=env, **kwargs) |
| 1175 else: | 1173 else: |
| 1176 gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs) | 1174 gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs) |
| OLD | NEW |