diff --git a/gclient_scm.py b/gclient_scm.py index a4c0dfd83..70ec6a95c 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -550,14 +550,21 @@ class GitWrapper(SCMWrapper): self._Clone(revision, url, options) if file_list is not None: files = self._Capture( - ['-c', 'core.quotePath=false', 'ls-files']).splitlines() + ['-c', 'core.quotePath=false', 'ls-files']).splitlines() file_list.extend([os.path.join(self.checkout_path, f) for f in files]) + if mirror: + self._Capture( + ['remote', 'set-url', '--push', 'origin', mirror.url]) if not verbose: # Make the output a little prettier. It's nice to have some whitespace # between projects when cloning. self.Print('') return self._Capture(['rev-parse', '--verify', 'HEAD']) + if mirror: + self._Capture( + ['remote', 'set-url', '--push', 'origin', mirror.url]) + if not managed: self._SetFetchConfig(options) self.Print('________ unmanaged solution; skipping %s' % self.relpath) diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 123167a94..6ae2ff992 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -570,6 +570,41 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase): rev_info = scm.revinfo(options, (), None) self.assertEquals(rev_info, '069c602044c5388d2d15c3f875b057c852003458') + def testMirrorPushUrl(self): + if not self.enabled: + return + fakes = fake_repos.FakeRepos() + fakes.set_up_git() + self.url = fakes.git_base + 'repo_1' + self.root_dir = fakes.root_dir + self.addCleanup(fake_repos.FakeRepos.tear_down_git, fakes) + + mirror = tempfile.mkdtemp() + self.addCleanup(rmtree, mirror) + + # This should never happen, but if it does, it'd render the other assertions + # in this test meaningless. + self.assertFalse(self.url.startswith(mirror)) + + git_cache.Mirror.SetCachePath(mirror) + self.addCleanup(git_cache.Mirror.SetCachePath, None) + + options = self.Options() + scm = gclient_scm.GitWrapper(self.url, self.root_dir, self.relpath) + self.assertIsNotNone(scm._GetMirror(self.url, options)) + scm.update(options, (), []) + + fetch_url = scm._Capture(['remote', 'get-url', 'origin']) + self.assertTrue( + fetch_url.startswith(mirror), + msg='\n'.join([ + 'Repository fetch url should be in the git cache mirror directory.', + ' fetch_url: %s' % fetch_url, + ' mirror: %s' % mirror])) + push_url = scm._Capture(['remote', 'get-url', '--push', 'origin']) + self.assertEquals(push_url, self.url) + sys.stdout.close() + class ManagedGitWrapperTestCaseMox(BaseTestCase): class OptionsObject(object):