summaryrefslogtreecommitdiffstats
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/StashApplyCommandTest.java90
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java47
2 files changed, 133 insertions, 4 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
index 2834100389..95b14192c9 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java
@@ -608,7 +608,8 @@ public class StashApplyCommandTest extends RepositoryTestCase {
fail("Exception not thrown");
} catch (JGitInternalException e) {
assertEquals(MessageFormat.format(
- JGitText.get().stashCommitMissingTwoParents, head.name()),
+ JGitText.get().stashCommitIncorrectNumberOfParents,
+ head.name(), 0),
e.getMessage());
}
}
@@ -648,4 +649,91 @@ public class StashApplyCommandTest extends RepositoryTestCase {
assertFalse(file.exists());
}
+
+ @Test
+ public void untrackedFileNotIncluded() throws Exception {
+ String untrackedPath = "untracked.txt";
+ File untrackedFile = writeTrashFile(untrackedPath, "content");
+ // at least one modification needed
+ writeTrashFile(PATH, "content2");
+ git.add().addFilepattern(PATH).call();
+ git.stashCreate().call();
+ assertTrue(untrackedFile.exists());
+
+ git.stashApply().setStashRef("stash@{0}").call();
+ assertTrue(untrackedFile.exists());
+
+ Status status = git.status().call();
+ assertEquals(1, status.getUntracked().size());
+ assertTrue(status.getUntracked().contains(untrackedPath));
+ assertEquals(1, status.getChanged().size());
+ assertTrue(status.getChanged().contains(PATH));
+ assertTrue(status.getAdded().isEmpty());
+ assertTrue(status.getConflicting().isEmpty());
+ assertTrue(status.getMissing().isEmpty());
+ assertTrue(status.getRemoved().isEmpty());
+ assertTrue(status.getModified().isEmpty());
+ }
+
+ @Test
+ public void untrackedFileIncluded() throws Exception {
+ String path = "a/b/untracked.txt";
+ File untrackedFile = writeTrashFile(path, "content");
+ RevCommit stashedCommit = git.stashCreate().setIncludeUntracked(true)
+ .call();
+ assertNotNull(stashedCommit);
+ assertFalse(untrackedFile.exists());
+ deleteTrashFile("a/b"); // checkout should create parent dirs
+
+ git.stashApply().setStashRef("stash@{0}").call();
+ assertTrue(untrackedFile.exists());
+ assertEquals("content", read(path));
+
+ Status status = git.status().call();
+ assertEquals(1, status.getUntracked().size());
+ assertTrue(status.getAdded().isEmpty());
+ assertTrue(status.getChanged().isEmpty());
+ assertTrue(status.getConflicting().isEmpty());
+ assertTrue(status.getMissing().isEmpty());
+ assertTrue(status.getRemoved().isEmpty());
+ assertTrue(status.getModified().isEmpty());
+ assertTrue(status.getUntracked().contains(path));
+ }
+
+ @Test
+ public void untrackedFileConflictsWithCommit() throws Exception {
+ String path = "untracked.txt";
+ writeTrashFile(path, "untracked");
+ git.stashCreate().setIncludeUntracked(true).call();
+
+ writeTrashFile(path, "committed");
+ head = git.commit().setMessage("add file").call();
+ git.add().addFilepattern(path).call();
+ git.commit().setMessage("conflicting commit").call();
+
+ try {
+ git.stashApply().setStashRef("stash@{0}").call();
+ fail("StashApplyFailureException should be thrown.");
+ } catch (StashApplyFailureException e) {
+ assertEquals(e.getMessage(), JGitText.get().stashApplyConflict);
+ }
+ assertEquals("committed", read(path));
+ }
+
+ @Test
+ public void untrackedFileConflictsWithWorkingDirectory()
+ throws Exception {
+ String path = "untracked.txt";
+ writeTrashFile(path, "untracked");
+ git.stashCreate().setIncludeUntracked(true).call();
+
+ writeTrashFile(path, "working-directory");
+ try {
+ git.stashApply().setStashRef("stash@{0}").call();
+ fail("StashApplyFailureException should be thrown.");
+ } catch (StashApplyFailureException e) {
+ assertEquals(e.getMessage(), JGitText.get().stashApplyConflict);
+ }
+ assertEquals("working-directory", read(path));
+ }
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
index 030dc9f4a1..387120342f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashCreateCommandTest.java
@@ -80,6 +80,8 @@ public class StashCreateCommandTest extends RepositoryTestCase {
private File committedFile;
+ private File untrackedFile;
+
@Before
public void setUp() throws Exception {
super.setUp();
@@ -88,16 +90,24 @@ public class StashCreateCommandTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call();
head = git.commit().setMessage("add file").call();
assertNotNull(head);
- writeTrashFile("untracked.txt", "content");
+ untrackedFile = writeTrashFile("untracked.txt", "content");
+ }
+
+ private void validateStashedCommit(final RevCommit commit)
+ throws IOException {
+ validateStashedCommit(commit, 2);
}
/**
* Core validation to be performed on all stashed commits
*
* @param commit
+ * @param parentCount
+ * number of parent commits required
* @throws IOException
*/
- private void validateStashedCommit(final RevCommit commit)
+ private void validateStashedCommit(final RevCommit commit,
+ int parentCount)
throws IOException {
assertNotNull(commit);
Ref stashRef = db.getRef(Constants.R_STASH);
@@ -105,7 +115,7 @@ public class StashCreateCommandTest extends RepositoryTestCase {
assertEquals(commit, stashRef.getObjectId());
assertNotNull(commit.getAuthorIdent());
assertEquals(commit.getAuthorIdent(), commit.getCommitterIdent());
- assertEquals(2, commit.getParentCount());
+ assertEquals(parentCount, commit.getParentCount());
// Load parents
RevWalk walk = new RevWalk(db);
@@ -461,4 +471,35 @@ public class StashCreateCommandTest extends RepositoryTestCase {
git.stashCreate().call();
}
+
+ @Test
+ public void untrackedFileIncluded() throws Exception {
+ String trackedPath = "tracked.txt";
+ writeTrashFile(trackedPath, "content2");
+ git.add().addFilepattern(trackedPath).call();
+
+ RevCommit stashed = git.stashCreate()
+ .setIncludeUntracked(true).call();
+ validateStashedCommit(stashed, 3);
+
+ assertEquals(
+ "Expected commits for workingDir,stashedIndex and untrackedFiles.",
+ 3, stashed.getParentCount());
+ assertFalse("untracked file should be deleted.", untrackedFile.exists());
+ }
+
+ @Test
+ public void untrackedFileNotIncluded() throws Exception {
+ String trackedPath = "tracked.txt";
+ // at least one modification needed
+ writeTrashFile(trackedPath, "content2");
+ git.add().addFilepattern(trackedPath).call();
+
+ RevCommit stashed = git.stashCreate().call();
+ validateStashedCommit(stashed);
+
+ assertTrue("untracked file should be left untouched.",
+ untrackedFile.exists());
+ assertEquals("content", read(untrackedFile));
+ }
}