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 logging | 9 import logging |
10 import os | 10 import os |
(...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
953 def _GetCurrentBranch(self): | 953 def _GetCurrentBranch(self): |
954 # Returns name of current branch or None for detached HEAD | 954 # Returns name of current branch or None for detached HEAD |
955 branch = self._Capture(['rev-parse', '--abbrev-ref=strict', 'HEAD']) | 955 branch = self._Capture(['rev-parse', '--abbrev-ref=strict', 'HEAD']) |
956 if branch == 'HEAD': | 956 if branch == 'HEAD': |
957 return None | 957 return None |
958 return branch | 958 return branch |
959 | 959 |
960 def _Capture(self, args, **kwargs): | 960 def _Capture(self, args, **kwargs): |
961 kwargs.setdefault('cwd', self.checkout_path) | 961 kwargs.setdefault('cwd', self.checkout_path) |
962 kwargs.setdefault('stderr', subprocess2.PIPE) | 962 kwargs.setdefault('stderr', subprocess2.PIPE) |
963 return subprocess2.check_output(['git'] + args, **kwargs).strip() | 963 env = scm.GIT.ApplyEnvVars(kwargs) |
| 964 return subprocess2.check_output(['git'] + args, env=env, **kwargs).strip() |
964 | 965 |
965 def _UpdateBranchHeads(self, options, fetch=False): | 966 def _UpdateBranchHeads(self, options, fetch=False): |
966 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" | 967 """Adds, and optionally fetches, "branch-heads" refspecs if requested.""" |
967 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: | 968 if hasattr(options, 'with_branch_heads') and options.with_branch_heads: |
968 config_cmd = ['config', 'remote.%s.fetch' % self.remote, | 969 config_cmd = ['config', 'remote.%s.fetch' % self.remote, |
969 '+refs/branch-heads/*:refs/remotes/branch-heads/*', | 970 '+refs/branch-heads/*:refs/remotes/branch-heads/*', |
970 '^\\+refs/branch-heads/\\*:.*$'] | 971 '^\\+refs/branch-heads/\\*:.*$'] |
971 self._Run(config_cmd, options) | 972 self._Run(config_cmd, options) |
972 if fetch: | 973 if fetch: |
973 cfg = gclient_utils.DefaultIndexPackConfig(self.url) | 974 cfg = gclient_utils.DefaultIndexPackConfig(self.url) |
974 fetch_cmd = cfg + ['fetch', self.remote] | 975 fetch_cmd = cfg + ['fetch', self.remote] |
975 if options.verbose: | 976 if options.verbose: |
976 fetch_cmd.append('--verbose') | 977 fetch_cmd.append('--verbose') |
977 self._Run(fetch_cmd, options, retry=True) | 978 self._Run(fetch_cmd, options, retry=True) |
978 | 979 |
979 def _Run(self, args, options, **kwargs): | 980 def _Run(self, args, options, **kwargs): |
980 cwd = kwargs.setdefault('cwd', self.checkout_path) | 981 cwd = kwargs.setdefault('cwd', self.checkout_path) |
981 kwargs.setdefault('stdout', self.out_fh) | 982 kwargs.setdefault('stdout', self.out_fh) |
982 kwargs['filter_fn'] = self.filter | 983 kwargs['filter_fn'] = self.filter |
983 kwargs.setdefault('print_stdout', False) | 984 kwargs.setdefault('print_stdout', False) |
984 # Don't prompt for passwords; just fail quickly and noisily. | 985 env = scm.GIT.ApplyEnvVars(kwargs) |
985 # By default, git will use an interactive terminal prompt when a username/ | |
986 # password is needed. That shouldn't happen in the chromium workflow, | |
987 # and if it does, then gclient may hide the prompt in the midst of a flood | |
988 # of terminal spew. The only indication that something has gone wrong | |
989 # will be when gclient hangs unresponsively. Instead, we disable the | |
990 # password prompt and simply allow git to fail noisily. The error | |
991 # message produced by git will be copied to gclient's output. | |
992 env = kwargs.get('env') or kwargs.setdefault('env', os.environ.copy()) | |
993 env.setdefault('GIT_ASKPASS', 'true') | |
994 env.setdefault('SSH_ASKPASS', 'true') | |
995 | |
996 cmd = ['git'] + args | 986 cmd = ['git'] + args |
997 header = "running '%s' in '%s'" % (' '.join(cmd), cwd) | 987 header = "running '%s' in '%s'" % (' '.join(cmd), cwd) |
998 self.filter(header) | 988 self.filter(header) |
999 return gclient_utils.CheckCallAndFilter(cmd, **kwargs) | 989 return gclient_utils.CheckCallAndFilter(cmd, env=env, **kwargs) |
1000 | 990 |
1001 | 991 |
1002 class SVNWrapper(SCMWrapper): | 992 class SVNWrapper(SCMWrapper): |
1003 """ Wrapper for SVN """ | 993 """ Wrapper for SVN """ |
1004 name = 'svn' | 994 name = 'svn' |
1005 | 995 |
1006 @staticmethod | 996 @staticmethod |
1007 def BinaryExists(): | 997 def BinaryExists(): |
1008 """Returns true if the command exists.""" | 998 """Returns true if the command exists.""" |
1009 try: | 999 try: |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 new_command.append('--force') | 1451 new_command.append('--force') |
1462 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1452 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1463 new_command.extend(('--accept', 'theirs-conflict')) | 1453 new_command.extend(('--accept', 'theirs-conflict')) |
1464 elif options.manually_grab_svn_rev: | 1454 elif options.manually_grab_svn_rev: |
1465 new_command.append('--force') | 1455 new_command.append('--force') |
1466 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1456 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1467 new_command.extend(('--accept', 'postpone')) | 1457 new_command.extend(('--accept', 'postpone')) |
1468 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1458 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1469 new_command.extend(('--accept', 'postpone')) | 1459 new_command.extend(('--accept', 'postpone')) |
1470 return new_command | 1460 return new_command |
OLD | NEW |