Browse Source

Merge "Add a test for merging deleted files"

stable-0.10
Shawn Pearce 14 years ago committed by Code Review
parent
commit
d1e8e97316
  1. 52
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

52
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);

Loading…
Cancel
Save