Browse Source

ResolveMergerTest: Open Git in try-with-resource

Change-Id: Ic378ec25c4a3ea4354ee643029f87e46b6449ed4
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.2
David Pursehouse 9 years ago
parent
commit
8074f50b58
  1. 59
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java

59
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java

@ -88,35 +88,36 @@ public class ResolveMergerTest extends RepositoryTestCase {
file = new File(folder1, "file2.txt");
write(file, "folder1--file2.txt");
Git git = new Git(db);
git.add().addFilepattern(folder1.getName()).call();
RevCommit base = git.commit().setMessage("adding folder").call();
recursiveDelete(folder1);
git.rm().addFilepattern("folder1/file1.txt")
.addFilepattern("folder1/file2.txt").call();
RevCommit other = git.commit()
.setMessage("removing folders on 'other'").call();
git.checkout().setName(base.name()).call();
file = new File(db.getWorkTree(), "unrelated.txt");
write(file, "unrelated");
git.add().addFilepattern("unrelated.txt").call();
RevCommit head = git.commit().setMessage("Adding another file").call();
// Untracked file to cause failing path for delete() of folder1
// but that's ok.
file = new File(folder1, "file3.txt");
write(file, "folder1--file3.txt");
ResolveMerger merger = (ResolveMerger) strategy.newMerger(db, false);
merger.setCommitNames(new String[] { "BASE", "HEAD", "other" });
merger.setWorkingTreeIterator(new FileTreeIterator(db));
boolean ok = merger.merge(head.getId(), other.getId());
assertTrue(ok);
assertTrue(file.exists());
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName()).call();
RevCommit base = git.commit().setMessage("adding folder").call();
recursiveDelete(folder1);
git.rm().addFilepattern("folder1/file1.txt")
.addFilepattern("folder1/file2.txt").call();
RevCommit other = git.commit()
.setMessage("removing folders on 'other'").call();
git.checkout().setName(base.name()).call();
file = new File(db.getWorkTree(), "unrelated.txt");
write(file, "unrelated");
git.add().addFilepattern("unrelated.txt").call();
RevCommit head = git.commit().setMessage("Adding another file").call();
// Untracked file to cause failing path for delete() of folder1
// but that's ok.
file = new File(folder1, "file3.txt");
write(file, "folder1--file3.txt");
ResolveMerger merger = (ResolveMerger) strategy.newMerger(db, false);
merger.setCommitNames(new String[] { "BASE", "HEAD", "other" });
merger.setWorkingTreeIterator(new FileTreeIterator(db));
boolean ok = merger.merge(head.getId(), other.getId());
assertTrue(ok);
assertTrue(file.exists());
}
}
/**

Loading…
Cancel
Save