diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index e690ad696..3651542fc 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -47,6 +47,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.io.File; import java.nio.file.Files; @@ -236,8 +237,8 @@ public class CheckoutTest extends CLIRepositoryTestCase { *
- * The working tree should contain 'a' with FileMode.REGULAR_FILE after the
- * checkout.
+ * The checkout has to delete folder but the workingtree contains a dirty
+ * file at this path. The checkout should fail like in native git.
*
* @throws Exception
*/
@@ -266,11 +267,15 @@ public class CheckoutTest extends CLIRepositoryTestCase {
db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
- git.checkout().setName(branch_1.getName()).call();
-
- entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
- db.getFS());
- assertEquals(FileMode.REGULAR_FILE, entry.getMode());
+ try {
+ git.checkout().setName(branch_1.getName()).call();
+ fail("Don't get the expected conflict");
+ } catch (CheckoutConflictException e) {
+ assertEquals("[a]", e.getConflictingPaths().toString());
+ entry = new FileTreeIterator.FileEntry(
+ new File(db.getWorkTree(), "a"), db.getFS());
+ assertEquals(FileMode.REGULAR_FILE, entry.getMode());
+ }
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
index fbe7dd041..bb553a444 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutTest.java
@@ -1614,6 +1614,64 @@ public class DirCacheCheckoutTest extends RepositoryTestCase {
assertNotNull(git.checkout().setName(Constants.MASTER).call());
}
+ @Test(expected = CheckoutConflictException.class)
+ public void testFolderFileConflict() throws Exception {
+ RevCommit headCommit = commitFile("f/a", "initial content", "master");
+ RevCommit checkoutCommit = commitFile("f/a", "side content", "side");
+ FileUtils.delete(new File(db.getWorkTree(), "f"), FileUtils.RECURSIVE);
+ writeTrashFile("f", "file instead of folder");
+ new DirCacheCheckout(db, headCommit.getTree(), db.lockDirCache(),
+ checkoutCommit.getTree()).checkout();
+ }
+
+ @Test
+ public void testMultipleContentConflicts() throws Exception {
+ commitFile("a", "initial content", "master");
+ RevCommit headCommit = commitFile("b", "initial content", "master");
+ commitFile("a", "side content", "side");
+ RevCommit checkoutCommit = commitFile("b", "side content", "side");
+ writeTrashFile("a", "changed content");
+ writeTrashFile("b", "changed content");
+
+ try {
+ new DirCacheCheckout(db, headCommit.getTree(), db.lockDirCache(),
+ checkoutCommit.getTree()).checkout();
+ fail();
+ } catch (CheckoutConflictException expected) {
+ assertEquals(2, expected.getConflictingFiles().length);
+ assertTrue(Arrays.asList(expected.getConflictingFiles())
+ .contains("a"));
+ assertTrue(Arrays.asList(expected.getConflictingFiles())
+ .contains("b"));
+ assertEquals("changed content", read("a"));
+ assertEquals("changed content", read("b"));
+ }
+ }
+
+ @Test
+ public void testFolderFileAndContentConflicts() throws Exception {
+ RevCommit headCommit = commitFile("f/a", "initial content", "master");
+ commitFile("b", "side content", "side");
+ RevCommit checkoutCommit = commitFile("f/a", "side content", "side");
+ FileUtils.delete(new File(db.getWorkTree(), "f"), FileUtils.RECURSIVE);
+ writeTrashFile("f", "file instead of a folder");
+ writeTrashFile("b", "changed content");
+
+ try {
+ new DirCacheCheckout(db, headCommit.getTree(), db.lockDirCache(),
+ checkoutCommit.getTree()).checkout();
+ fail();
+ } catch (CheckoutConflictException expected) {
+ assertEquals(2, expected.getConflictingFiles().length);
+ assertTrue(Arrays.asList(expected.getConflictingFiles())
+ .contains("b"));
+ assertTrue(Arrays.asList(expected.getConflictingFiles())
+ .contains("f"));
+ assertEquals("file instead of a folder", read("f"));
+ assertEquals("changed content", read("b"));
+ }
+ }
+
public void assertWorkDir(Map