aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CheckoutCommandTest.java51
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();
+ }
+ }
}