diff --git a/gclient_scm.py b/gclient_scm.py index 4debb299bd..6301010dd6 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -417,8 +417,6 @@ class GitWrapper(SCMWrapper): self.Print('===Applying patch===') self.Print('Revision to patch is %r @ %r.' % (patch_repo, patch_rev)) - self.Print('Will cherrypick %r .. %r on top of %r.' % ( - target_rev, patch_rev, base_rev)) self.Print('Current dir is %r' % self.checkout_path) self._Capture(['reset', '--hard']) self._Capture(['fetch', patch_repo, patch_rev]) @@ -426,7 +424,15 @@ class GitWrapper(SCMWrapper): if not options.rebase_patch_ref: self._Capture(['checkout', patch_rev]) + # Adjust base_rev to be the first parent of our checked out patch ref; + # This will allow us to correctly extend `file_list`, and will show the + # correct file-list to programs which do `git diff --cached` expecting to + # see the patch diff. + base_rev = self._Capture(['rev-parse', patch_rev+'~']) + else: + self.Print('Will cherrypick %r .. %r on top of %r.' % ( + target_rev, patch_rev, base_rev)) try: if scm.GIT.IsAncestor(self.checkout_path, patch_rev, target_rev): # If |patch_rev| is an ancestor of |target_rev|, check it out. diff --git a/tests/gclient_scm_test.py b/tests/gclient_scm_test.py index 9b53902df7..f7490e1fe1 100755 --- a/tests/gclient_scm_test.py +++ b/tests/gclient_scm_test.py @@ -1217,7 +1217,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase): file_list) self.assertCommits([1, 2, 3, 5, 6]) - self.assertEqual(self.githash('repo_1', 4), self.gitrevparse(self.root_dir)) + self.assertEqual(self.githash('repo_1', 5), self.gitrevparse(self.root_dir)) def testDoesntRebasePatchOldCheckout(self): """Tests that we can apply a patch without rebasing it on an old checkout. @@ -1237,7 +1237,7 @@ class GerritChangesTest(fake_repos.FakeReposTestBase): file_list) self.assertCommits([1, 2, 3, 5, 6]) - self.assertEqual(self.githash('repo_1', 1), self.gitrevparse(self.root_dir)) + self.assertEqual(self.githash('repo_1', 5), self.gitrevparse(self.root_dir)) def testDoesntSoftResetIfNotAskedTo(self): """Test that we can apply a patch without doing a soft reset."""