OLD | NEW |
1 # Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2009 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 logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 cwd=self._root_dir, redirect_stdout=False) | 133 cwd=self._root_dir, redirect_stdout=False) |
134 if revision: | 134 if revision: |
135 self._Run(['reset', '--hard', revision], redirect_stdout=False) | 135 self._Run(['reset', '--hard', revision], redirect_stdout=False) |
136 files = self._Run(['ls-files']).split() | 136 files = self._Run(['ls-files']).split() |
137 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 137 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
138 return | 138 return |
139 | 139 |
140 new_base = 'origin' | 140 new_base = 'origin' |
141 if revision: | 141 if revision: |
142 new_base = revision | 142 new_base = revision |
143 cur_branch = self._Run(['symbolic-ref', 'HEAD']).split('/')[-1] | 143 cur_branch = self._GetCurrentBranch() |
| 144 |
| 145 # Check if we are in a rebase conflict |
| 146 if cur_branch is None: |
| 147 raise gclient_utils.Error('\n____ %s%s\n' |
| 148 '\tAlready in a conflict, i.e. (no branch).\n' |
| 149 '\tFix the conflict and run gclient again.\n' |
| 150 '\tOr to abort run:\n\t\tgit-rebase --abort\n' |
| 151 '\tSee man git-rebase for details.\n' |
| 152 % (self.relpath, rev_str)) |
| 153 |
144 merge_base = self._Run(['merge-base', 'HEAD', new_base]) | 154 merge_base = self._Run(['merge-base', 'HEAD', new_base]) |
145 self._Run(['remote', 'update'], redirect_stdout=False) | 155 self._Run(['remote', 'update'], redirect_stdout=False) |
146 files = self._Run(['diff', new_base, '--name-only']).split() | 156 files = self._Run(['diff', new_base, '--name-only']).split() |
147 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | 157 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
148 self._Run(['rebase', '-v', '--onto', new_base, merge_base, cur_branch], | 158 self._Run(['rebase', '-v', '--onto', new_base, merge_base, cur_branch], |
149 redirect_stdout=False) | 159 redirect_stdout=False, checkrc=False) |
| 160 |
| 161 # If the rebase generated a conflict, abort and ask user to fix |
| 162 if self._GetCurrentBranch() is None: |
| 163 raise gclient_utils.Error('\n____ %s%s\n' |
| 164 '\nConflict while rebasing this branch.\n' |
| 165 'Fix the conflict and run gclient again.\n' |
| 166 'See man git-rebase for details.\n' |
| 167 % (self.relpath, rev_str)) |
| 168 |
150 print "Checked out revision %s." % self.revinfo(options, (), None) | 169 print "Checked out revision %s." % self.revinfo(options, (), None) |
151 | 170 |
152 def revert(self, options, args, file_list): | 171 def revert(self, options, args, file_list): |
153 """Reverts local modifications. | 172 """Reverts local modifications. |
154 | 173 |
155 All reverted files will be appended to file_list. | 174 All reverted files will be appended to file_list. |
156 """ | 175 """ |
157 __pychecker__ = 'unusednames=args' | 176 __pychecker__ = 'unusednames=args' |
158 path = os.path.join(self._root_dir, self.relpath) | 177 path = os.path.join(self._root_dir, self.relpath) |
159 if not os.path.isdir(path): | 178 if not os.path.isdir(path): |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 version_list = map(only_int, version.split('.')) | 216 version_list = map(only_int, version.split('.')) |
198 min_version_list = map(int, min_version.split('.')) | 217 min_version_list = map(int, min_version.split('.')) |
199 for min_ver in min_version_list: | 218 for min_ver in min_version_list: |
200 ver = version_list.pop(0) | 219 ver = version_list.pop(0) |
201 if min_ver > ver: | 220 if min_ver > ver: |
202 raise gclient_utils.Error('git version %s < minimum required %s' % | 221 raise gclient_utils.Error('git version %s < minimum required %s' % |
203 (version, min_version)) | 222 (version, min_version)) |
204 elif min_ver < ver: | 223 elif min_ver < ver: |
205 return | 224 return |
206 | 225 |
| 226 def _GetCurrentBranch(self): |
| 227 # Returns name of current branch |
| 228 # Returns None if inside a (no branch) |
| 229 tokens = self._Run(['branch']).split() |
| 230 branch = tokens[tokens.index('*') + 1] |
| 231 if branch == '(no': |
| 232 return None |
| 233 return branch |
| 234 |
207 def _Run(self, args, cwd=None, checkrc=True, redirect_stdout=True): | 235 def _Run(self, args, cwd=None, checkrc=True, redirect_stdout=True): |
208 # TODO(maruel): Merge with Capture? | 236 # TODO(maruel): Merge with Capture? |
209 if cwd is None: | 237 if cwd is None: |
210 cwd = self.checkout_path | 238 cwd = self.checkout_path |
211 stdout=None | 239 stdout=None |
212 if redirect_stdout: | 240 if redirect_stdout: |
213 stdout=subprocess.PIPE | 241 stdout=subprocess.PIPE |
214 if cwd == None: | 242 if cwd == None: |
215 cwd = self.checkout_path | 243 cwd = self.checkout_path |
216 cmd = [self.COMMAND] | 244 cmd = [self.COMMAND] |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 self.ReplaceAndPrint(line) | 507 self.ReplaceAndPrint(line) |
480 else: | 508 else: |
481 if (line.startswith(self.original_prefix) or | 509 if (line.startswith(self.original_prefix) or |
482 line.startswith(self.working_prefix)): | 510 line.startswith(self.working_prefix)): |
483 self.ReplaceAndPrint(line) | 511 self.ReplaceAndPrint(line) |
484 else: | 512 else: |
485 print line | 513 print line |
486 | 514 |
487 filterer = DiffFilterer(self.relpath) | 515 filterer = DiffFilterer(self.relpath) |
488 self.RunAndFilterOutput(command, path, False, False, filterer.Filter) | 516 self.RunAndFilterOutput(command, path, False, False, filterer.Filter) |
OLD | NEW |