Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHiroshi Tomita2013-06-30 16:07:10 +0000
committerHiroshi Tomita2013-07-01 13:37:48 +0000
commit6845bb5b3e46785f940d1830e08645711ffc1273 (patch)
treead3506bbd592d35e9f234d2dfb0485395be6c316
parenta2e5653d5af56e190102624159d734efd0a4f4c0 (diff)
downloadjgit-6845bb5b3e46785f940d1830e08645711ffc1273.tar.gz
jgit-6845bb5b3e46785f940d1830e08645711ffc1273.tar.xz
jgit-6845bb5b3e46785f940d1830e08645711ffc1273.zip
Update HEAD in cherry-picking several commits
Without update, index is wrongly detected to be dirty when picking the second commit. Change-Id: Idf47ecb33e8bd38340d760806d629f67be92d2d5 Signed-off-by: Hiroshi Tomita <tomykaira@gmail.com> Bug: 411963
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java36
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java9
2 files changed, 40 insertions, 5 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index f66661a52f..2668c116a0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -111,6 +111,42 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertFalse(history.hasNext());
}
+ @Test
+ public void testSequentialCherryPick() throws IOException, JGitInternalException,
+ GitAPIException {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "first line\nsec. line\nthird line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit firstCommit = git.commit().setMessage("create a").call();
+
+ writeTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit enlargingA = git.commit().setMessage("enlarged a").call();
+
+ writeTrashFile("a",
+ "first line\nsecond line\nthird line\nfourth line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit fixingA = git.commit().setMessage("fixed a").call();
+
+ git.branchCreate().setName("side").setStartPoint(firstCommit).call();
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("b", "nothing to do with a");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("create b").call();
+
+ CherryPickResult result = git.cherryPick().include(enlargingA).include(fixingA).call();
+ assertEquals(CherryPickResult.CherryPickStatus.OK, result.getStatus());
+
+ Iterator<RevCommit> history = git.log().call().iterator();
+ assertEquals("fixed a", history.next().getFullMessage());
+ assertEquals("enlarged a", history.next().getFullMessage());
+ assertEquals("create b", history.next().getFullMessage());
+ assertEquals("create a", history.next().getFullMessage());
+ assertFalse(history.hasNext());
+ }
+
@Test
public void testCherryPickDirtyIndex() throws Exception {
Git git = new Git(db);
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
index d5d9559296..2ebff14f9c 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CherryPickCommand.java
@@ -122,9 +122,8 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
if (headRef == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
- RevCommit headCommit = revWalk.parseCommit(headRef.getObjectId());
- newHead = headCommit;
+ newHead = revWalk.parseCommit(headRef.getObjectId());
// loop through all refs to be cherry-picked
for (Ref src : commits) {
@@ -156,12 +155,12 @@ public class CherryPickCommand extends GitCommand<CherryPickResult> {
merger.setBase(srcParent.getTree());
merger.setCommitNames(new String[] { "BASE", ourName,
cherryPickName });
- if (merger.merge(headCommit, srcCommit)) {
- if (AnyObjectId.equals(headCommit.getTree().getId(), merger
+ if (merger.merge(newHead, srcCommit)) {
+ if (AnyObjectId.equals(newHead.getTree().getId(), merger
.getResultTreeId()))
continue;
DirCacheCheckout dco = new DirCacheCheckout(repo,
- headCommit.getTree(), repo.lockDirCache(),
+ newHead.getTree(), repo.lockDirCache(),
merger.getResultTreeId());
dco.setFailOnConflict(true);
dco.checkout();

Back to the top