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 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import posixpath | 9 import posixpath |
| 10 import re | 10 import re |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 # Not a fatal error, or even very interesting in a non-git-submodule | 230 # Not a fatal error, or even very interesting in a non-git-submodule |
| 231 # world. So just keep it quiet. | 231 # world. So just keep it quiet. |
| 232 pass | 232 pass |
| 233 try: | 233 try: |
| 234 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) | 234 gclient_utils.CheckCallAndFilter(cmd3, **kwargs) |
| 235 except subprocess2.CalledProcessError: | 235 except subprocess2.CalledProcessError: |
| 236 gclient_utils.CheckCallAndFilter(cmd3 + ['always'], **kwargs) | 236 gclient_utils.CheckCallAndFilter(cmd3 + ['always'], **kwargs) |
| 237 | 237 |
| 238 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) | 238 gclient_utils.CheckCallAndFilter(cmd4, **kwargs) |
| 239 | 239 |
| 240 def _FetchAndReset(self, revision, file_list, options): | |
|
M-A Ruel
2013/06/11 19:01:36
"""Equivalent of git fetch; git reset."""
Mike Stip (use stip instead)
2013/06/11 20:38:54
Done.
| |
| 241 quiet = [] | |
| 242 if not options.verbose: | |
| 243 quiet = ['--quiet'] | |
| 244 self._UpdateBranchHeads(options, fetch=False) | |
| 245 self._Run(['fetch', 'origin', '--prune'] + quiet, options) | |
| 246 self._Run(['reset', '--hard', revision] + quiet, options) | |
| 247 self.UpdateSubmoduleConfig() | |
| 248 files = self._Capture(['ls-files']).splitlines() | |
| 249 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | |
| 250 | |
| 240 def update(self, options, args, file_list): | 251 def update(self, options, args, file_list): |
| 241 """Runs git to update or transparently checkout the working copy. | 252 """Runs git to update or transparently checkout the working copy. |
| 242 | 253 |
| 243 All updated files will be appended to file_list. | 254 All updated files will be appended to file_list. |
| 244 | 255 |
| 245 Raises: | 256 Raises: |
| 246 Error: if can't get URL for relative path. | 257 Error: if can't get URL for relative path. |
| 247 """ | 258 """ |
| 248 if args: | 259 if args: |
| 249 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) | 260 raise gclient_utils.Error("Unsupported argument(s): %s" % ",".join(args)) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 331 if (current_url != url and | 342 if (current_url != url and |
| 332 url != 'git://foo' and | 343 url != 'git://foo' and |
| 333 subprocess2.capture( | 344 subprocess2.capture( |
| 334 ['git', 'config', 'remote.origin.gclient-auto-fix-url'], | 345 ['git', 'config', 'remote.origin.gclient-auto-fix-url'], |
| 335 cwd=self.checkout_path).strip() != 'False'): | 346 cwd=self.checkout_path).strip() != 'False'): |
| 336 print('_____ switching %s to a new upstream' % self.relpath) | 347 print('_____ switching %s to a new upstream' % self.relpath) |
| 337 # Make sure it's clean | 348 # Make sure it's clean |
| 338 self._CheckClean(rev_str) | 349 self._CheckClean(rev_str) |
| 339 # Switch over to the new upstream | 350 # Switch over to the new upstream |
| 340 self._Run(['remote', 'set-url', 'origin', url], options) | 351 self._Run(['remote', 'set-url', 'origin', url], options) |
| 341 quiet = [] | 352 self._FetchAndReset(revision, file_list, options) |
| 342 if not options.verbose: | |
| 343 quiet = ['--quiet'] | |
| 344 self._UpdateBranchHeads(options, fetch=False) | |
| 345 self._Run(['fetch', 'origin', '--prune'] + quiet, options) | |
| 346 self._Run(['reset', '--hard', revision] + quiet, options) | |
| 347 self.UpdateSubmoduleConfig() | |
| 348 files = self._Capture(['ls-files']).splitlines() | |
| 349 file_list.extend([os.path.join(self.checkout_path, f) for f in files]) | |
| 350 return | 353 return |
| 351 | 354 |
| 355 if not self._IsValidGitRepo(options): | |
| 356 # .git directory is hosed for some reason, set it back up. | |
| 357 print('_____ %s/.git is corrupted, rebuilding' % self.relpath) | |
| 358 self._Run(['init'], options) | |
| 359 self._Run(['remote', 'set-url', 'origin', url], options) | |
| 360 | |
| 361 if not self._HasHead(): | |
| 362 # Previous checkout was aborted before branches could be created in repo, | |
| 363 # so we need to reconstruct them here. | |
| 364 self._Run(['pull', 'origin', 'master'], options) | |
|
M-A Ruel
2013/06/11 19:01:36
Why pull when you're about to fetch right after?
Mike Stip (use stip instead)
2013/06/11 20:38:54
Pull sets up the remote tracking branches (includi
M-A Ruel
2013/06/11 22:43:50
ORLY? Wow.
| |
| 365 self._FetchAndReset(revision, file_list, options) | |
| 366 | |
| 352 cur_branch = self._GetCurrentBranch() | 367 cur_branch = self._GetCurrentBranch() |
| 353 | 368 |
| 354 # Cases: | 369 # Cases: |
| 355 # 0) HEAD is detached. Probably from our initial clone. | 370 # 0) HEAD is detached. Probably from our initial clone. |
| 356 # - make sure HEAD is contained by a named ref, then update. | 371 # - make sure HEAD is contained by a named ref, then update. |
| 357 # Cases 1-4. HEAD is a branch. | 372 # Cases 1-4. HEAD is a branch. |
| 358 # 1) current branch is not tracking a remote branch (could be git-svn) | 373 # 1) current branch is not tracking a remote branch (could be git-svn) |
| 359 # - try to rebase onto the new hash or branch | 374 # - try to rebase onto the new hash or branch |
| 360 # 2) current branch is tracking a remote branch with local committed | 375 # 2) current branch is tracking a remote branch with local committed |
| 361 # changes, but the DEPS file switched to point to a hash | 376 # changes, but the DEPS file switched to point to a hash |
| (...skipping 432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 "manually.\ncd %s && git " % | 809 "manually.\ncd %s && git " % |
| 795 self.checkout_path | 810 self.checkout_path |
| 796 + "%s" % ' '.join(rebase_cmd)) | 811 + "%s" % ' '.join(rebase_cmd)) |
| 797 | 812 |
| 798 print(rebase_output.strip()) | 813 print(rebase_output.strip()) |
| 799 if not options.verbose: | 814 if not options.verbose: |
| 800 # Make the output a little prettier. It's nice to have some | 815 # Make the output a little prettier. It's nice to have some |
| 801 # whitespace between projects when syncing. | 816 # whitespace between projects when syncing. |
| 802 print('') | 817 print('') |
| 803 | 818 |
| 819 def _IsValidGitRepo(self, options): | |
| 820 """Check if git status works in the current repository.""" | |
|
M-A Ruel
2013/06/11 19:01:36
"""Returns if the directory is a valid git reposit
Mike Stip (use stip instead)
2013/06/11 20:38:54
Done.
| |
| 821 try: | |
| 822 self._Run(['status'], options) | |
| 823 return True | |
| 824 except subprocess2.CalledProcessError: | |
| 825 return False | |
| 826 | |
| 827 def _HasHead(self): | |
| 828 """Check if rev-parse HEAD works in the current repository.""" | |
|
M-A Ruel
2013/06/11 19:01:36
"""Returns True if any commit is checked out.
Thi
| |
| 829 try: | |
| 830 self._GetCurrentBranch() | |
| 831 return True | |
| 832 except subprocess2.CalledProcessError: | |
| 833 return False | |
| 834 | |
| 804 @staticmethod | 835 @staticmethod |
| 805 def _CheckMinVersion(min_version): | 836 def _CheckMinVersion(min_version): |
| 806 (ok, current_version) = scm.GIT.AssertVersion(min_version) | 837 (ok, current_version) = scm.GIT.AssertVersion(min_version) |
| 807 if not ok: | 838 if not ok: |
| 808 raise gclient_utils.Error('git version %s < minimum required %s' % | 839 raise gclient_utils.Error('git version %s < minimum required %s' % |
| 809 (current_version, min_version)) | 840 (current_version, min_version)) |
| 810 | 841 |
| 811 def _IsRebasing(self): | 842 def _IsRebasing(self): |
| 812 # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't | 843 # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't |
| 813 # have a plumbing command to determine whether a rebase is in progress, so | 844 # have a plumbing command to determine whether a rebase is in progress, so |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1291 new_command.append('--force') | 1322 new_command.append('--force') |
| 1292 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1323 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1293 new_command.extend(('--accept', 'theirs-conflict')) | 1324 new_command.extend(('--accept', 'theirs-conflict')) |
| 1294 elif options.manually_grab_svn_rev: | 1325 elif options.manually_grab_svn_rev: |
| 1295 new_command.append('--force') | 1326 new_command.append('--force') |
| 1296 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1327 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1297 new_command.extend(('--accept', 'postpone')) | 1328 new_command.extend(('--accept', 'postpone')) |
| 1298 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1329 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
| 1299 new_command.extend(('--accept', 'postpone')) | 1330 new_command.extend(('--accept', 'postpone')) |
| 1300 return new_command | 1331 return new_command |
| OLD | NEW |