Add a test for merging deleted files

The JGit merge algorithm or the Merge Command may have problems with handling
deletions always correctly. Therefore one additional test is added to check
this.

Change-Id: Id6aa49136996b29047c340994fe7faba68858e8c
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
This commit is contained in:
Christian Halstrick 2010-11-03 13:32:54 +01:00
parent 009507ca2e
commit f5076d8b04
1 changed files with 52 additions and 0 deletions

View File

@ -313,6 +313,58 @@ public void testSuccessfulContentMergeAndDirtyworkingTree()
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);