diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java index 71df59e1f..498005ded 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java @@ -154,7 +154,7 @@ public class CheckoutCommandTest extends RepositoryTestCase { } @Test - public void testCheckoutWithConflict() { + public void testCheckoutWithConflict() throws Exception { CheckoutCommand co = git.checkout(); try { writeTrashFile("Test.txt", "Another change"); @@ -165,6 +165,8 @@ public class CheckoutCommandTest extends RepositoryTestCase { assertEquals(Status.CONFLICTS, co.getResult().getStatus()); assertTrue(co.getResult().getConflictList().contains("Test.txt")); } + git.checkout().setName("master").setForce(true).call(); + assertThat(read("Test.txt"), is("Hello world")); } @Test diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index 11edb1089..455a2e665 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -269,7 +269,7 @@ public class CheckoutCommand extends GitCommand { try { dco = new DirCacheCheckout(repo, headTree, dc, newCommit.getTree()); - dco.setFailOnConflict(true); + dco.setFailOnConflict(!force); dco.setProgressMonitor(monitor); try { dco.checkout(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java index ca1e3ab27..db6073f89 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCacheCheckout.java @@ -522,7 +522,7 @@ public class DirCacheCheckout { builder.finish(); // init progress reporting - int numTotal = removed.size() + updated.size(); + int numTotal = removed.size() + updated.size() + conflicts.size(); monitor.beginTask(JGitText.get().checkingOutFiles, numTotal); performingCheckout = true; @@ -597,6 +597,33 @@ public class DirCacheCheckout { } throw ex; } + for (String conflict : conflicts) { + // the conflicts are likely to have multiple entries in the + // dircache, we only want to check out the one for the "theirs" + // tree + int entryIdx = dc.findEntry(conflict); + if (entryIdx >= 0) { + while (entryIdx < dc.getEntryCount()) { + DirCacheEntry entry = dc.getEntry(entryIdx); + if (!entry.getPathString().equals(conflict)) { + break; + } + if (entry.getStage() == DirCacheEntry.STAGE_3) { + checkoutEntry(repo, entry, objectReader, false, + null); + break; + } + ++entryIdx; + } + } + + monitor.update(1); + if (monitor.isCancelled()) { + throw new CanceledException(MessageFormat.format( + JGitText.get().operationCanceled, + JGitText.get().checkingOutFiles)); + } + } monitor.endTask(); // commit the index builder - a new index is persisted