aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2010-11-05 18:03:19 -0400
committerCode Review <codereview-daemon@eclipse.org>2010-11-05 18:03:19 -0400
commitd1e8e97316f8a1349e69a773b1fb0837d9892bbd (patch)
tree7d859d5273aa55b9d189fe30ae01deee0010a686 /org.eclipse.jgit.test/tst
parent5835ad1a91de1ef3949579fabe49d9a436f6fe9e (diff)
parentf5076d8b041bc7d0e1497cacbec370237a5ccaf7 (diff)
downloadjgit-d1e8e97316f8a1349e69a773b1fb0837d9892bbd.tar.gz
jgit-d1e8e97316f8a1349e69a773b1fb0837d9892bbd.zip
Merge "Add a test for merging deleted files"
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java52
1 files changed, 52 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
index 02d4b0e15b..7efe7c948d 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
@@ -313,6 +313,58 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
+ public void testSingleDeletion() throws Exception {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "1\na\n3\n");
+ writeTrashFile("b", "1\nb\n3\n");
+ writeTrashFile("d", "1\nd\n3\n");
+ writeTrashFile("c/c/c", "1\nc\n3\n");
+ git.add().addFilepattern("a").addFilepattern("b")
+ .addFilepattern("c/c/c").addFilepattern("d").call();
+ RevCommit initialCommit = git.commit().setMessage("initial").call();
+
+ createBranch(initialCommit, "refs/heads/side");
+ checkoutBranch("refs/heads/side");
+
+ assertTrue(new File(db.getWorkTree(), "b").delete());
+ git.add().addFilepattern("b").setUpdate(true).call();
+ RevCommit secondCommit = git.commit().setMessage("side").call();
+
+ assertFalse(new File(db.getWorkTree(), "b").exists());
+ checkoutBranch("refs/heads/master");
+ assertTrue(new File(db.getWorkTree(), "b").exists());
+
+ writeTrashFile("a", "1\na\n3(main)\n");
+ writeTrashFile("c/c/c", "1\nc(main)\n3\n");
+ git.add().addFilepattern("a").addFilepattern("c/c/c").call();
+ RevCommit thirdCommit = git.commit().setMessage("main").call();
+
+ // We are merging a deletion into our branch
+ MergeResult result = git.merge().include(secondCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+
+ assertEquals("1\na\n3(main)\n", read(new File(db.getWorkTree(), "a")));
+ assertFalse(new File(db.getWorkTree(), "b").exists());
+ assertEquals("1\nc(main)\n3\n",
+ read(new File(db.getWorkTree(), "c/c/c")));
+
+ // Do the opposite, be on a branch where we have deleted a file and
+ // merge in a old commit where this file was not deleted
+ checkoutBranch("refs/heads/side");
+ assertFalse(new File(db.getWorkTree(), "b").exists());
+
+ result = git.merge().include(thirdCommit.getId())
+ .setStrategy(MergeStrategy.RESOLVE).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+
+ assertEquals("1\na\n3(main)\n", read(new File(db.getWorkTree(), "a")));
+ assertFalse(new File(db.getWorkTree(), "b").exists());
+ assertEquals("1\nc(main)\n3\n",
+ read(new File(db.getWorkTree(), "c/c/c")));
+ }
+
public void testMergeFailingWithDirtyWorkingTree() throws Exception {
Git git = new Git(db);