Chromium Code Reviews| 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 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 362 rev_str = ' at %s' % revision | 362 rev_str = ' at %s' % revision |
| 363 files = [] if file_list is not None else None | 363 files = [] if file_list is not None else None |
| 364 | 364 |
| 365 printed_path = False | 365 printed_path = False |
| 366 verbose = [] | 366 verbose = [] |
| 367 if options.verbose: | 367 if options.verbose: |
| 368 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) | 368 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) |
| 369 verbose = ['--verbose'] | 369 verbose = ['--verbose'] |
| 370 printed_path = True | 370 printed_path = True |
| 371 | 371 |
| 372 if revision.startswith('refs/'): | 372 remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) |
| 373 if revision.startswith('refs/') or remote_ref: | |
| 373 rev_type = "branch" | 374 rev_type = "branch" |
| 374 elif revision.startswith(self.remote + '/'): | 375 elif revision.startswith(self.remote + '/'): |
| 375 # Rewrite remote refs to their local equivalents. | 376 # Rewrite remote refs to their local equivalents. |
| 376 revision = 'refs/remotes/' + revision | 377 revision = 'refs/remotes/' + revision |
| 377 rev_type = "branch" | 378 rev_type = "branch" |
| 378 else: | 379 else: |
| 379 # hash is also a tag, only make a distinction at checkout | 380 # hash is also a tag, only make a distinction at checkout |
| 380 rev_type = "hash" | 381 rev_type = "hash" |
| 381 | 382 |
| 382 mirror = self._GetMirror(url, options) | 383 mirror = self._GetMirror(url, options) |
| 383 if mirror: | 384 if mirror: |
| 384 url = mirror.mirror_path | 385 url = mirror.mirror_path |
| 385 | 386 |
| 386 if (not os.path.exists(self.checkout_path) or | 387 if (not os.path.exists(self.checkout_path) or |
| 387 (os.path.isdir(self.checkout_path) and | 388 (os.path.isdir(self.checkout_path) and |
| 388 not os.path.exists(os.path.join(self.checkout_path, '.git')))): | 389 not os.path.exists(os.path.join(self.checkout_path, '.git')))): |
| 389 if mirror: | 390 if mirror: |
| 390 self._UpdateMirror(mirror, options) | 391 self._UpdateMirror(mirror, options) |
| 391 try: | 392 try: |
| 392 self._Clone(revision, url, options) | 393 self._Clone(revision, url, options) |
| 393 except subprocess2.CalledProcessError: | 394 except subprocess2.CalledProcessError: |
| 394 self._DeleteOrMove(options.force) | 395 self._DeleteOrMove(options.force) |
| 395 self._Clone(revision, url, options) | 396 self._Clone(revision, url, options) |
| 396 if deps_revision and deps_revision.startswith('branch-heads/'): | 397 if remote_ref: |
| 397 deps_branch = deps_revision.replace('branch-heads/', '') | 398 deps_branch = remote_ref[1] |
| 398 self._Capture(['branch', deps_branch, deps_revision]) | 399 self._Capture(['branch', deps_branch, deps_revision]) |
| 399 self._Checkout(options, deps_branch, quiet=True) | 400 self._Checkout(options, deps_branch, quiet=True) |
| 400 if file_list is not None: | 401 if file_list is not None: |
| 401 files = self._Capture(['ls-files']).splitlines() | 402 files = self._Capture(['ls-files']).splitlines() |
| 402 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 403 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| 403 if not verbose: | 404 if not verbose: |
| 404 # Make the output a little prettier. It's nice to have some whitespace | 405 # Make the output a little prettier. It's nice to have some whitespace |
| 405 # between projects when cloning. | 406 # between projects when cloning. |
| 406 self.Print('') | 407 self.Print('') |
| 407 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 408 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 444 | 445 |
| 445 # Cases: | 446 # Cases: |
| 446 # 0) HEAD is detached. Probably from our initial clone. | 447 # 0) HEAD is detached. Probably from our initial clone. |
| 447 # - make sure HEAD is contained by a named ref, then update. | 448 # - make sure HEAD is contained by a named ref, then update. |
| 448 # Cases 1-4. HEAD is a branch. | 449 # Cases 1-4. HEAD is a branch. |
| 449 # 1) current branch is not tracking a remote branch (could be git-svn) | 450 # 1) current branch is not tracking a remote branch (could be git-svn) |
| 450 # - try to rebase onto the new hash or branch | 451 # - try to rebase onto the new hash or branch |
| 451 # 2) current branch is tracking a remote branch with local committed | 452 # 2) current branch is tracking a remote branch with local committed |
| 452 # changes, but the DEPS file switched to point to a hash | 453 # changes, but the DEPS file switched to point to a hash |
| 453 # - rebase those changes on top of the hash | 454 # - rebase those changes on top of the hash |
| 454 # 3) current branch is tracking a remote branch w/or w/out changes, | 455 # 3) current branch is tracking a remote branch w/or w/out changes, and |
| 455 # no switch | 456 # no DEPS switch |
| 456 # - see if we can FF, if not, prompt the user for rebase, merge, or stop | 457 # - see if we can FF, if not, prompt the user for rebase, merge, or stop |
| 457 # 4) current branch is tracking a remote branch, switches to a different | 458 # 4) current branch is tracking a remote branch, but DEPS switches to a |
| 458 # remote branch | 459 # different remote branch, and |
| 459 # - exit | 460 # a) current branch has no local changes, and --force: |
| 461 # - checkout new branch | |
| 462 # b) current branch has local changes, and --force and --reset: | |
| 463 # - checkout new branch | |
| 464 # c) otherwise exit | |
| 460 | 465 |
| 461 # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for | 466 # GetUpstreamBranch returns something like 'refs/remotes/origin/master' for |
| 462 # a tracking branch | 467 # a tracking branch |
| 463 # or 'master' if not a tracking branch (it's based on a specific rev/hash) | 468 # or 'master' if not a tracking branch (it's based on a specific rev/hash) |
| 464 # or it returns None if it couldn't find an upstream | 469 # or it returns None if it couldn't find an upstream |
| 465 if cur_branch is None: | 470 if cur_branch is None: |
| 466 upstream_branch = None | 471 upstream_branch = None |
| 467 current_type = "detached" | 472 current_type = "detached" |
| 468 logging.debug("Detached HEAD") | 473 logging.debug("Detached HEAD") |
| 469 else: | 474 else: |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 upstream_branch = revision | 532 upstream_branch = revision |
| 528 self._AttemptRebase(upstream_branch, files, options, | 533 self._AttemptRebase(upstream_branch, files, options, |
| 529 printed_path=printed_path, merge=options.merge) | 534 printed_path=printed_path, merge=options.merge) |
| 530 printed_path = True | 535 printed_path = True |
| 531 elif rev_type == 'hash': | 536 elif rev_type == 'hash': |
| 532 # case 2 | 537 # case 2 |
| 533 self._AttemptRebase(upstream_branch, files, options, | 538 self._AttemptRebase(upstream_branch, files, options, |
| 534 newbase=revision, printed_path=printed_path, | 539 newbase=revision, printed_path=printed_path, |
| 535 merge=options.merge) | 540 merge=options.merge) |
| 536 printed_path = True | 541 printed_path = True |
| 537 elif revision.replace('heads', 'remotes/' + self.remote) != upstream_branch: | 542 elif remote_ref and ''.join(remote_ref) != upstream_branch: |
| 538 # case 4 | 543 # case 4 |
| 539 new_base = revision.replace('heads', 'remotes/' + self.remote) | 544 new_base = ''.join(remote_ref) |
| 540 if not printed_path: | 545 if not printed_path: |
| 541 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) | 546 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) |
| 542 switch_error = ("Switching upstream branch from %s to %s\n" | 547 switch_error = ("Could not switch upstream branch from %s to %s\n" |
| 543 % (upstream_branch, new_base) + | 548 % (upstream_branch, new_base) + |
| 544 "Please merge or rebase manually:\n" + | 549 "Please use --force or merge or rebase manually:\n" + |
| 545 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + | 550 "cd %s; git rebase %s\n" % (self.checkout_path, new_base) + |
| 546 "OR git checkout -b <some new branch> %s" % new_base) | 551 "OR git checkout -b <some new branch> %s" % new_base) |
| 547 raise gclient_utils.Error(switch_error) | 552 force_switch = False |
| 553 if options.force: | |
| 554 try: | |
| 555 self._CheckClean(rev_str) | |
| 556 # case 4a | |
| 557 force_switch = True | |
| 558 except gclient_utils.Error as e: | |
| 559 if options.reset: | |
| 560 # case 4b | |
| 561 force_switch = True | |
| 562 else: | |
| 563 switch_error = '%s\n%s' % (e.message, switch_error) | |
| 564 if force_switch: | |
| 565 self.Print("Switching upstream branch from %s to %s" % | |
| 566 (upstream_branch, new_base)) | |
| 567 switch_branch = 'gclient_' + remote_ref[1] | |
| 568 self._Capture(['branch', '-f', switch_branch, new_base]) | |
| 569 self._Checkout(options, switch_branch, force=True, quiet=True) | |
| 570 pass | |
|
iannucci
2014/09/06 20:01:29
pass not needed?
Michael Moss
2014/09/08 23:58:42
Done.
| |
| 571 else: | |
| 572 # case 4c | |
| 573 raise gclient_utils.Error(switch_error) | |
|
iannucci
2014/09/06 20:01:29
why not raise this directly in the else case above
Michael Moss
2014/09/08 23:58:43
That's in the options.force block, so it would nev
| |
| 548 else: | 574 else: |
| 549 # case 3 - the default case | 575 # case 3 - the default case |
| 550 if files is not None: | 576 if files is not None: |
| 551 files = self._Capture(['diff', upstream_branch, '--name-only']).split() | 577 files = self._Capture(['diff', upstream_branch, '--name-only']).split() |
| 552 if verbose: | 578 if verbose: |
| 553 self.Print('Trying fast-forward merge to branch : %s' % upstream_branch) | 579 self.Print('Trying fast-forward merge to branch : %s' % upstream_branch) |
| 554 try: | 580 try: |
| 555 merge_args = ['merge'] | 581 merge_args = ['merge'] |
| 556 if options.merge: | 582 if options.merge: |
| 557 merge_args.append('--ff') | 583 merge_args.append('--ff') |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1575 new_command.append('--force') | 1601 new_command.append('--force') |
| 1576 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1602 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1577 new_command.extend(('--accept', 'theirs-conflict')) | 1603 new_command.extend(('--accept', 'theirs-conflict')) |
| 1578 elif options.manually_grab_svn_rev: | 1604 elif options.manually_grab_svn_rev: |
| 1579 new_command.append('--force') | 1605 new_command.append('--force') |
| 1580 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1606 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1581 new_command.extend(('--accept', 'postpone')) | 1607 new_command.extend(('--accept', 'postpone')) |
| 1582 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1608 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1583 new_command.extend(('--accept', 'postpone')) | 1609 new_command.extend(('--accept', 'postpone')) |
| 1584 return new_command | 1610 return new_command |
| OLD | NEW |