diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2016-06-17 16:41:14 +0200 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2016-06-23 09:34:22 +0200 |
commit | 5fe44ed3ee025404dc34966ec996641f47f8490b (patch) | |
tree | 38cded9b222b7a4c832484d0a7ab3a123a811164 /org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit | |
parent | 2ec3accb3bcc0bd45dfb1333511c72489ab835cb (diff) | |
download | jgit-5fe44ed3ee025404dc34966ec996641f47f8490b.tar.gz jgit-5fe44ed3ee025404dc34966ec996641f47f8490b.zip |
Fix DirCacheCheckout to return CheckoutConflictException
Problem occurs when the checkout wants to create a file 'd/f' but
the workingtree contains a dirty file 'd'. In order to create d/f the
file 'd' would have to be deleted and since the file is dirty that
content would be lost. This should lead to a CheckoutConflictException
for d/f when failOnConflict was set to true.
This fix also changes jgit checkout semantics to be more like native
gits checkout semantics. If during a checkout jgit wants to delete a
folder but finds that the working tree contains a dirty file at this
path then JGit will now throw an exception instead of silently keeping
the dirty file. Like in this example:
git init
touch b
git add b
git commit -m addB
mkdir a
touch a/c
git add a/c
git commit -m addAC
rm -fr a
touch a
git checkout HEAD~
Change-Id: I9089123179e09dd565285d50b0caa308d290cccd
Signed-off-by: RĂ¼diger Herrmann <ruediger.herrmann@gmx.de>
Also-by: RĂ¼diger Herrmann <ruediger.herrmann@gmx.de>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit')
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java | 19 |
1 files changed, 12 insertions, 7 deletions
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 e690ad6964..3651542fc6 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 { * <li>Checkout branch '1' * </ol> * <p> - * 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()); + } } } |