Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(33)

Side by Side Diff: gclient_scm.py

Issue 326153003: Added common git 'checkout' function (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Rebased to 8a10f6de3ef3257844166d23928e958b34c8163e Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 if mirror: 388 if mirror:
389 self._UpdateMirror(mirror, options) 389 self._UpdateMirror(mirror, options)
390 try: 390 try:
391 self._Clone(revision, url, options) 391 self._Clone(revision, url, options)
392 except subprocess2.CalledProcessError: 392 except subprocess2.CalledProcessError:
393 self._DeleteOrMove(options.force) 393 self._DeleteOrMove(options.force)
394 self._Clone(revision, url, options) 394 self._Clone(revision, url, options)
395 if deps_revision and deps_revision.startswith('branch-heads/'): 395 if deps_revision and deps_revision.startswith('branch-heads/'):
396 deps_branch = deps_revision.replace('branch-heads/', '') 396 deps_branch = deps_revision.replace('branch-heads/', '')
397 self._Capture(['branch', deps_branch, deps_revision]) 397 self._Capture(['branch', deps_branch, deps_revision])
398 self._Capture(['checkout', '--quiet', deps_branch]) 398 self._Checkout(options, deps_branch, quiet=True)
399 if file_list is not None: 399 if file_list is not None:
400 files = self._Capture(['ls-files']).splitlines() 400 files = self._Capture(['ls-files']).splitlines()
401 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) 401 file_list.extend([os.path.join(self.checkout_path, f) for f in files])
402 if not verbose: 402 if not verbose:
403 # Make the output a little prettier. It's nice to have some whitespace 403 # Make the output a little prettier. It's nice to have some whitespace
404 # between projects when cloning. 404 # between projects when cloning.
405 self.Print('') 405 self.Print('')
406 return self._Capture(['rev-parse', '--verify', 'HEAD']) 406 return self._Capture(['rev-parse', '--verify', 'HEAD'])
407 407
408 if not managed: 408 if not managed:
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 493
494 if current_type == 'detached': 494 if current_type == 'detached':
495 # case 0 495 # case 0
496 self._CheckClean(rev_str) 496 self._CheckClean(rev_str)
497 self._CheckDetachedHead(rev_str, options) 497 self._CheckDetachedHead(rev_str, options)
498 if self._Capture(['rev-list', '-n', '1', 'HEAD']) == revision: 498 if self._Capture(['rev-list', '-n', '1', 'HEAD']) == revision:
499 self.Print('Up-to-date; skipping checkout.') 499 self.Print('Up-to-date; skipping checkout.')
500 else: 500 else:
501 # 'git checkout' may need to overwrite existing untracked files. Allow 501 # 'git checkout' may need to overwrite existing untracked files. Allow
502 # it only when nuclear options are enabled. 502 # it only when nuclear options are enabled.
503 if options.force and options.delete_unversioned_trees: 503 self._Checkout(
504 self._Capture(['checkout', '--force', '--quiet', '%s' % revision]) 504 options,
505 else: 505 revision,
506 self._Capture(['checkout', '--quiet', '%s' % revision]) 506 force=(options.force and options.delete_unversioned_trees),
507 quiet=True,
508 )
507 if not printed_path: 509 if not printed_path:
508 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False) 510 self.Print('_____ %s%s' % (self.relpath, rev_str), timestamp=False)
509 elif current_type == 'hash': 511 elif current_type == 'hash':
510 # case 1 512 # case 1
511 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None: 513 if scm.GIT.IsGitSvn(self.checkout_path) and upstream_branch is not None:
512 # Our git-svn branch (upstream_branch) is our upstream 514 # Our git-svn branch (upstream_branch) is our upstream
513 self._AttemptRebase(upstream_branch, files, options, 515 self._AttemptRebase(upstream_branch, files, options,
514 newbase=revision, printed_path=printed_path, 516 newbase=revision, printed_path=printed_path,
515 merge=options.merge) 517 merge=options.merge)
516 printed_path = True 518 printed_path = True
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'), 837 gclient_utils.safe_rename(os.path.join(tmp_dir, '.git'),
836 os.path.join(self.checkout_path, '.git')) 838 os.path.join(self.checkout_path, '.git'))
837 except: 839 except:
838 traceback.print_exc(file=self.out_fh) 840 traceback.print_exc(file=self.out_fh)
839 raise 841 raise
840 finally: 842 finally:
841 if os.listdir(tmp_dir): 843 if os.listdir(tmp_dir):
842 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir) 844 self.Print('_____ removing non-empty tmp dir %s' % tmp_dir)
843 gclient_utils.rmtree(tmp_dir) 845 gclient_utils.rmtree(tmp_dir)
844 self._UpdateBranchHeads(options, fetch=True) 846 self._UpdateBranchHeads(options, fetch=True)
845 self._Run(['checkout', '--quiet', revision.replace('refs/heads/', '')], 847 self._Checkout(options, revision.replace('refs/heads/', ''), quiet=True)
846 options)
847 if self._GetCurrentBranch() is None: 848 if self._GetCurrentBranch() is None:
848 # Squelch git's very verbose detached HEAD warning and use our own 849 # Squelch git's very verbose detached HEAD warning and use our own
849 self.Print( 850 self.Print(
850 ('Checked out %s to a detached HEAD. Before making any commits\n' 851 ('Checked out %s to a detached HEAD. Before making any commits\n'
851 'in this repo, you should use \'git checkout <branch>\' to switch to\n' 852 'in this repo, you should use \'git checkout <branch>\' to switch to\n'
852 'an existing branch or use \'git checkout %s -b <branch>\' to\n' 853 'an existing branch or use \'git checkout %s -b <branch>\' to\n'
853 'create a new branch for your work.') % (revision, self.remote)) 854 'create a new branch for your work.') % (revision, self.remote))
854 855
855 def _AskForData(self, prompt, options): 856 def _AskForData(self, prompt, options):
856 if options.jobs > 1: 857 if options.jobs > 1:
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
1009 if branch == 'HEAD': 1010 if branch == 'HEAD':
1010 return None 1011 return None
1011 return branch 1012 return branch
1012 1013
1013 def _Capture(self, args, **kwargs): 1014 def _Capture(self, args, **kwargs):
1014 kwargs.setdefault('cwd', self.checkout_path) 1015 kwargs.setdefault('cwd', self.checkout_path)
1015 kwargs.setdefault('stderr', subprocess2.PIPE) 1016 kwargs.setdefault('stderr', subprocess2.PIPE)
1016 env = scm.GIT.ApplyEnvVars(kwargs) 1017 env = scm.GIT.ApplyEnvVars(kwargs)
1017 return subprocess2.check_output(['git'] + args, env=env, **kwargs).strip() 1018 return subprocess2.check_output(['git'] + args, env=env, **kwargs).strip()
1018 1019
1020 def _Checkout(self, options, ref, force=False, quiet=None):
1021 """Performs a 'git-checkout' operation.
1022
1023 Args:
1024 options: The configured option set
1025 ref: (str) The branch/commit to checkout
1026 quiet: (bool/None) Whether or not the checkout shoud pass '--quiet'; if
1027 'None', the behavior is inferred from 'options.verbose'.
1028 Returns: (str) The output of the checkout operation
1029 """
1030 if quiet is None:
1031 quiet = (not options.verbose)
1032 checkout_args = ['checkout']
1033 if force:
1034 checkout_args.append('--force')
1035 if quiet:
1036 checkout_args.append('--quiet')
1037 checkout_args.append(ref)
1038 return self._Capture(checkout_args)
1039
1019 def _UpdateBranchHeads(self, options, fetch=False): 1040 def _UpdateBranchHeads(self, options, fetch=False):
1020 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" 1041 """Adds, and optionally fetches, "branch-heads" refspecs if requested."""
1021 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: 1042 if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
1022 config_cmd = ['config', 'remote.%s.fetch' % self.remote, 1043 config_cmd = ['config', 'remote.%s.fetch' % self.remote,
1023 '+refs/branch-heads/*:refs/remotes/branch-heads/*', 1044 '+refs/branch-heads/*:refs/remotes/branch-heads/*',
1024 '^\\+refs/branch-heads/\\*:.*$'] 1045 '^\\+refs/branch-heads/\\*:.*$']
1025 self._Run(config_cmd, options) 1046 self._Run(config_cmd, options)
1026 if fetch: 1047 if fetch:
1027 cfg = gclient_utils.DefaultIndexPackConfig(self.url) 1048 cfg = gclient_utils.DefaultIndexPackConfig(self.url)
1028 fetch_cmd = cfg + ['fetch', self.remote] 1049 fetch_cmd = cfg + ['fetch', self.remote]
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 new_command.append('--force') 1525 new_command.append('--force')
1505 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1526 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1506 new_command.extend(('--accept', 'theirs-conflict')) 1527 new_command.extend(('--accept', 'theirs-conflict'))
1507 elif options.manually_grab_svn_rev: 1528 elif options.manually_grab_svn_rev:
1508 new_command.append('--force') 1529 new_command.append('--force')
1509 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1530 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1510 new_command.extend(('--accept', 'postpone')) 1531 new_command.extend(('--accept', 'postpone'))
1511 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: 1532 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]:
1512 new_command.extend(('--accept', 'postpone')) 1533 new_command.extend(('--accept', 'postpone'))
1513 return new_command 1534 return new_command
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698