diff options
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StashApplyCommandTest.java | 87 |
1 files changed, 87 insertions, 0 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 16e80f1bfa..2834100389 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 @@ -409,6 +409,93 @@ public class StashApplyCommandTest extends RepositoryTestCase { } @Test + public void stashedApplyOnOtherBranch() throws Exception { + writeTrashFile(PATH, "content\nmore content\n"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("more content").call(); + String path2 = "file2.txt"; + File file2 = writeTrashFile(path2, "content\nmore content\n"); + git.add().addFilepattern(PATH).call(); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("even content").call(); + + String otherBranch = "otherBranch"; + git.branchCreate().setName(otherBranch).call(); + + writeTrashFile(PATH, "master content"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("even content").call(); + + git.checkout().setName(otherBranch).call(); + + writeTrashFile(PATH, "otherBranch content"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("even more content").call(); + + writeTrashFile(path2, "content\nstashed change\nmore content\n"); + + RevCommit stashed = git.stashCreate().call(); + + assertNotNull(stashed); + assertEquals("content\nmore content\n", read(file2)); + assertEquals("otherBranch content", + read(committedFile)); + assertTrue(git.status().call().isClean()); + + git.checkout().setName("master").call(); + git.stashApply().call(); + assertEquals("content\nstashed change\nmore content\n", read(file2)); + assertEquals("master content", + read(committedFile)); + } + + @Test + public void stashedApplyOnOtherBranchWithStagedChange() throws Exception { + writeTrashFile(PATH, "content\nmore content\n"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("more content").call(); + String path2 = "file2.txt"; + File file2 = writeTrashFile(path2, "content\nmore content\n"); + git.add().addFilepattern(PATH).call(); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("even content").call(); + + String otherBranch = "otherBranch"; + git.branchCreate().setName(otherBranch).call(); + + writeTrashFile(PATH, "master content"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("even content").call(); + + git.checkout().setName(otherBranch).call(); + + writeTrashFile(PATH, "otherBranch content"); + git.add().addFilepattern(PATH).call(); + git.commit().setMessage("even more content").call(); + + writeTrashFile(path2, + "content\nstashed change in index\nmore content\n"); + git.add().addFilepattern(path2).call(); + writeTrashFile(path2, "content\nstashed change\nmore content\n"); + + RevCommit stashed = git.stashCreate().call(); + + assertNotNull(stashed); + assertEquals("content\nmore content\n", read(file2)); + assertEquals("otherBranch content", read(committedFile)); + assertTrue(git.status().call().isClean()); + + git.checkout().setName("master").call(); + git.stashApply().call(); + assertEquals("content\nstashed change\nmore content\n", read(file2)); + assertEquals( + "[file.txt, mode:100644, content:master content]" + + "[file2.txt, mode:100644, content:content\nstashed change in index\nmore content\n]", + indexState(CONTENT)); + assertEquals("master content", read(committedFile)); + } + + @Test public void workingDirectoryContentMerge() throws Exception { writeTrashFile(PATH, "content\nmore content\n"); git.add().addFilepattern(PATH).call(); |