}
@Test
- public void testCheckoutWithConflict() {
+ public void testCheckoutWithConflict() throws Exception {
CheckoutCommand co = git.checkout();
try {
writeTrashFile("Test.txt", "Another change");
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
try {
dco = new DirCacheCheckout(repo, headTree, dc,
newCommit.getTree());
- dco.setFailOnConflict(true);
+ dco.setFailOnConflict(!force);
dco.setProgressMonitor(monitor);
try {
dco.checkout();
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;
}
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