diff --git a/gclient_scm.py b/gclient_scm.py index 3b1b59f7a..8acc4250c 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -698,15 +698,24 @@ class GitWrapper(SCMWrapper): # Switch over to the new upstream self._Run(['remote', 'set-url', self.remote, url], options) if mirror: - # Because we use Git alternatives, our existing repository is not - # self-contained. It's possible that new git alternative doesn't have - # all necessary objects that the current repository needs. Instead of - # blindly hoping that new alternative contains all necessary objects, - # keep the old alternative and just append a new one on top of it. - with open(os.path.join( - self.checkout_path, '.git', 'objects', 'info', 'alternates'), - 'a') as fh: - fh.write("\n" + os.path.join(url, 'objects')) + if git_cache.Mirror.CacheDirToUrl( + current_url.rstrip('/')) == git_cache.Mirror.CacheDirToUrl( + url.rstrip('/')): + # Reset alternates when the cache dir is updated. + with open( + os.path.join(self.checkout_path, '.git', 'objects', 'info', + 'alternates'), 'w') as fh: + fh.write(os.path.join(url, 'objects')) + else: + # Because we use Git alternatives, our existing repository is not + # self-contained. It's possible that new git alternative doesn't have + # all necessary objects that the current repository needs. Instead of + # blindly hoping that new alternative contains all necessary objects, + # keep the old alternative and just append a new one on top of it. + with open( + os.path.join(self.checkout_path, '.git', 'objects', 'info', + 'alternates'), 'a') as fh: + fh.write("\n" + os.path.join(url, 'objects')) self._EnsureValidHeadObjectOrCheckout(revision, options, url) self._FetchAndReset(revision, file_list, options)