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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
454 if not (options.force or options.reset): | 454 if not (options.force or options.reset): |
455 # Make sure it's clean | 455 # Make sure it's clean |
456 self._CheckClean(rev_str) | 456 self._CheckClean(rev_str) |
457 # Switch over to the new upstream | 457 # Switch over to the new upstream |
458 self._Run(['remote', 'set-url', self.remote, url], options) | 458 self._Run(['remote', 'set-url', self.remote, url], options) |
459 if mirror: | 459 if mirror: |
460 with open(os.path.join( | 460 with open(os.path.join( |
461 self.checkout_path, '.git', 'objects', 'info', 'alternates'), | 461 self.checkout_path, '.git', 'objects', 'info', 'alternates'), |
462 'w') as fh: | 462 'w') as fh: |
463 fh.write(os.path.join(url, 'objects')) | 463 fh.write(os.path.join(url, 'objects')) |
464 self._EnsureValidHeadObjectOrCheckout(revision, options, url) | |
464 self._FetchAndReset(revision, file_list, options) | 465 self._FetchAndReset(revision, file_list, options) |
466 | |
465 return_early = True | 467 return_early = True |
468 else: | |
469 self._EnsureValidHeadObjectOrCheckout(revision, options, url) | |
466 | 470 |
467 if return_early: | 471 if return_early: |
468 return self._Capture(['rev-parse', '--verify', 'HEAD']) | 472 return self._Capture(['rev-parse', '--verify', 'HEAD']) |
469 | 473 |
470 cur_branch = self._GetCurrentBranch() | 474 cur_branch = self._GetCurrentBranch() |
471 | 475 |
472 # Cases: | 476 # Cases: |
473 # 0) HEAD is detached. Probably from our initial clone. | 477 # 0) HEAD is detached. Probably from our initial clone. |
474 # - make sure HEAD is contained by a named ref, then update. | 478 # - make sure HEAD is contained by a named ref, then update. |
475 # Cases 1-4. HEAD is a branch. | 479 # Cases 1-4. HEAD is a branch. |
(...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1032 # whitespace between projects when syncing. | 1036 # whitespace between projects when syncing. |
1033 self.Print('') | 1037 self.Print('') |
1034 | 1038 |
1035 @staticmethod | 1039 @staticmethod |
1036 def _CheckMinVersion(min_version): | 1040 def _CheckMinVersion(min_version): |
1037 (ok, current_version) = scm.GIT.AssertVersion(min_version) | 1041 (ok, current_version) = scm.GIT.AssertVersion(min_version) |
1038 if not ok: | 1042 if not ok: |
1039 raise gclient_utils.Error('git version %s < minimum required %s' % | 1043 raise gclient_utils.Error('git version %s < minimum required %s' % |
1040 (current_version, min_version)) | 1044 (current_version, min_version)) |
1041 | 1045 |
1046 def _EnsureValidHeadObjectOrCheckout(self, revision, options, url): | |
1047 # Special case handling if all 3 conditions are met: | |
1048 # * the mirros have recently changed, but deps destination remains same, | |
1049 # * the git histories of mirrors are conflicting. | |
1050 # * git cache is used | |
1051 # This manifests itself in current checkout having invalid HEAD commit on | |
1052 # most git operations. Since git cache is used, just deleted the .git | |
1053 # folder, and re-create it by cloning. | |
1054 try: | |
1055 self._Capture(['rev-list', '-n', '1', 'HEAD']) | |
1056 except subprocess2.CalledProcessError as e: | |
1057 if ('fatal: bad object HEAD' in e.stderr | |
Ryan Tseng
2015/08/24 22:40:46
This sort of error detection scares me :/. Theres
tandrii(chromium)
2015/08/25 08:00:52
So, I thought this way:
best case -> it works
ok
| |
1058 and self.cache_dir and self.cache_dir in url): | |
1059 self.Print(( | |
1060 'Likely due to DEPS change with git cache_dir, ' | |
1061 'the current commit points to no longer existing object.\n' | |
1062 '%s' % e) | |
1063 ) | |
1064 self._DeleteOrMove(options.force) | |
1065 self._Clone(revision, url, options) | |
1066 else: | |
1067 raise | |
1068 | |
1042 def _IsRebasing(self): | 1069 def _IsRebasing(self): |
1043 # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't | 1070 # Check for any of REBASE-i/REBASE-m/REBASE/AM. Unfortunately git doesn't |
1044 # have a plumbing command to determine whether a rebase is in progress, so | 1071 # have a plumbing command to determine whether a rebase is in progress, so |
1045 # for now emualate (more-or-less) git-rebase.sh / git-completion.bash | 1072 # for now emualate (more-or-less) git-rebase.sh / git-completion.bash |
1046 g = os.path.join(self.checkout_path, '.git') | 1073 g = os.path.join(self.checkout_path, '.git') |
1047 return ( | 1074 return ( |
1048 os.path.isdir(os.path.join(g, "rebase-merge")) or | 1075 os.path.isdir(os.path.join(g, "rebase-merge")) or |
1049 os.path.isdir(os.path.join(g, "rebase-apply"))) | 1076 os.path.isdir(os.path.join(g, "rebase-apply"))) |
1050 | 1077 |
1051 def _CheckClean(self, rev_str): | 1078 def _CheckClean(self, rev_str): |
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1654 new_command.append('--force') | 1681 new_command.append('--force') |
1655 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1682 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1656 new_command.extend(('--accept', 'theirs-conflict')) | 1683 new_command.extend(('--accept', 'theirs-conflict')) |
1657 elif options.manually_grab_svn_rev: | 1684 elif options.manually_grab_svn_rev: |
1658 new_command.append('--force') | 1685 new_command.append('--force') |
1659 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1686 if command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1660 new_command.extend(('--accept', 'postpone')) | 1687 new_command.extend(('--accept', 'postpone')) |
1661 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: | 1688 elif command[0] != 'checkout' and scm.SVN.AssertVersion('1.6')[0]: |
1662 new_command.extend(('--accept', 'postpone')) | 1689 new_command.extend(('--accept', 'postpone')) |
1663 return new_command | 1690 return new_command |
OLD | NEW |