diff options
author | Mathias Kinzler <mathias.kinzler@sap.com> | 2010-12-20 10:21:49 +0100 |
---|---|---|
committer | Mathias Kinzler <mathias.kinzler@sap.com> | 2010-12-20 10:21:49 +0100 |
commit | 645d262de6da32fdb05aba5a48dbf6188dfa7776 (patch) | |
tree | 3f3af8b99eb6e77c6ece0a94578455f482334d5b /org.eclipse.jgit.test | |
parent | 94a2cbb40750c0f5b4f873fa109d339393ee6888 (diff) | |
download | jgit-645d262de6da32fdb05aba5a48dbf6188dfa7776.tar.gz jgit-645d262de6da32fdb05aba5a48dbf6188dfa7776.zip |
Checkout: expose a CheckoutResult
This is needed by callers to determine checkout conflicts and
possible files that were not deleted during the checkout so that they
can present the end user with a better Exception description and retry
to delete the undeleted files later, respectively.
Change-Id: I037930da7b1a4dfb24cfa3205afb51dc29e4a5b8
Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
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 295a284c02..cf78a0e563 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 @@ -42,8 +42,11 @@ */ package org.eclipse.jgit.api; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import org.eclipse.jgit.api.CheckoutResult.Status; import org.eclipse.jgit.api.errors.InvalidRefNameException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.RefAlreadyExistsException; @@ -52,6 +55,7 @@ import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RepositoryTestCase; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.util.FileUtils; public class CheckoutCommandTest extends RepositoryTestCase { private Git git; @@ -120,4 +124,51 @@ public class CheckoutCommandTest extends RepositoryTestCase { } } + public void testCheckoutWithConflict() { + CheckoutCommand co = git.checkout(); + try { + writeTrashFile("Test.txt", "Another change"); + assertEquals(Status.NOT_TRIED, co.getResult().getStatus()); + co.setName("master").call(); + fail("Should have failed"); + } catch (Exception e) { + assertEquals(Status.CONFLICTS, co.getResult().getStatus()); + assertTrue(co.getResult().getConflictList().contains("Test.txt")); + } + } + + public void testCheckoutWithNonDeletedFiles() throws Exception { + File testFile = writeTrashFile("temp", ""); + FileInputStream fis = new FileInputStream(testFile); + try { + FileUtils.delete(testFile); + return; + } catch (IOException e) { + // the test makes only sense if deletion of + // a file with open stream fails + } + fis.close(); + FileUtils.delete(testFile); + CheckoutCommand co = git.checkout(); + // delete Test.txt in branch test + testFile = new File(db.getWorkTree(), "Test.txt"); + assertTrue(testFile.exists()); + FileUtils.delete(testFile); + assertFalse(testFile.exists()); + git.add().addFilepattern("Test.txt"); + git.commit().setMessage("Delete Test.txt").setAll(true).call(); + git.checkout().setName("master").call(); + assertTrue(testFile.exists()); + // lock the file so it can't be deleted (in Windows, that is) + fis = new FileInputStream(testFile); + try { + assertEquals(Status.NOT_TRIED, co.getResult().getStatus()); + co.setName("test").call(); + assertTrue(testFile.exists()); + assertEquals(Status.NONDELETED, co.getResult().getStatus()); + assertTrue(co.getResult().getUndeletedList().contains("Test.txt")); + } finally { + fis.close(); + } + } } |