From 03987f980b7336786a1d63fe39425a41b27eb0eb Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 12 Feb 2016 14:39:08 +0900 Subject: [PATCH 01/22] MergeCommandTest: Open Git instances in try-with-resource Change-Id: I95074358cec6fef6b5ced7bb7b117c33fee08a7a Signed-off-by: David Pursehouse --- .../eclipse/jgit/api/MergeCommandTest.java | 2414 +++++++++-------- 1 file changed, 1212 insertions(+), 1202 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 cea8393ff..b51c2beff 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 @@ -96,11 +96,12 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testMergeInItself() throws Exception { - Git git = new Git(db); - git.commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); - MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call(); - assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); + MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call(); + assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); + } // no reflog entry written by merge assertEquals("commit (initial): initial commit", db @@ -112,14 +113,15 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testAlreadyUpToDate() throws Exception { - Git git = new Git(db); - RevCommit first = git.commit().setMessage("initial commit").call(); - createBranch(first, "refs/heads/branch1"); - - RevCommit second = git.commit().setMessage("second commit").call(); - MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call(); - assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); - assertEquals(second, result.getNewHead()); + try (Git git = new Git(db)) { + RevCommit first = git.commit().setMessage("initial commit").call(); + createBranch(first, "refs/heads/branch1"); + + RevCommit second = git.commit().setMessage("second commit").call(); + MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call(); + assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); + assertEquals(second, result.getNewHead()); + } // no reflog entry written by merge assertEquals("commit: second commit", db .getReflogReader(Constants.HEAD).getLastEntry().getComment()); @@ -129,18 +131,19 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testFastForward() throws Exception { - Git git = new Git(db); - RevCommit first = git.commit().setMessage("initial commit").call(); - createBranch(first, "refs/heads/branch1"); + try (Git git = new Git(db)) { + RevCommit first = git.commit().setMessage("initial commit").call(); + createBranch(first, "refs/heads/branch1"); - RevCommit second = git.commit().setMessage("second commit").call(); + RevCommit second = git.commit().setMessage("second commit").call(); - checkoutBranch("refs/heads/branch1"); + checkoutBranch("refs/heads/branch1"); - MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); - assertEquals(second, result.getNewHead()); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); + assertEquals(second, result.getNewHead()); + } assertEquals("merge refs/heads/master: Fast-forward", db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); assertEquals("merge refs/heads/master: Fast-forward", @@ -149,20 +152,21 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testFastForwardNoCommit() throws Exception { - Git git = new Git(db); - RevCommit first = git.commit().setMessage("initial commit").call(); - createBranch(first, "refs/heads/branch1"); + try (Git git = new Git(db)) { + RevCommit first = git.commit().setMessage("initial commit").call(); + createBranch(first, "refs/heads/branch1"); - RevCommit second = git.commit().setMessage("second commit").call(); + RevCommit second = git.commit().setMessage("second commit").call(); - checkoutBranch("refs/heads/branch1"); + checkoutBranch("refs/heads/branch1"); - MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)) - .setCommit(false).call(); + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)) + .setCommit(false).call(); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD, - result.getMergeStatus()); - assertEquals(second, result.getNewHead()); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD, + result.getMergeStatus()); + assertEquals(second, result.getNewHead()); + } assertEquals("merge refs/heads/master: Fast-forward", db .getReflogReader(Constants.HEAD).getLastEntry().getComment()); assertEquals("merge refs/heads/master: Fast-forward", db @@ -171,29 +175,29 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testFastForwardWithFiles() throws Exception { - Git git = new Git(db); - - writeTrashFile("file1", "file1"); - git.add().addFilepattern("file1").call(); - RevCommit first = git.commit().setMessage("initial commit").call(); + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit first = git.commit().setMessage("initial commit").call(); - assertTrue(new File(db.getWorkTree(), "file1").exists()); - createBranch(first, "refs/heads/branch1"); + assertTrue(new File(db.getWorkTree(), "file1").exists()); + createBranch(first, "refs/heads/branch1"); - writeTrashFile("file2", "file2"); - git.add().addFilepattern("file2").call(); - RevCommit second = git.commit().setMessage("second commit").call(); - assertTrue(new File(db.getWorkTree(), "file2").exists()); + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + RevCommit second = git.commit().setMessage("second commit").call(); + assertTrue(new File(db.getWorkTree(), "file2").exists()); - checkoutBranch("refs/heads/branch1"); - assertFalse(new File(db.getWorkTree(), "file2").exists()); + checkoutBranch("refs/heads/branch1"); + assertFalse(new File(db.getWorkTree(), "file2").exists()); - MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); + MergeResult result = git.merge().include(db.exactRef(R_HEADS + MASTER)).call(); - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); - assertEquals(second, result.getNewHead()); + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); + assertEquals(second, result.getNewHead()); + } assertEquals("merge refs/heads/master: Fast-forward", db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); assertEquals("merge refs/heads/master: Fast-forward", @@ -202,56 +206,56 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testMultipleHeads() throws Exception { - Git git = new Git(db); - - writeTrashFile("file1", "file1"); - git.add().addFilepattern("file1").call(); - RevCommit first = git.commit().setMessage("initial commit").call(); - createBranch(first, "refs/heads/branch1"); - - writeTrashFile("file2", "file2"); - git.add().addFilepattern("file2").call(); - RevCommit second = git.commit().setMessage("second commit").call(); - - writeTrashFile("file3", "file3"); - git.add().addFilepattern("file3").call(); - git.commit().setMessage("third commit").call(); - - checkoutBranch("refs/heads/branch1"); - assertFalse(new File(db.getWorkTree(), "file2").exists()); - assertFalse(new File(db.getWorkTree(), "file3").exists()); - - MergeCommand merge = git.merge(); - merge.include(second.getId()); - merge.include(db.exactRef(R_HEADS + MASTER)); - try { - merge.call(); - fail("Expected exception not thrown when merging multiple heads"); - } catch (InvalidMergeHeadsException e) { - // expected this exception + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit first = git.commit().setMessage("initial commit").call(); + createBranch(first, "refs/heads/branch1"); + + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + RevCommit second = git.commit().setMessage("second commit").call(); + + writeTrashFile("file3", "file3"); + git.add().addFilepattern("file3").call(); + git.commit().setMessage("third commit").call(); + + checkoutBranch("refs/heads/branch1"); + assertFalse(new File(db.getWorkTree(), "file2").exists()); + assertFalse(new File(db.getWorkTree(), "file3").exists()); + + MergeCommand merge = git.merge(); + merge.include(second.getId()); + merge.include(db.exactRef(R_HEADS + MASTER)); + try { + merge.call(); + fail("Expected exception not thrown when merging multiple heads"); + } catch (InvalidMergeHeadsException e) { + // expected this exception + } } } @Theory public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy) throws Exception { - Git git = new Git(db); - - RevCommit first = git.commit().setMessage("first").call(); - createBranch(first, "refs/heads/side"); - - writeTrashFile("a", "a"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("second").call(); - - checkoutBranch("refs/heads/side"); - writeTrashFile("b", "b"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("third").call(); - - MergeResult result = git.merge().setStrategy(mergeStrategy) - .include(db.exactRef(R_HEADS + MASTER)).call(); - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + try (Git git = new Git(db)) { + RevCommit first = git.commit().setMessage("first").call(); + createBranch(first, "refs/heads/side"); + + writeTrashFile("a", "a"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("second").call(); + + checkoutBranch("refs/heads/side"); + writeTrashFile("b", "b"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("third").call(); + + MergeResult result = git.merge().setStrategy(mergeStrategy) + .include(db.exactRef(R_HEADS + MASTER)).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + } assertEquals( "merge refs/heads/master: Merge made by " + mergeStrategy.getName() + ".", @@ -265,604 +269,604 @@ public class MergeCommandTest extends RepositoryTestCase { @Theory public void testMergeSuccessAllStrategiesNoCommit( MergeStrategy mergeStrategy) throws Exception { - Git git = new Git(db); - - RevCommit first = git.commit().setMessage("first").call(); - createBranch(first, "refs/heads/side"); - - writeTrashFile("a", "a"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("second").call(); - - checkoutBranch("refs/heads/side"); - writeTrashFile("b", "b"); - git.add().addFilepattern("b").call(); - RevCommit thirdCommit = git.commit().setMessage("third").call(); - - MergeResult result = git.merge().setStrategy(mergeStrategy) - .setCommit(false) - .include(db.exactRef(R_HEADS + MASTER)).call(); - assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); - assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), - thirdCommit.getId()); + try (Git git = new Git(db)) { + RevCommit first = git.commit().setMessage("first").call(); + createBranch(first, "refs/heads/side"); + + writeTrashFile("a", "a"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("second").call(); + + checkoutBranch("refs/heads/side"); + writeTrashFile("b", "b"); + git.add().addFilepattern("b").call(); + RevCommit thirdCommit = git.commit().setMessage("third").call(); + + MergeResult result = git.merge().setStrategy(mergeStrategy) + .setCommit(false) + .include(db.exactRef(R_HEADS + MASTER)).call(); + assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); + assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), + thirdCommit.getId()); + } } @Test public void testContentMerge() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - writeTrashFile("c/c/c", "1\nc\n3\n"); - git.add().addFilepattern("a").addFilepattern("b") - .addFilepattern("c/c/c").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - writeTrashFile("a", "1\na(side)\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - writeTrashFile("a", "1\na(main)\n3\n"); - writeTrashFile("c/c/c", "1\nc(main)\n3\n"); - git.add().addFilepattern("a").addFilepattern("c/c/c").call(); - git.commit().setMessage("main").call(); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - - assertEquals( - "1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n", - read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", - read(new File(db.getWorkTree(), "c/c/c"))); - - assertEquals(1, result.getConflicts().size()); - assertEquals(3, result.getConflicts().get("a")[0].length); - - assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + writeTrashFile("c/c/c", "1\nc\n3\n"); + git.add().addFilepattern("a").addFilepattern("b") + .addFilepattern("c/c/c").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1\na(side)\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + writeTrashFile("a", "1\na(main)\n3\n"); + writeTrashFile("c/c/c", "1\nc(main)\n3\n"); + git.add().addFilepattern("a").addFilepattern("c/c/c").call(); + git.commit().setMessage("main").call(); + + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + + assertEquals( + "1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n", + read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", + read(new File(db.getWorkTree(), "c/c/c"))); + + assertEquals(1, result.getConflicts().size()); + assertEquals(3, result.getConflicts().get("a")[0].length); + + assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + } } @Test public void testMergeTag() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "a"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "a"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - writeTrashFile("b", "b"); - git.add().addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - Ref tag = git.tag().setAnnotated(true).setMessage("my tag 01") - .setName("tag01").setObjectId(secondCommit).call(); + writeTrashFile("b", "b"); + git.add().addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + Ref tag = git.tag().setAnnotated(true).setMessage("my tag 01") + .setName("tag01").setObjectId(secondCommit).call(); - checkoutBranch("refs/heads/master"); + checkoutBranch("refs/heads/master"); - writeTrashFile("a", "a2"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); + writeTrashFile("a", "a2"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); - MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + } } @Test public void testMergeMessage() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - writeTrashFile("a", "1\na(side)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("side").call(); + writeTrashFile("a", "1\na(side)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("side").call(); - checkoutBranch("refs/heads/master"); + checkoutBranch("refs/heads/master"); - writeTrashFile("a", "1\na(main)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); - Ref sideBranch = db.exactRef("refs/heads/side"); + Ref sideBranch = db.exactRef("refs/heads/side"); - git.merge().include(sideBranch) - .setStrategy(MergeStrategy.RESOLVE).call(); + git.merge().include(sideBranch) + .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n", - db.readMergeCommitMsg()); + assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n", + db.readMergeCommitMsg()); + } } @Test public void testMergeNonVersionedPaths() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - writeTrashFile("c/c/c", "1\nc\n3\n"); - git.add().addFilepattern("a").addFilepattern("b") - .addFilepattern("c/c/c").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - writeTrashFile("a", "1\na(side)\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - writeTrashFile("a", "1\na(main)\n3\n"); - writeTrashFile("c/c/c", "1\nc(main)\n3\n"); - git.add().addFilepattern("a").addFilepattern("c/c/c").call(); - git.commit().setMessage("main").call(); - - writeTrashFile("d", "1\nd\n3\n"); - assertTrue(new File(db.getWorkTree(), "e").mkdir()); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - - assertEquals( - "1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n", - read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", - read(new File(db.getWorkTree(), "c/c/c"))); - assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); - File dir = new File(db.getWorkTree(), "e"); - assertTrue(dir.isDirectory()); - - assertEquals(1, result.getConflicts().size()); - assertEquals(3, result.getConflicts().get("a")[0].length); - - assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + writeTrashFile("c/c/c", "1\nc\n3\n"); + git.add().addFilepattern("a").addFilepattern("b") + .addFilepattern("c/c/c").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1\na(side)\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + writeTrashFile("a", "1\na(main)\n3\n"); + writeTrashFile("c/c/c", "1\nc(main)\n3\n"); + git.add().addFilepattern("a").addFilepattern("c/c/c").call(); + git.commit().setMessage("main").call(); + + writeTrashFile("d", "1\nd\n3\n"); + assertTrue(new File(db.getWorkTree(), "e").mkdir()); + + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + + assertEquals( + "1\n<<<<<<< HEAD\na(main)\n=======\na(side)\n>>>>>>> 86503e7e397465588cc267b65d778538bffccb83\n3\n", + read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", + read(new File(db.getWorkTree(), "c/c/c"))); + assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + File dir = new File(db.getWorkTree(), "e"); + assertTrue(dir.isDirectory()); + + assertEquals(1, result.getConflicts().size()); + assertEquals(3, result.getConflicts().get("a")[0].length); + + assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + } } @Test public void testMultipleCreations() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); - checkoutBranch("refs/heads/master"); + checkoutBranch("refs/heads/master"); - writeTrashFile("b", "1\nb(main)\n3\n"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("main").call(); + writeTrashFile("b", "1\nb(main)\n3\n"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("main").call(); - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + } } @Test public void testMultipleCreationsSameContent() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - writeTrashFile("b", "1\nb(1)\n3\n"); - git.add().addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - checkoutBranch("refs/heads/master"); - - writeTrashFile("b", "1\nb(1)\n3\n"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("main").call(); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); - assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("merge " + secondCommit.getId().getName() - + ": Merge made by resolve.", db - .getReflogReader(Constants.HEAD) - .getLastEntry().getComment()); - assertEquals("merge " + secondCommit.getId().getName() - + ": Merge made by resolve.", db - .getReflogReader(db.getBranch()) - .getLastEntry().getComment()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("b", "1\nb(1)\n3\n"); + git.add().addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + checkoutBranch("refs/heads/master"); + + writeTrashFile("b", "1\nb(1)\n3\n"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("main").call(); + + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + assertEquals("1\nb(1)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("merge " + secondCommit.getId().getName() + + ": Merge made by resolve.", db + .getReflogReader(Constants.HEAD) + .getLastEntry().getComment()); + assertEquals("merge " + secondCommit.getId().getName() + + ": Merge made by resolve.", db + .getReflogReader(db.getBranch()) + .getLastEntry().getComment()); + } } @Test public void testSuccessfulContentMerge() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - writeTrashFile("c/c/c", "1\nc\n3\n"); - git.add().addFilepattern("a").addFilepattern("b") - .addFilepattern("c/c/c").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - writeTrashFile("a", "1(side)\na\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - 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(); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); - - assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), - "a"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), - "c/c/c"))); - - assertEquals(null, result.getConflicts()); - - assertEquals(2, result.getMergedCommits().length); - assertEquals(thirdCommit, result.getMergedCommits()[0]); - assertEquals(secondCommit, result.getMergedCommits()[1]); - - Iterator it = git.log().call().iterator(); - RevCommit newHead = it.next(); - assertEquals(newHead, result.getNewHead()); - assertEquals(2, newHead.getParentCount()); - assertEquals(thirdCommit, newHead.getParent(0)); - assertEquals(secondCommit, newHead.getParent(1)); - assertEquals( - "Merge commit '3fa334456d236a92db020289fe0bf481d91777b4'", - newHead.getFullMessage()); - // @TODO fix me - assertEquals(RepositoryState.SAFE, db.getRepositoryState()); - // test index state + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + writeTrashFile("c/c/c", "1\nc\n3\n"); + git.add().addFilepattern("a").addFilepattern("b") + .addFilepattern("c/c/c").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1(side)\na\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + 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(); + + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + + assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), + "a"))); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), + "c/c/c"))); + + assertEquals(null, result.getConflicts()); + + assertEquals(2, result.getMergedCommits().length); + assertEquals(thirdCommit, result.getMergedCommits()[0]); + assertEquals(secondCommit, result.getMergedCommits()[1]); + + Iterator it = git.log().call().iterator(); + RevCommit newHead = it.next(); + assertEquals(newHead, result.getNewHead()); + assertEquals(2, newHead.getParentCount()); + assertEquals(thirdCommit, newHead.getParent(0)); + assertEquals(secondCommit, newHead.getParent(1)); + assertEquals( + "Merge commit '3fa334456d236a92db020289fe0bf481d91777b4'", + newHead.getFullMessage()); + // @TODO fix me + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + // test index state + } } @Test public void testSuccessfulContentMergeNoCommit() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - writeTrashFile("c/c/c", "1\nc\n3\n"); - git.add().addFilepattern("a").addFilepattern("b") - .addFilepattern("c/c/c").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - writeTrashFile("a", "1(side)\na\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - 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(); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setCommit(false) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); - assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), - thirdCommit.getId()); - - assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), - "a"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", - read(new File(db.getWorkTree(), "c/c/c"))); - - assertEquals(null, result.getConflicts()); - - assertEquals(2, result.getMergedCommits().length); - assertEquals(thirdCommit, result.getMergedCommits()[0]); - assertEquals(secondCommit, result.getMergedCommits()[1]); - assertNull(result.getNewHead()); - assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + writeTrashFile("c/c/c", "1\nc\n3\n"); + git.add().addFilepattern("a").addFilepattern("b") + .addFilepattern("c/c/c").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + writeTrashFile("a", "1(side)\na\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + 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(); + + MergeResult result = git.merge().include(secondCommit.getId()) + .setCommit(false) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); + assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), + thirdCommit.getId()); + + assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), + "a"))); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", + read(new File(db.getWorkTree(), "c/c/c"))); + + assertEquals(null, result.getConflicts()); + + assertEquals(2, result.getMergedCommits().length); + assertEquals(thirdCommit, result.getMergedCommits()[0]); + assertEquals(secondCommit, result.getMergedCommits()[1]); + assertNull(result.getNewHead()); + assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); + } } @Test public void testSuccessfulContentMergeAndDirtyworkingTree() 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"); - - writeTrashFile("a", "1(side)\na\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - 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(); - - writeTrashFile("d", "--- dirty ---"); - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); - - assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), - "a"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), - "c/c/c"))); - assertEquals("--- dirty ---", read(new File(db.getWorkTree(), "d"))); - - assertEquals(null, result.getConflicts()); - - assertEquals(2, result.getMergedCommits().length); - assertEquals(thirdCommit, result.getMergedCommits()[0]); - assertEquals(secondCommit, result.getMergedCommits()[1]); - - Iterator it = git.log().call().iterator(); - RevCommit newHead = it.next(); - assertEquals(newHead, result.getNewHead()); - assertEquals(2, newHead.getParentCount()); - assertEquals(thirdCommit, newHead.getParent(0)); - assertEquals(secondCommit, newHead.getParent(1)); - assertEquals( - "Merge commit '064d54d98a4cdb0fed1802a21c656bfda67fe879'", - newHead.getFullMessage()); - - assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + try (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"); + + writeTrashFile("a", "1(side)\na\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + 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(); + + writeTrashFile("d", "--- dirty ---"); + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + + assertEquals("1(side)\na\n3(main)\n", read(new File(db.getWorkTree(), + "a"))); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), + "c/c/c"))); + assertEquals("--- dirty ---", read(new File(db.getWorkTree(), "d"))); + + assertEquals(null, result.getConflicts()); + + assertEquals(2, result.getMergedCommits().length); + assertEquals(thirdCommit, result.getMergedCommits()[0]); + assertEquals(secondCommit, result.getMergedCommits()[1]); + + Iterator it = git.log().call().iterator(); + RevCommit newHead = it.next(); + assertEquals(newHead, result.getNewHead()); + assertEquals(2, newHead.getParentCount()); + assertEquals(thirdCommit, newHead.getParent(0)); + assertEquals(secondCommit, newHead.getParent(1)); + assertEquals( + "Merge commit '064d54d98a4cdb0fed1802a21c656bfda67fe879'", + newHead.getFullMessage()); + + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + } } @Test 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"))); - assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); - - // 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"))); - assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + try (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"))); + assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + + // 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"))); + assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + } } @Test public void testMultipleDeletions() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - - assertTrue(new File(db.getWorkTree(), "a").delete()); - git.add().addFilepattern("a").setUpdate(true).call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - assertFalse(new File(db.getWorkTree(), "a").exists()); - checkoutBranch("refs/heads/master"); - assertTrue(new File(db.getWorkTree(), "a").exists()); - - assertTrue(new File(db.getWorkTree(), "a").delete()); - git.add().addFilepattern("a").setUpdate(true).call(); - 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()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + + assertTrue(new File(db.getWorkTree(), "a").delete()); + git.add().addFilepattern("a").setUpdate(true).call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + assertFalse(new File(db.getWorkTree(), "a").exists()); + checkoutBranch("refs/heads/master"); + assertTrue(new File(db.getWorkTree(), "a").exists()); + + assertTrue(new File(db.getWorkTree(), "a").delete()); + git.add().addFilepattern("a").setUpdate(true).call(); + 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()); + } } @Test public void testDeletionAndConflict() 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()); - writeTrashFile("a", "1\na\n3(side)\n"); - git.add().addFilepattern("b").setUpdate(true).call(); - git.add().addFilepattern("a").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(); - 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.CONFLICTING, result.getMergeStatus()); - - assertEquals( - "1\na\n<<<<<<< HEAD\n3(main)\n=======\n3(side)\n>>>>>>> 54ffed45d62d252715fc20e41da92d44c48fb0ff\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"))); - assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + try (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()); + writeTrashFile("a", "1\na\n3(side)\n"); + git.add().addFilepattern("b").setUpdate(true).call(); + git.add().addFilepattern("a").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(); + 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.CONFLICTING, result.getMergeStatus()); + + assertEquals( + "1\na\n<<<<<<< HEAD\n3(main)\n=======\n3(side)\n>>>>>>> 54ffed45d62d252715fc20e41da92d44c48fb0ff\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"))); + assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); + } } @Test public void testDeletionOnMasterConflict() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - // create side branch and modify "a" - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - writeTrashFile("a", "1\na(side)\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - // delete a on master to generate conflict - checkoutBranch("refs/heads/master"); - git.rm().addFilepattern("a").call(); - git.commit().setMessage("main").call(); - - // merge side with master - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - - // result should be 'a' conflicting with workspace content from side - assertTrue(new File(db.getWorkTree(), "a").exists()); - assertEquals("1\na(side)\n3\n", read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + // create side branch and modify "a" + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + writeTrashFile("a", "1\na(side)\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + // delete a on master to generate conflict + checkoutBranch("refs/heads/master"); + git.rm().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + // merge side with master + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + + // result should be 'a' conflicting with workspace content from side + assertTrue(new File(db.getWorkTree(), "a").exists()); + assertEquals("1\na(side)\n3\n", read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + } } @Test public void testDeletionOnSideConflict() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - // create side branch and delete "a" - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - git.rm().addFilepattern("a").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - // update a on master to generate conflict - checkoutBranch("refs/heads/master"); - writeTrashFile("a", "1\na(main)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); - - // merge side with master - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - - assertTrue(new File(db.getWorkTree(), "a").exists()); - assertEquals("1\na(main)\n3\n", read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - - assertEquals(1, result.getConflicts().size()); - assertEquals(3, result.getConflicts().get("a")[0].length); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + // create side branch and delete "a" + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + git.rm().addFilepattern("a").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + // update a on master to generate conflict + checkoutBranch("refs/heads/master"); + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + // merge side with master + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + + assertTrue(new File(db.getWorkTree(), "a").exists()); + assertEquals("1\na(main)\n3\n", read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + + assertEquals(1, result.getConflicts().size()); + assertEquals(3, result.getConflicts().get("a")[0].length); + } } @Test @@ -870,262 +874,262 @@ public class MergeCommandTest extends RepositoryTestCase { // this test is essentially the same as testDeletionOnSideConflict, // however if once rename support is added this test should result in a // successful merge instead of a conflict - Git git = new Git(db); - - writeTrashFile("x", "add x"); - git.add().addFilepattern("x").call(); - RevCommit initial = git.commit().setMessage("add x").call(); - - createBranch(initial, "refs/heads/d1"); - createBranch(initial, "refs/heads/d2"); - - // rename x to y on d1 - checkoutBranch("refs/heads/d1"); - new File(db.getWorkTree(), "x") - .renameTo(new File(db.getWorkTree(), "y")); - git.rm().addFilepattern("x").call(); - git.add().addFilepattern("y").call(); - RevCommit d1Commit = git.commit().setMessage("d1 rename x -> y").call(); - - checkoutBranch("refs/heads/d2"); - writeTrashFile("x", "d2 change"); - git.add().addFilepattern("x").call(); - RevCommit d2Commit = git.commit().setMessage("d2 change in x").call(); - - checkoutBranch("refs/heads/master"); - MergeResult d1Merge = git.merge().include(d1Commit).call(); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD, - d1Merge.getMergeStatus()); - - MergeResult d2Merge = git.merge().include(d2Commit).call(); - assertEquals(MergeResult.MergeStatus.CONFLICTING, - d2Merge.getMergeStatus()); - assertEquals(1, d2Merge.getConflicts().size()); - assertEquals(3, d2Merge.getConflicts().get("x")[0].length); + try (Git git = new Git(db)) { + writeTrashFile("x", "add x"); + git.add().addFilepattern("x").call(); + RevCommit initial = git.commit().setMessage("add x").call(); + + createBranch(initial, "refs/heads/d1"); + createBranch(initial, "refs/heads/d2"); + + // rename x to y on d1 + checkoutBranch("refs/heads/d1"); + new File(db.getWorkTree(), "x") + .renameTo(new File(db.getWorkTree(), "y")); + git.rm().addFilepattern("x").call(); + git.add().addFilepattern("y").call(); + RevCommit d1Commit = git.commit().setMessage("d1 rename x -> y").call(); + + checkoutBranch("refs/heads/d2"); + writeTrashFile("x", "d2 change"); + git.add().addFilepattern("x").call(); + RevCommit d2Commit = git.commit().setMessage("d2 change in x").call(); + + checkoutBranch("refs/heads/master"); + MergeResult d1Merge = git.merge().include(d1Commit).call(); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD, + d1Merge.getMergeStatus()); + + MergeResult d2Merge = git.merge().include(d2Commit).call(); + assertEquals(MergeResult.MergeStatus.CONFLICTING, + d2Merge.getMergeStatus()); + assertEquals(1, d2Merge.getConflicts().size()); + assertEquals(3, d2Merge.getConflicts().get("x")[0].length); + } } @Test public void testMergeFailingWithDirtyWorkingTree() throws Exception { - Git git = new Git(db); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + writeTrashFile("a", "1(side)\na\n3\n"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); - writeTrashFile("a", "1(side)\na\n3\n"); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); + assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); + checkoutBranch("refs/heads/master"); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nb(side)\n3\n", read(new File(db.getWorkTree(), "b"))); - checkoutBranch("refs/heads/master"); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + writeTrashFile("a", "1\na\n3(main)\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); - writeTrashFile("a", "1\na\n3(main)\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); + writeTrashFile("a", "--- dirty ---"); + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); - writeTrashFile("a", "--- dirty ---"); - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.FAILED, result.getMergeStatus()); - assertEquals(MergeStatus.FAILED, result.getMergeStatus()); + assertEquals("--- dirty ---", read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("--- dirty ---", read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals(null, result.getConflicts()); - assertEquals(null, result.getConflicts()); - - assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + assertEquals(RepositoryState.SAFE, db.getRepositoryState()); + } } @Test public void testMergeConflictFileFolder() throws Exception { - Git git = new Git(db); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + writeTrashFile("c/c/c", "1\nc(side)\n3\n"); + writeTrashFile("d", "1\nd(side)\n3\n"); + git.add().addFilepattern("c/c/c").addFilepattern("d").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); - writeTrashFile("c/c/c", "1\nc(side)\n3\n"); - writeTrashFile("d", "1\nd(side)\n3\n"); - git.add().addFilepattern("c/c/c").addFilepattern("d").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); + checkoutBranch("refs/heads/master"); - checkoutBranch("refs/heads/master"); + writeTrashFile("c", "1\nc(main)\n3\n"); + writeTrashFile("d/d/d", "1\nd(main)\n3\n"); + git.add().addFilepattern("c").addFilepattern("d/d/d").call(); + git.commit().setMessage("main").call(); - writeTrashFile("c", "1\nc(main)\n3\n"); - writeTrashFile("d/d/d", "1\nd(main)\n3\n"); - git.add().addFilepattern("c").addFilepattern("d/d/d").call(); - git.commit().setMessage("main").call(); + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + assertEquals("1\na\n3\n", read(new File(db.getWorkTree(), "a"))); + assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); + assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), "c"))); + assertEquals("1\nd(main)\n3\n", read(new File(db.getWorkTree(), "d/d/d"))); - assertEquals("1\na\n3\n", read(new File(db.getWorkTree(), "a"))); - assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); - assertEquals("1\nc(main)\n3\n", read(new File(db.getWorkTree(), "c"))); - assertEquals("1\nd(main)\n3\n", read(new File(db.getWorkTree(), "d/d/d"))); + assertEquals(null, result.getConflicts()); - assertEquals(null, result.getConflicts()); - - assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + assertEquals(RepositoryState.MERGING, db.getRepositoryState()); + } } @Test public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception { - Git git = new Git(db); - - File fileA = writeTrashFile("a", "a"); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - // modify file a - write(fileA, "a(side)"); - writeTrashFile("b", "b"); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - checkoutBranch("refs/heads/master"); - writeTrashFile("c", "c"); - addAllAndCommit(git); - - // modify and add file a - write(fileA, "a(modified)"); - git.add().addFilepattern("a").call(); - // do not commit - - // get current index state - String indexState = indexState(CONTENT); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - - checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, - indexState, fileA); + try (Git git = new Git(db)) { + File fileA = writeTrashFile("a", "a"); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + // modify file a + write(fileA, "a(side)"); + writeTrashFile("b", "b"); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + checkoutBranch("refs/heads/master"); + writeTrashFile("c", "c"); + addAllAndCommit(git); + + // modify and add file a + write(fileA, "a(modified)"); + git.add().addFilepattern("a").call(); + // do not commit + + // get current index state + String indexState = indexState(CONTENT); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + + checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, + indexState, fileA); + } } @Test public void testConflictingMergeFailsDueToDirtyIndex() throws Exception { - Git git = new Git(db); - - File fileA = writeTrashFile("a", "a"); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - // modify file a - write(fileA, "a(side)"); - writeTrashFile("b", "b"); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - checkoutBranch("refs/heads/master"); - // modify file a - this will cause a conflict during merge - write(fileA, "a(master)"); - writeTrashFile("c", "c"); - addAllAndCommit(git); - - // modify and add file a - write(fileA, "a(modified)"); - git.add().addFilepattern("a").call(); - // do not commit - - // get current index state - String indexState = indexState(CONTENT); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - - checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, - indexState, fileA); + try (Git git = new Git(db)) { + File fileA = writeTrashFile("a", "a"); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + // modify file a + write(fileA, "a(side)"); + writeTrashFile("b", "b"); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + checkoutBranch("refs/heads/master"); + // modify file a - this will cause a conflict during merge + write(fileA, "a(master)"); + writeTrashFile("c", "c"); + addAllAndCommit(git); + + // modify and add file a + write(fileA, "a(modified)"); + git.add().addFilepattern("a").call(); + // do not commit + + // get current index state + String indexState = indexState(CONTENT); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + + checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, + indexState, fileA); + } } @Test public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception { - Git git = new Git(db); - - File fileA = writeTrashFile("a", "a"); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - // modify file a - write(fileA, "a(side)"); - writeTrashFile("b", "b"); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - checkoutBranch("refs/heads/master"); - writeTrashFile("c", "c"); - addAllAndCommit(git); - - // modify file a - write(fileA, "a(modified)"); - // do not add and commit - - // get current index state - String indexState = indexState(CONTENT); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - - checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, - indexState, fileA); + try (Git git = new Git(db)) { + File fileA = writeTrashFile("a", "a"); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + // modify file a + write(fileA, "a(side)"); + writeTrashFile("b", "b"); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + checkoutBranch("refs/heads/master"); + writeTrashFile("c", "c"); + addAllAndCommit(git); + + // modify file a + write(fileA, "a(modified)"); + // do not add and commit + + // get current index state + String indexState = indexState(CONTENT); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + + checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, + indexState, fileA); + } } @Test public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception { - Git git = new Git(db); - - File fileA = writeTrashFile("a", "a"); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - // modify file a - write(fileA, "a(side)"); - writeTrashFile("b", "b"); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - checkoutBranch("refs/heads/master"); - // modify file a - this will cause a conflict during merge - write(fileA, "a(master)"); - writeTrashFile("c", "c"); - addAllAndCommit(git); - - // modify file a - write(fileA, "a(modified)"); - // do not add and commit - - // get current index state - String indexState = indexState(CONTENT); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - - checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, - indexState, fileA); + try (Git git = new Git(db)) { + File fileA = writeTrashFile("a", "a"); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + // modify file a + write(fileA, "a(side)"); + writeTrashFile("b", "b"); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + checkoutBranch("refs/heads/master"); + // modify file a - this will cause a conflict during merge + write(fileA, "a(master)"); + writeTrashFile("c", "c"); + addAllAndCommit(git); + + // modify file a + write(fileA, "a(modified)"); + // do not add and commit + + // get current index state + String indexState = indexState(CONTENT); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + + checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, + indexState, fileA); + } } @Test @@ -1143,29 +1147,30 @@ public class MergeCommandTest extends RepositoryTestCase { file = new File(folder2, "file2.txt"); write(file, "folder2--file2.txt"); - Git git = new Git(db); - git.add().addFilepattern(folder1.getName()) - .addFilepattern(folder2.getName()).call(); - RevCommit commit1 = git.commit().setMessage("adding folders").call(); - - recursiveDelete(folder1); - recursiveDelete(folder2); - git.rm().addFilepattern("folder1/file1.txt") - .addFilepattern("folder1/file2.txt") - .addFilepattern("folder2/file1.txt") - .addFilepattern("folder2/file2.txt").call(); - RevCommit commit2 = git.commit() - .setMessage("removing folders on 'branch'").call(); - - git.checkout().setName(commit1.name()).call(); - - MergeResult result = git.merge().include(commit2.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD, - result.getMergeStatus()); - assertEquals(commit2, result.getNewHead()); - assertFalse(folder1.exists()); - assertFalse(folder2.exists()); + try (Git git = new Git(db)) { + git.add().addFilepattern(folder1.getName()) + .addFilepattern(folder2.getName()).call(); + RevCommit commit1 = git.commit().setMessage("adding folders").call(); + + recursiveDelete(folder1); + recursiveDelete(folder2); + git.rm().addFilepattern("folder1/file1.txt") + .addFilepattern("folder1/file2.txt") + .addFilepattern("folder2/file1.txt") + .addFilepattern("folder2/file2.txt").call(); + RevCommit commit2 = git.commit() + .setMessage("removing folders on 'branch'").call(); + + git.checkout().setName(commit1.name()).call(); + + MergeResult result = git.merge().include(commit2.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD, + result.getMergeStatus()); + assertEquals(commit2, result.getNewHead()); + assertFalse(folder1.exists()); + assertFalse(folder2.exists()); + } } @Test @@ -1183,34 +1188,35 @@ public class MergeCommandTest extends RepositoryTestCase { file = new File(folder2, "file2.txt"); write(file, "folder2--file2.txt"); - Git git = new Git(db); - git.add().addFilepattern(folder1.getName()) - .addFilepattern(folder2.getName()).call(); - RevCommit base = git.commit().setMessage("adding folders").call(); + try (Git git = new Git(db)) { + git.add().addFilepattern(folder1.getName()) + .addFilepattern(folder2.getName()).call(); + RevCommit base = git.commit().setMessage("adding folders").call(); - recursiveDelete(folder1); - recursiveDelete(folder2); - git.rm().addFilepattern("folder1/file1.txt") - .addFilepattern("folder1/file2.txt") - .addFilepattern("folder2/file1.txt") - .addFilepattern("folder2/file2.txt").call(); - RevCommit other = git.commit() - .setMessage("removing folders on 'branch'").call(); + recursiveDelete(folder1); + recursiveDelete(folder2); + git.rm().addFilepattern("folder1/file1.txt") + .addFilepattern("folder1/file2.txt") + .addFilepattern("folder2/file1.txt") + .addFilepattern("folder2/file2.txt").call(); + RevCommit other = git.commit() + .setMessage("removing folders on 'branch'").call(); - git.checkout().setName(base.name()).call(); + git.checkout().setName(base.name()).call(); - file = new File(folder2, "file3.txt"); - write(file, "folder2--file3.txt"); + file = new File(folder2, "file3.txt"); + write(file, "folder2--file3.txt"); - git.add().addFilepattern(folder2.getName()).call(); - git.commit().setMessage("adding another file").call(); + git.add().addFilepattern(folder2.getName()).call(); + git.commit().setMessage("adding another file").call(); - MergeResult result = git.merge().include(other.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); + MergeResult result = git.merge().include(other.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeResult.MergeStatus.MERGED, - result.getMergeStatus()); - assertFalse(folder1.exists()); + assertEquals(MergeResult.MergeStatus.MERGED, + result.getMergeStatus()); + assertFalse(folder1.exists()); + } } @Test @@ -1218,38 +1224,38 @@ public class MergeCommandTest extends RepositoryTestCase { if (!FS.DETECTED.supportsExecute()) return; // Only Java6 - Git git = new Git(db); - - writeTrashFile("mergeableMode", "a"); - setExecutable(git, "mergeableMode", false); - writeTrashFile("conflictingModeWithBase", "a"); - setExecutable(git, "conflictingModeWithBase", false); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - setExecutable(git, "mergeableMode", true); - writeTrashFile("conflictingModeNoBase", "b"); - setExecutable(git, "conflictingModeNoBase", true); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side2"); - checkoutBranch("refs/heads/side2"); - setExecutable(git, "mergeableMode", false); - assertFalse(new File(git.getRepository().getWorkTree(), - "conflictingModeNoBase").exists()); - writeTrashFile("conflictingModeNoBase", "b"); - setExecutable(git, "conflictingModeNoBase", false); - addAllAndCommit(git); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - assertTrue(canExecute(git, "mergeableMode")); - assertFalse(canExecute(git, "conflictingModeNoBase")); + try (Git git = new Git(db)) { + writeTrashFile("mergeableMode", "a"); + setExecutable(git, "mergeableMode", false); + writeTrashFile("conflictingModeWithBase", "a"); + setExecutable(git, "conflictingModeWithBase", false); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + setExecutable(git, "mergeableMode", true); + writeTrashFile("conflictingModeNoBase", "b"); + setExecutable(git, "conflictingModeNoBase", true); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side2"); + checkoutBranch("refs/heads/side2"); + setExecutable(git, "mergeableMode", false); + assertFalse(new File(git.getRepository().getWorkTree(), + "conflictingModeNoBase").exists()); + writeTrashFile("conflictingModeNoBase", "b"); + setExecutable(git, "conflictingModeNoBase", false); + addAllAndCommit(git); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + assertTrue(canExecute(git, "mergeableMode")); + assertFalse(canExecute(git, "conflictingModeNoBase")); + } } @Test @@ -1258,291 +1264,295 @@ public class MergeCommandTest extends RepositoryTestCase { return; // Only Java6 (or set x bit in index) - Git git = new Git(db); - - writeTrashFile("mergeableButDirty", "a"); - setExecutable(git, "mergeableButDirty", false); - RevCommit initialCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - setExecutable(git, "mergeableButDirty", true); - RevCommit sideCommit = addAllAndCommit(git); - - // switch branch - createBranch(initialCommit, "refs/heads/side2"); - checkoutBranch("refs/heads/side2"); - setExecutable(git, "mergeableButDirty", false); - addAllAndCommit(git); - - writeTrashFile("mergeableButDirty", "b"); - - // merge - MergeResult result = git.merge().include(sideCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.FAILED, result.getMergeStatus()); - assertFalse(canExecute(git, "mergeableButDirty")); + try (Git git = new Git(db)) { + writeTrashFile("mergeableButDirty", "a"); + setExecutable(git, "mergeableButDirty", false); + RevCommit initialCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + setExecutable(git, "mergeableButDirty", true); + RevCommit sideCommit = addAllAndCommit(git); + + // switch branch + createBranch(initialCommit, "refs/heads/side2"); + checkoutBranch("refs/heads/side2"); + setExecutable(git, "mergeableButDirty", false); + addAllAndCommit(git); + + writeTrashFile("mergeableButDirty", "b"); + + // merge + MergeResult result = git.merge().include(sideCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.FAILED, result.getMergeStatus()); + assertFalse(canExecute(git, "mergeableButDirty")); + } } @Test public void testSquashFastForward() throws Exception { - Git git = new Git(db); - - writeTrashFile("file1", "file1"); - git.add().addFilepattern("file1").call(); - RevCommit first = git.commit().setMessage("initial commit").call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - createBranch(first, "refs/heads/branch1"); - checkoutBranch("refs/heads/branch1"); - - writeTrashFile("file2", "file2"); - git.add().addFilepattern("file2").call(); - RevCommit second = git.commit().setMessage("second commit").call(); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - - writeTrashFile("file3", "file3"); - git.add().addFilepattern("file3").call(); - RevCommit third = git.commit().setMessage("third commit").call(); - assertTrue(new File(db.getWorkTree(), "file3").exists()); - - checkoutBranch("refs/heads/master"); - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertFalse(new File(db.getWorkTree(), "file2").exists()); - assertFalse(new File(db.getWorkTree(), "file3").exists()); - - MergeResult result = git.merge() - .include(db.exactRef("refs/heads/branch1")) - .setSquash(true) - .call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - assertTrue(new File(db.getWorkTree(), "file3").exists()); - assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED, - result.getMergeStatus()); - assertEquals(first, result.getNewHead()); // HEAD didn't move - assertEquals(first, db.resolve(Constants.HEAD + "^{commit}")); - - assertEquals( - "Squashed commit of the following:\n\ncommit " - + third.getName() - + "\nAuthor: " - + third.getAuthorIdent().getName() - + " <" - + third.getAuthorIdent().getEmailAddress() - + ">\nDate: " - + dateFormatter.formatDate(third - .getAuthorIdent()) - + "\n\n\tthird commit\n\ncommit " - + second.getName() - + "\nAuthor: " - + second.getAuthorIdent().getName() - + " <" - + second.getAuthorIdent().getEmailAddress() - + ">\nDate: " - + dateFormatter.formatDate(second - .getAuthorIdent()) + "\n\n\tsecond commit\n", - db.readSquashCommitMsg()); - assertNull(db.readMergeCommitMsg()); - - Status stat = git.status().call(); - assertEquals(Sets.of("file2", "file3"), stat.getAdded()); + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit first = git.commit().setMessage("initial commit").call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + createBranch(first, "refs/heads/branch1"); + checkoutBranch("refs/heads/branch1"); + + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + RevCommit second = git.commit().setMessage("second commit").call(); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + + writeTrashFile("file3", "file3"); + git.add().addFilepattern("file3").call(); + RevCommit third = git.commit().setMessage("third commit").call(); + assertTrue(new File(db.getWorkTree(), "file3").exists()); + + checkoutBranch("refs/heads/master"); + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertFalse(new File(db.getWorkTree(), "file2").exists()); + assertFalse(new File(db.getWorkTree(), "file3").exists()); + + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + assertTrue(new File(db.getWorkTree(), "file3").exists()); + assertEquals(MergeResult.MergeStatus.FAST_FORWARD_SQUASHED, + result.getMergeStatus()); + assertEquals(first, result.getNewHead()); // HEAD didn't move + assertEquals(first, db.resolve(Constants.HEAD + "^{commit}")); + + assertEquals( + "Squashed commit of the following:\n\ncommit " + + third.getName() + + "\nAuthor: " + + third.getAuthorIdent().getName() + + " <" + + third.getAuthorIdent().getEmailAddress() + + ">\nDate: " + + dateFormatter.formatDate(third + .getAuthorIdent()) + + "\n\n\tthird commit\n\ncommit " + + second.getName() + + "\nAuthor: " + + second.getAuthorIdent().getName() + + " <" + + second.getAuthorIdent().getEmailAddress() + + ">\nDate: " + + dateFormatter.formatDate(second + .getAuthorIdent()) + "\n\n\tsecond commit\n", + db.readSquashCommitMsg()); + assertNull(db.readMergeCommitMsg()); + + Status stat = git.status().call(); + assertEquals(Sets.of("file2", "file3"), stat.getAdded()); + } } @Test public void testSquashMerge() throws Exception { - Git git = new Git(db); - - writeTrashFile("file1", "file1"); - git.add().addFilepattern("file1").call(); - RevCommit first = git.commit().setMessage("initial commit").call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - createBranch(first, "refs/heads/branch1"); - - writeTrashFile("file2", "file2"); - git.add().addFilepattern("file2").call(); - RevCommit second = git.commit().setMessage("second commit").call(); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - - checkoutBranch("refs/heads/branch1"); - - writeTrashFile("file3", "file3"); - git.add().addFilepattern("file3").call(); - RevCommit third = git.commit().setMessage("third commit").call(); - assertTrue(new File(db.getWorkTree(), "file3").exists()); - - checkoutBranch("refs/heads/master"); - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - assertFalse(new File(db.getWorkTree(), "file3").exists()); - - MergeResult result = git.merge() - .include(db.exactRef("refs/heads/branch1")) - .setSquash(true) - .call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - assertTrue(new File(db.getWorkTree(), "file3").exists()); - assertEquals(MergeResult.MergeStatus.MERGED_SQUASHED, - result.getMergeStatus()); - assertEquals(second, result.getNewHead()); // HEAD didn't move - assertEquals(second, db.resolve(Constants.HEAD + "^{commit}")); - - assertEquals( - "Squashed commit of the following:\n\ncommit " - + third.getName() - + "\nAuthor: " - + third.getAuthorIdent().getName() - + " <" - + third.getAuthorIdent().getEmailAddress() - + ">\nDate: " - + dateFormatter.formatDate(third - .getAuthorIdent()) + "\n\n\tthird commit\n", - db.readSquashCommitMsg()); - assertNull(db.readMergeCommitMsg()); - - Status stat = git.status().call(); - assertEquals(Sets.of("file3"), stat.getAdded()); + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit first = git.commit().setMessage("initial commit").call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + createBranch(first, "refs/heads/branch1"); + + writeTrashFile("file2", "file2"); + git.add().addFilepattern("file2").call(); + RevCommit second = git.commit().setMessage("second commit").call(); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + + checkoutBranch("refs/heads/branch1"); + + writeTrashFile("file3", "file3"); + git.add().addFilepattern("file3").call(); + RevCommit third = git.commit().setMessage("third commit").call(); + assertTrue(new File(db.getWorkTree(), "file3").exists()); + + checkoutBranch("refs/heads/master"); + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + assertFalse(new File(db.getWorkTree(), "file3").exists()); + + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + assertTrue(new File(db.getWorkTree(), "file3").exists()); + assertEquals(MergeResult.MergeStatus.MERGED_SQUASHED, + result.getMergeStatus()); + assertEquals(second, result.getNewHead()); // HEAD didn't move + assertEquals(second, db.resolve(Constants.HEAD + "^{commit}")); + + assertEquals( + "Squashed commit of the following:\n\ncommit " + + third.getName() + + "\nAuthor: " + + third.getAuthorIdent().getName() + + " <" + + third.getAuthorIdent().getEmailAddress() + + ">\nDate: " + + dateFormatter.formatDate(third + .getAuthorIdent()) + "\n\n\tthird commit\n", + db.readSquashCommitMsg()); + assertNull(db.readMergeCommitMsg()); + + Status stat = git.status().call(); + assertEquals(Sets.of("file3"), stat.getAdded()); + } } @Test public void testSquashMergeConflict() throws Exception { - Git git = new Git(db); - - writeTrashFile("file1", "file1"); - git.add().addFilepattern("file1").call(); - RevCommit first = git.commit().setMessage("initial commit").call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - createBranch(first, "refs/heads/branch1"); - - writeTrashFile("file2", "master"); - git.add().addFilepattern("file2").call(); - RevCommit second = git.commit().setMessage("second commit").call(); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - - checkoutBranch("refs/heads/branch1"); - - writeTrashFile("file2", "branch"); - git.add().addFilepattern("file2").call(); - RevCommit third = git.commit().setMessage("third commit").call(); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - - checkoutBranch("refs/heads/master"); - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - - MergeResult result = git.merge() - .include(db.exactRef("refs/heads/branch1")) - .setSquash(true) - .call(); - - assertTrue(new File(db.getWorkTree(), "file1").exists()); - assertTrue(new File(db.getWorkTree(), "file2").exists()); - assertEquals(MergeResult.MergeStatus.CONFLICTING, - result.getMergeStatus()); - assertNull(result.getNewHead()); - assertEquals(second, db.resolve(Constants.HEAD + "^{commit}")); - - assertEquals( - "Squashed commit of the following:\n\ncommit " - + third.getName() - + "\nAuthor: " - + third.getAuthorIdent().getName() - + " <" - + third.getAuthorIdent().getEmailAddress() - + ">\nDate: " - + dateFormatter.formatDate(third - .getAuthorIdent()) + "\n\n\tthird commit\n", - db.readSquashCommitMsg()); - assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg()); - - Status stat = git.status().call(); - assertEquals(Sets.of("file2"), stat.getConflicting()); + try (Git git = new Git(db)) { + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + RevCommit first = git.commit().setMessage("initial commit").call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + createBranch(first, "refs/heads/branch1"); + + writeTrashFile("file2", "master"); + git.add().addFilepattern("file2").call(); + RevCommit second = git.commit().setMessage("second commit").call(); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + + checkoutBranch("refs/heads/branch1"); + + writeTrashFile("file2", "branch"); + git.add().addFilepattern("file2").call(); + RevCommit third = git.commit().setMessage("third commit").call(); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + + checkoutBranch("refs/heads/master"); + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + + MergeResult result = git.merge() + .include(db.exactRef("refs/heads/branch1")) + .setSquash(true) + .call(); + + assertTrue(new File(db.getWorkTree(), "file1").exists()); + assertTrue(new File(db.getWorkTree(), "file2").exists()); + assertEquals(MergeResult.MergeStatus.CONFLICTING, + result.getMergeStatus()); + assertNull(result.getNewHead()); + assertEquals(second, db.resolve(Constants.HEAD + "^{commit}")); + + assertEquals( + "Squashed commit of the following:\n\ncommit " + + third.getName() + + "\nAuthor: " + + third.getAuthorIdent().getName() + + " <" + + third.getAuthorIdent().getEmailAddress() + + ">\nDate: " + + dateFormatter.formatDate(third + .getAuthorIdent()) + "\n\n\tthird commit\n", + db.readSquashCommitMsg()); + assertEquals("\nConflicts:\n\tfile2\n", db.readMergeCommitMsg()); + + Status stat = git.status().call(); + assertEquals(Sets.of("file2"), stat.getConflicting()); + } } @Test public void testFastForwardOnly() throws Exception { - Git git = new Git(db); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - createBranch(initialCommit, "refs/heads/branch1"); - git.commit().setMessage("second commit").call(); - checkoutBranch("refs/heads/branch1"); - - MergeCommand merge = git.merge(); - merge.setFastForward(FastForwardMode.FF_ONLY); - merge.include(db.exactRef(R_HEADS + MASTER)); - MergeResult result = merge.call(); - - assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); + try (Git git = new Git(db)) { + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + createBranch(initialCommit, "refs/heads/branch1"); + git.commit().setMessage("second commit").call(); + checkoutBranch("refs/heads/branch1"); + + MergeCommand merge = git.merge(); + merge.setFastForward(FastForwardMode.FF_ONLY); + merge.include(db.exactRef(R_HEADS + MASTER)); + MergeResult result = merge.call(); + + assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); + } } @Test public void testNoFastForward() throws Exception { - Git git = new Git(db); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - createBranch(initialCommit, "refs/heads/branch1"); - git.commit().setMessage("second commit").call(); - checkoutBranch("refs/heads/branch1"); - - MergeCommand merge = git.merge(); - merge.setFastForward(FastForwardMode.NO_FF); - merge.include(db.exactRef(R_HEADS + MASTER)); - MergeResult result = merge.call(); - - assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + try (Git git = new Git(db)) { + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + createBranch(initialCommit, "refs/heads/branch1"); + git.commit().setMessage("second commit").call(); + checkoutBranch("refs/heads/branch1"); + + MergeCommand merge = git.merge(); + merge.setFastForward(FastForwardMode.NO_FF); + merge.include(db.exactRef(R_HEADS + MASTER)); + MergeResult result = merge.call(); + + assertEquals(MergeStatus.MERGED, result.getMergeStatus()); + } } @Test public void testNoFastForwardNoCommit() throws Exception { // given - Git git = new Git(db); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - createBranch(initialCommit, "refs/heads/branch1"); - RevCommit secondCommit = git.commit().setMessage("second commit") - .call(); - checkoutBranch("refs/heads/branch1"); - - // when - MergeCommand merge = git.merge(); - merge.setFastForward(FastForwardMode.NO_FF); - merge.include(db.exactRef(R_HEADS + MASTER)); - merge.setCommit(false); - MergeResult result = merge.call(); - - // then - assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); - assertEquals(2, result.getMergedCommits().length); - assertEquals(initialCommit, result.getMergedCommits()[0]); - assertEquals(secondCommit, result.getMergedCommits()[1]); - assertNull(result.getNewHead()); - assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); + try (Git git = new Git(db)) { + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + createBranch(initialCommit, "refs/heads/branch1"); + RevCommit secondCommit = git.commit().setMessage("second commit") + .call(); + checkoutBranch("refs/heads/branch1"); + + // when + MergeCommand merge = git.merge(); + merge.setFastForward(FastForwardMode.NO_FF); + merge.include(db.exactRef(R_HEADS + MASTER)); + merge.setCommit(false); + MergeResult result = merge.call(); + + // then + assertEquals(MergeStatus.MERGED_NOT_COMMITTED, result.getMergeStatus()); + assertEquals(2, result.getMergedCommits().length); + assertEquals(initialCommit, result.getMergedCommits()[0]); + assertEquals(secondCommit, result.getMergedCommits()[1]); + assertNull(result.getNewHead()); + assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); + } } @Test public void testFastForwardOnlyNotPossible() throws Exception { - Git git = new Git(db); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - createBranch(initialCommit, "refs/heads/branch1"); - git.commit().setMessage("second commit").call(); - checkoutBranch("refs/heads/branch1"); - writeTrashFile("file1", "branch1"); - git.add().addFilepattern("file").call(); - git.commit().setMessage("second commit on branch1").call(); - MergeCommand merge = git.merge(); - merge.setFastForward(FastForwardMode.FF_ONLY); - merge.include(db.exactRef(R_HEADS + MASTER)); - MergeResult result = merge.call(); - - assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); + try (Git git = new Git(db)) { + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + createBranch(initialCommit, "refs/heads/branch1"); + git.commit().setMessage("second commit").call(); + checkoutBranch("refs/heads/branch1"); + writeTrashFile("file1", "branch1"); + git.add().addFilepattern("file").call(); + git.commit().setMessage("second commit on branch1").call(); + MergeCommand merge = git.merge(); + merge.setFastForward(FastForwardMode.FF_ONLY); + merge.include(db.exactRef(R_HEADS + MASTER)); + MergeResult result = merge.call(); + + assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); + } } @Test @@ -1577,65 +1587,65 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testMergeWithMessageOption() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("side").call(); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("side").call(); - checkoutBranch("refs/heads/master"); + checkoutBranch("refs/heads/master"); - writeTrashFile("c", "1\nc\n3\n"); - git.add().addFilepattern("c").call(); - git.commit().setMessage("main").call(); + writeTrashFile("c", "1\nc\n3\n"); + git.add().addFilepattern("c").call(); + git.commit().setMessage("main").call(); - Ref sideBranch = db.exactRef("refs/heads/side"); + Ref sideBranch = db.exactRef("refs/heads/side"); - git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) - .setMessage("user message").call(); + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setMessage("user message").call(); - assertNull(db.readMergeCommitMsg()); + assertNull(db.readMergeCommitMsg()); - Iterator it = git.log().call().iterator(); - RevCommit newHead = it.next(); - assertEquals("user message", newHead.getFullMessage()); + Iterator it = git.log().call().iterator(); + RevCommit newHead = it.next(); + assertEquals("user message", newHead.getFullMessage()); + } } @Test public void testMergeConflictWithMessageOption() throws Exception { - Git git = new Git(db); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + writeTrashFile("a", "1\na(side)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("side").call(); - writeTrashFile("a", "1\na(side)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("side").call(); + checkoutBranch("refs/heads/master"); - checkoutBranch("refs/heads/master"); + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); - writeTrashFile("a", "1\na(main)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); + Ref sideBranch = db.exactRef("refs/heads/side"); - Ref sideBranch = db.exactRef("refs/heads/side"); + git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) + .setMessage("user message").call(); - git.merge().include(sideBranch).setStrategy(MergeStrategy.RESOLVE) - .setMessage("user message").call(); - - assertEquals("user message\n\nConflicts:\n\ta\n", - db.readMergeCommitMsg()); + assertEquals("user message\n\nConflicts:\n\ta\n", + db.readMergeCommitMsg()); + } } private static void setExecutable(Git git, String path, boolean executable) { From 61bb701eebb8b6701510dff392f6370a54358e13 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Fri, 12 Feb 2016 14:41:44 +0900 Subject: [PATCH 02/22] MergeCommandTest: Use JUnit's assume to check preconditions Using the assume method, instead of just returning, will cause the test to be marked as skipped rather than passed on systems where the precondition is not satisfied. Change-Id: I13672371f6cd3c481a0a6247e0eaed3aac6d766e Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/api/MergeCommandTest.java | 7 +++---- 1 file changed, 3 insertions(+), 4 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 b51c2beff..cb3dbf1bc 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 @@ -50,6 +50,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; import java.io.File; import java.util.Iterator; @@ -1221,9 +1222,8 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testFileModeMerge() throws Exception { - if (!FS.DETECTED.supportsExecute()) - return; // Only Java6 + assumeTrue(FS.DETECTED.supportsExecute()); try (Git git = new Git(db)) { writeTrashFile("mergeableMode", "a"); setExecutable(git, "mergeableMode", false); @@ -1260,9 +1260,8 @@ public class MergeCommandTest extends RepositoryTestCase { @Test public void testFileModeMergeWithDirtyWorkTree() throws Exception { - if (!FS.DETECTED.supportsExecute()) - return; // Only Java6 (or set x bit in index) + assumeTrue(FS.DETECTED.supportsExecute()); try (Git git = new Git(db)) { writeTrashFile("mergeableButDirty", "a"); From 29159f1171c4930128ab0557836e856ce8cba6c8 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Sun, 14 Feb 2016 23:58:51 +0100 Subject: [PATCH 03/22] JGit v4.1.2.201602141800-r Change-Id: If0721109f389835a3a00b1a97559fd8f8c156556 Signed-off-by: Matthias Sohn --- org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.ant.test/pom.xml | 2 +- org.eclipse.jgit.ant/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.ant/pom.xml | 2 +- org.eclipse.jgit.archive/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF | 4 ++-- org.eclipse.jgit.archive/pom.xml | 2 +- org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.http.apache/pom.xml | 2 +- org.eclipse.jgit.http.server/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.http.server/pom.xml | 2 +- org.eclipse.jgit.http.test/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.http.test/pom.xml | 2 +- org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.junit.http/pom.xml | 2 +- org.eclipse.jgit.junit/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.junit/pom.xml | 2 +- .../org.eclipse.jgit.feature/feature.xml | 2 +- org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml | 2 +- .../org.eclipse.jgit.http.apache.feature/feature.xml | 2 +- .../org.eclipse.jgit.http.apache.feature/pom.xml | 2 +- .../org.eclipse.jgit.junit.feature/feature.xml | 2 +- .../org.eclipse.jgit.junit.feature/pom.xml | 2 +- .../org.eclipse.jgit.pgm.feature/feature.xml | 2 +- .../org.eclipse.jgit.pgm.feature/pom.xml | 2 +- .../org.eclipse.jgit.pgm.source.feature/feature.xml | 2 +- .../org.eclipse.jgit.pgm.source.feature/pom.xml | 2 +- .../org.eclipse.jgit.repository/pom.xml | 2 +- .../org.eclipse.jgit.source.feature/feature.xml | 2 +- .../org.eclipse.jgit.source.feature/pom.xml | 2 +- .../org.eclipse.jgit.target/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml | 2 +- org.eclipse.jgit.packaging/pom.xml | 2 +- org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.pgm.test/pom.xml | 2 +- org.eclipse.jgit.pgm/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF | 4 ++-- org.eclipse.jgit.pgm/pom.xml | 2 +- org.eclipse.jgit.test/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.test/pom.xml | 2 +- org.eclipse.jgit.ui/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit.ui/pom.xml | 2 +- org.eclipse.jgit/META-INF/MANIFEST.MF | 2 +- org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF | 4 ++-- org.eclipse.jgit/pom.xml | 2 +- pom.xml | 2 +- 46 files changed, 49 insertions(+), 49 deletions(-) diff --git a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF index 8f5d0b90d..83051f9c8 100644 --- a/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ant.test/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.ant.test -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-ActivationPolicy: lazy Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: org.apache.tools.ant, diff --git a/org.eclipse.jgit.ant.test/pom.xml b/org.eclipse.jgit.ant.test/pom.xml index a514e3dbc..67e6c38a8 100644 --- a/org.eclipse.jgit.ant.test/pom.xml +++ b/org.eclipse.jgit.ant.test/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.ant.test diff --git a/org.eclipse.jgit.ant/META-INF/MANIFEST.MF b/org.eclipse.jgit.ant/META-INF/MANIFEST.MF index 4986f0fbb..5ff9fd511 100644 --- a/org.eclipse.jgit.ant/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ant/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.jgit.ant -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Import-Package: org.apache.tools.ant, org.eclipse.jgit.storage.file;version="[4.1.2,4.2.0)" diff --git a/org.eclipse.jgit.ant/pom.xml b/org.eclipse.jgit.ant/pom.xml index cb0fcb0a1..f40e0f736 100644 --- a/org.eclipse.jgit.ant/pom.xml +++ b/org.eclipse.jgit.ant/pom.xml @@ -48,7 +48,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.ant diff --git a/org.eclipse.jgit.archive/META-INF/MANIFEST.MF b/org.eclipse.jgit.archive/META-INF/MANIFEST.MF index 4b1e81d40..3787f8675 100644 --- a/org.eclipse.jgit.archive/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.archive/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.archive -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Vendor: %provider_name Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.7 diff --git a/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF index cc3181962..d1f674ddb 100644 --- a/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit.archive/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit.archive - Sources Bundle-SymbolicName: org.eclipse.jgit.archive.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 4.1.2.qualifier -Eclipse-SourceBundle: org.eclipse.jgit.archive;version="4.1.2.qualifier";roots="." +Bundle-Version: 4.1.2.201602141800-r +Eclipse-SourceBundle: org.eclipse.jgit.archive;version="4.1.2.201602141800-r";roots="." diff --git a/org.eclipse.jgit.archive/pom.xml b/org.eclipse.jgit.archive/pom.xml index 1127a773f..377d8128c 100644 --- a/org.eclipse.jgit.archive/pom.xml +++ b/org.eclipse.jgit.archive/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.archive diff --git a/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF index 700badbca..182262f5e 100644 --- a/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.apache/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %Bundle-Name Bundle-SymbolicName: org.eclipse.jgit.http.apache -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Localization: plugin Bundle-Vendor: %Provider-Name diff --git a/org.eclipse.jgit.http.apache/pom.xml b/org.eclipse.jgit.http.apache/pom.xml index dee349cd8..7510088dc 100644 --- a/org.eclipse.jgit.http.apache/pom.xml +++ b/org.eclipse.jgit.http.apache/pom.xml @@ -48,7 +48,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.http.apache diff --git a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF index 85e1dd7d4..b66606c6d 100644 --- a/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.server/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.http.server -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Localization: plugin Bundle-Vendor: %provider_name Export-Package: org.eclipse.jgit.http.server;version="4.1.2", diff --git a/org.eclipse.jgit.http.server/pom.xml b/org.eclipse.jgit.http.server/pom.xml index 8707e0153..ea60b00ab 100644 --- a/org.eclipse.jgit.http.server/pom.xml +++ b/org.eclipse.jgit.http.server/pom.xml @@ -52,7 +52,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.http.server diff --git a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF index cff5d24fa..a5bf31a08 100644 --- a/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.http.test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.http.test -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Vendor: %provider_name Bundle-Localization: plugin Bundle-RequiredExecutionEnvironment: JavaSE-1.7 diff --git a/org.eclipse.jgit.http.test/pom.xml b/org.eclipse.jgit.http.test/pom.xml index 8f7cd03fd..17128ed70 100644 --- a/org.eclipse.jgit.http.test/pom.xml +++ b/org.eclipse.jgit.http.test/pom.xml @@ -51,7 +51,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.http.test diff --git a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF index aa1dc8b2f..8a5ee6caa 100644 --- a/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit.http/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.junit.http -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit.junit.http/pom.xml b/org.eclipse.jgit.junit.http/pom.xml index 40cdca158..d25ae009e 100644 --- a/org.eclipse.jgit.junit.http/pom.xml +++ b/org.eclipse.jgit.junit.http/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.junit.http diff --git a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF index 048f65d8f..ea32b1b4b 100644 --- a/org.eclipse.jgit.junit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.junit/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.junit -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit.junit/pom.xml b/org.eclipse.jgit.junit/pom.xml index 53f1bdcc8..d3616a714 100644 --- a/org.eclipse.jgit.junit/pom.xml +++ b/org.eclipse.jgit.junit/pom.xml @@ -52,7 +52,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.junit diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml index 43575f525..09b59b0c7 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml index f7ef5ee25..ce0f9b940 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml index f54ec78c5..31295cf35 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml index 8be8b18b9..350de3c9a 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.http.apache.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml index 8dbf9f8a3..cb9fbf36c 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml index aa1d85cdc..cb76911b5 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.junit.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml index 084c49f16..e1dcfcd31 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml index 6010467d6..9076053eb 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml index 8e13dc939..bbd0aa0b8 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml index b72f82f45..0e64da423 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.pgm.source.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml index d7c1f6ad7..88ad03242 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.repository/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.repository diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml index 9a7e6e0ba..17030ff48 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/feature.xml @@ -2,7 +2,7 @@ diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml index d71064311..aa7128e13 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.source.feature/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.feature diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF index 60492325c..38732b581 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/META-INF/MANIFEST.MF @@ -2,4 +2,4 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: JGit Target Platform Bundle Bundle-SymbolicName: org.eclipse.jgit.target -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r diff --git a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml index e8e036ed4..9b565ecdd 100644 --- a/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml +++ b/org.eclipse.jgit.packaging/org.eclipse.jgit.target/pom.xml @@ -49,7 +49,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.target diff --git a/org.eclipse.jgit.packaging/pom.xml b/org.eclipse.jgit.packaging/pom.xml index e1f71cbd7..3b5b7d822 100644 --- a/org.eclipse.jgit.packaging/pom.xml +++ b/org.eclipse.jgit.packaging/pom.xml @@ -53,7 +53,7 @@ org.eclipse.jgit jgit.tycho.parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r pom JGit Tycho Parent diff --git a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF index 08a08a828..1693bee1c 100644 --- a/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm.test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.pgm.test -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Vendor: %provider_name Bundle-Localization: plugin Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit.pgm.test/pom.xml b/org.eclipse.jgit.pgm.test/pom.xml index 132645b97..cca2e92c6 100644 --- a/org.eclipse.jgit.pgm.test/pom.xml +++ b/org.eclipse.jgit.pgm.test/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.pgm.test diff --git a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF index 3a78d94df..7d00a96ba 100644 --- a/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.pgm -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy Bundle-Localization: plugin diff --git a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF index 303ebf44f..215f8e7ec 100644 --- a/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit.pgm/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit.pgm - Sources Bundle-SymbolicName: org.eclipse.jgit.pgm.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 4.1.2.qualifier -Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="4.1.2.qualifier";roots="." +Bundle-Version: 4.1.2.201602141800-r +Eclipse-SourceBundle: org.eclipse.jgit.pgm;version="4.1.2.201602141800-r";roots="." diff --git a/org.eclipse.jgit.pgm/pom.xml b/org.eclipse.jgit.pgm/pom.xml index 42fde6fe9..f84e7469f 100644 --- a/org.eclipse.jgit.pgm/pom.xml +++ b/org.eclipse.jgit.pgm/pom.xml @@ -50,7 +50,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.pgm diff --git a/org.eclipse.jgit.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.test/META-INF/MANIFEST.MF index 8f2f4284f..f059fdb32 100644 --- a/org.eclipse.jgit.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.test/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.test -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit.test/pom.xml b/org.eclipse.jgit.test/pom.xml index c174ba270..be7221151 100644 --- a/org.eclipse.jgit.test/pom.xml +++ b/org.eclipse.jgit.test/pom.xml @@ -52,7 +52,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.test diff --git a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF index 3df434701..3586cbcfc 100644 --- a/org.eclipse.jgit.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ui/META-INF/MANIFEST.MF @@ -3,7 +3,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit.ui -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Vendor: %provider_name Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Export-Package: org.eclipse.jgit.awtui;version="4.1.2" diff --git a/org.eclipse.jgit.ui/pom.xml b/org.eclipse.jgit.ui/pom.xml index 79c30f0ac..776cb8b10 100644 --- a/org.eclipse.jgit.ui/pom.xml +++ b/org.eclipse.jgit.ui/pom.xml @@ -52,7 +52,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit.ui diff --git a/org.eclipse.jgit/META-INF/MANIFEST.MF b/org.eclipse.jgit/META-INF/MANIFEST.MF index 24798be02..a51bee840 100644 --- a/org.eclipse.jgit/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %plugin_name Bundle-SymbolicName: org.eclipse.jgit -Bundle-Version: 4.1.2.qualifier +Bundle-Version: 4.1.2.201602141800-r Bundle-Localization: plugin Bundle-Vendor: %provider_name Bundle-ActivationPolicy: lazy diff --git a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF index c5476a85c..c7d9753bf 100644 --- a/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF +++ b/org.eclipse.jgit/META-INF/SOURCE-MANIFEST.MF @@ -3,5 +3,5 @@ Bundle-ManifestVersion: 2 Bundle-Name: org.eclipse.jgit - Sources Bundle-SymbolicName: org.eclipse.jgit.source Bundle-Vendor: Eclipse.org - JGit -Bundle-Version: 4.1.2.qualifier -Eclipse-SourceBundle: org.eclipse.jgit;version="4.1.2.qualifier";roots="." +Bundle-Version: 4.1.2.201602141800-r +Eclipse-SourceBundle: org.eclipse.jgit;version="4.1.2.201602141800-r";roots="." diff --git a/org.eclipse.jgit/pom.xml b/org.eclipse.jgit/pom.xml index 8791389da..945b13513 100644 --- a/org.eclipse.jgit/pom.xml +++ b/org.eclipse.jgit/pom.xml @@ -53,7 +53,7 @@ org.eclipse.jgit org.eclipse.jgit-parent - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r org.eclipse.jgit diff --git a/pom.xml b/pom.xml index 760d66fdb..fa77335e7 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ org.eclipse.jgit org.eclipse.jgit-parent pom - 4.1.2-SNAPSHOT + 4.1.2.201602141800-r JGit - Parent ${jgit-url} From 6d33322df42aff5bc25a26f66a19464b46afd826 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 14:48:02 +0900 Subject: [PATCH 04/22] LockFileTest: Open Git instance in try-with-resource Change-Id: Ie2b0e55e606f50c46e21227f23de74dbea8388e5 Signed-off-by: David Pursehouse --- .../internal/storage/file/LockFileTest.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java index 1a3a567f9..520721b6a 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java @@ -61,25 +61,26 @@ public class LockFileTest extends RepositoryTestCase { @Test public void lockFailedExceptionRecovery() throws Exception { - Git git = new Git(db); - writeTrashFile("file.txt", "content"); - git.add().addFilepattern("file.txt").call(); - RevCommit commit1 = git.commit().setMessage("create file").call(); + try (Git git = new Git(db)) { + writeTrashFile("file.txt", "content"); + git.add().addFilepattern("file.txt").call(); + RevCommit commit1 = git.commit().setMessage("create file").call(); - assertNotNull(commit1); - writeTrashFile("file.txt", "content2"); - git.add().addFilepattern("file.txt").call(); - assertNotNull(git.commit().setMessage("edit file").call()); + assertNotNull(commit1); + writeTrashFile("file.txt", "content2"); + git.add().addFilepattern("file.txt").call(); + assertNotNull(git.commit().setMessage("edit file").call()); - LockFile lf = new LockFile(db.getIndexFile(), db.getFS()); - assertTrue(lf.lock()); - try { - git.checkout().setName(commit1.name()).call(); - fail("JGitInternalException not thrown"); - } catch (JGitInternalException e) { - assertTrue(e.getCause() instanceof LockFailedException); - lf.unlock(); - git.checkout().setName(commit1.name()).call(); + LockFile lf = new LockFile(db.getIndexFile(), db.getFS()); + assertTrue(lf.lock()); + try { + git.checkout().setName(commit1.name()).call(); + fail("JGitInternalException not thrown"); + } catch (JGitInternalException e) { + assertTrue(e.getCause() instanceof LockFailedException); + lf.unlock(); + git.checkout().setName(commit1.name()).call(); + } } } } From de73fbf5972589462674c83f4e48ada9037b0405 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 14:49:58 +0900 Subject: [PATCH 05/22] InterIndexDiffFilterTest: Open TreeWalk in try-with-resource Change-Id: Ie0046771b1ab1c9784d9a3bb597a9d76c6c3017d Signed-off-by: David Pursehouse --- .../filter/InterIndexDiffFilterTest.java | 69 ++++++++++--------- 1 file changed, 37 insertions(+), 32 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java index b3aa0ee68..9f0f06732 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java @@ -76,10 +76,11 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { public void testEmpty() throws IOException { DirCache dc1 = DirCache.newInCore(); DirCache dc2 = DirCache.newInCore(); - TreeWalk tw = new TreeWalk(db); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - assertFalse(tw.next()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + assertFalse(tw.next()); + } } static final class AddEdit extends PathEdit { @@ -124,14 +125,15 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); editor.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertTrue(tw.next()); - assertEquals("a/a", tw.getPathString()); - assertFalse(tw.next()); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } } @Test @@ -145,13 +147,14 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } @Test @@ -165,15 +168,16 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertTrue(tw.next()); - assertEquals("a/a", tw.getPathString()); - assertFalse(tw.next()); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertFalse(tw.next()); + } } @Test @@ -188,12 +192,13 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase { ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true)); ed2.finish(); - TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc1)); - tw.addTree(new DirCacheIterator(dc2)); - tw.setFilter(InterIndexDiffFilter.INSTANCE); + try (TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc1)); + tw.addTree(new DirCacheIterator(dc2)); + tw.setFilter(InterIndexDiffFilter.INSTANCE); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } } From 217760fee5c8f40ad52b2f07e89a1a14b30f1cbd Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 14:51:42 +0900 Subject: [PATCH 06/22] IndexModificationTimesTest: Open Git instances in try-with-resource Change-Id: If52c071b71f5df822b1ac276a6f665515f6c9d00 Signed-off-by: David Pursehouse --- .../jgit/lib/IndexModificationTimesTest.java | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java index c6f02f4a4..b9bbbeb9e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java @@ -49,80 +49,81 @@ public class IndexModificationTimesTest extends RepositoryTestCase { @Test public void testLastModifiedTimes() throws Exception { - Git git = new Git(db); - String path = "file"; - writeTrashFile(path, "content"); - String path2 = "file2"; - writeTrashFile(path2, "content2"); + try (Git git = new Git(db)) { + String path = "file"; + writeTrashFile(path, "content"); + String path2 = "file2"; + writeTrashFile(path2, "content2"); - git.add().addFilepattern(path).call(); - git.add().addFilepattern(path2).call(); - git.commit().setMessage("commit").call(); + git.add().addFilepattern(path).call(); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("commit").call(); - DirCache dc = db.readDirCache(); - DirCacheEntry entry = dc.getEntry(path); - DirCacheEntry entry2 = dc.getEntry(path); + DirCache dc = db.readDirCache(); + DirCacheEntry entry = dc.getEntry(path); + DirCacheEntry entry2 = dc.getEntry(path); - assertTrue("last modified shall not be zero!", - entry.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry.getLastModified() != 0); - assertTrue("last modified shall not be zero!", - entry2.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry2.getLastModified() != 0); - writeTrashFile(path, "new content"); - git.add().addFilepattern(path).call(); - git.commit().setMessage("commit2").call(); + writeTrashFile(path, "new content"); + git.add().addFilepattern(path).call(); + git.commit().setMessage("commit2").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); - entry2 = dc.getEntry(path); + dc = db.readDirCache(); + entry = dc.getEntry(path); + entry2 = dc.getEntry(path); - assertTrue("last modified shall not be zero!", - entry.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry.getLastModified() != 0); - assertTrue("last modified shall not be zero!", - entry2.getLastModified() != 0); + assertTrue("last modified shall not be zero!", + entry2.getLastModified() != 0); + } } @Test public void testModify() throws Exception { - Git git = new Git(db); - String path = "file"; - writeTrashFile(path, "content"); + try (Git git = new Git(db)) { + String path = "file"; + writeTrashFile(path, "content"); - git.add().addFilepattern(path).call(); - git.commit().setMessage("commit").call(); + git.add().addFilepattern(path).call(); + git.commit().setMessage("commit").call(); - DirCache dc = db.readDirCache(); - DirCacheEntry entry = dc.getEntry(path); + DirCache dc = db.readDirCache(); + DirCacheEntry entry = dc.getEntry(path); - long masterLastMod = entry.getLastModified(); + long masterLastMod = entry.getLastModified(); - git.checkout().setCreateBranch(true).setName("side").call(); + git.checkout().setCreateBranch(true).setName("side").call(); - Thread.sleep(10); - String path2 = "file2"; - writeTrashFile(path2, "side content"); - git.add().addFilepattern(path2).call(); - git.commit().setMessage("commit").call(); + Thread.sleep(10); + String path2 = "file2"; + writeTrashFile(path2, "side content"); + git.add().addFilepattern(path2).call(); + git.commit().setMessage("commit").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); + dc = db.readDirCache(); + entry = dc.getEntry(path); - long sideLastMode = entry.getLastModified(); + long sideLastMode = entry.getLastModified(); - Thread.sleep(2000); + Thread.sleep(2000); - writeTrashFile(path, "uncommitted content"); - git.checkout().setName("master").call(); + writeTrashFile(path, "uncommitted content"); + git.checkout().setName("master").call(); - dc = db.readDirCache(); - entry = dc.getEntry(path); - - assertTrue("shall have equal mod time!", masterLastMod == sideLastMode); - assertTrue("shall not equal master timestamp!", - entry.getLastModified() == masterLastMod); + dc = db.readDirCache(); + entry = dc.getEntry(path); + assertTrue("shall have equal mod time!", masterLastMod == sideLastMode); + assertTrue("shall not equal master timestamp!", + entry.getLastModified() == masterLastMod); + } } } From f04bd20fc658365fcf24086ea26beaf3ff5f1ada Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 14:57:39 +0900 Subject: [PATCH 07/22] InMemoryRepository: Remove unused RevWalk from batch method signature The RevWalk given in the arguments is not used. According to the comment at the top of the method, a new RevWalk is intentionally used in the implementation. Remove the unused argument. Change-Id: Iec81a1341d5bf377801475845b96a465753096ef Signed-off-by: David Pursehouse --- .../eclipse/jgit/internal/storage/dfs/InMemoryRepository.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java index 5e246b47b..b312835bb 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java @@ -274,7 +274,7 @@ public class InMemoryRepository extends DfsRepository { if (performsAtomicTransactions()) { try { lock.writeLock().lock(); - batch(walk, getCommands()); + batch(getCommands()); } finally { lock.writeLock().unlock(); } @@ -304,7 +304,7 @@ public class InMemoryRepository extends DfsRepository { return new RefCache(ids.toRefList(), sym.toRefList()); } - private void batch(RevWalk walk, List cmds) { + private void batch(List cmds) { // Validate that the target exists in a new RevWalk, as the RevWalk // from the RefUpdate might be reading back unflushed objects. Map peeled = new HashMap<>(); From 4d3dc41f2fbc2d9ff33ccfa078e1e63cc1e5c0be Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 16:52:40 +0900 Subject: [PATCH 08/22] ManifestParserTest: Don't use deprecated StringBufferInputStream Replace it with ByteArrayInputStream as suggested in [1]. [1] http://stackoverflow.com/a/2219543/381622 Change-Id: I5ca8d721a756a82ea5f5687a20555303eb1dfc18 Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java index 5ed4268eb..30b3df1c0 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java @@ -43,8 +43,9 @@ package org.eclipse.jgit.gitrepo; import static org.junit.Assert.assertTrue; +import static java.nio.charset.StandardCharsets.UTF_8; -import java.io.StringBufferInputStream; +import java.io.ByteArrayInputStream; import java.util.HashSet; import java.util.Set; @@ -77,7 +78,7 @@ public class ManifestParserTest { ManifestParser parser = new ManifestParser( null, null, "master", baseUrl, null, null); - parser.read(new StringBufferInputStream(xmlContent.toString())); + parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8))); // Unfiltered projects should have them all. results.clear(); results.add("foo"); From f23b0fd7e6cd99ca904182e78055070d3ff0cf60 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:03:25 +0900 Subject: [PATCH 09/22] IndexDiffTest: Open Git instances in try-with-resources Change-Id: I7fa2d16561982ddfde053f2fe78135c114b66b1d Signed-off-by: David Pursehouse --- .../org/eclipse/jgit/lib/IndexDiffTest.java | 674 +++++++++--------- 1 file changed, 340 insertions(+), 334 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java index 18c959607..733f1668b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java @@ -148,8 +148,9 @@ public class IndexDiffTest extends RepositoryTestCase { writeTrashFile("file2", "file2"); writeTrashFile("dir/file3", "dir/file3"); - Git git = new Git(db); - git.add().addFilepattern("file2").addFilepattern("dir/file3").call(); + try (Git git = new Git(db)) { + git.add().addFilepattern("file2").addFilepattern("dir/file3").call(); + } writeTrashFile("dir/file3", "changed"); @@ -177,31 +178,31 @@ public class IndexDiffTest extends RepositoryTestCase { @Test public void testConflicting() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - // create side branch with two modifications - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - writeTrashFile("a", "1\na(side)\n3\n"); - writeTrashFile("b", "1\nb\n3\n(side)"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - // update a on master to generate conflict - checkoutBranch("refs/heads/master"); - writeTrashFile("a", "1\na(main)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); - - // merge side with master - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + // create side branch with two modifications + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + writeTrashFile("a", "1\na(side)\n3\n"); + writeTrashFile("b", "1\nb\n3\n(side)"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + // update a on master to generate conflict + checkoutBranch("refs/heads/master"); + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + // merge side with master + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + } FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); @@ -221,29 +222,29 @@ public class IndexDiffTest extends RepositoryTestCase { @Test public void testConflictingDeletedAndModified() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "1\na\n3\n"); - writeTrashFile("b", "1\nb\n3\n"); - git.add().addFilepattern("a").addFilepattern("b").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); - - // create side branch and delete "a" - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); - git.rm().addFilepattern("a").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); - - // update a on master to generate conflict - checkoutBranch("refs/heads/master"); - writeTrashFile("a", "1\na(main)\n3\n"); - git.add().addFilepattern("a").call(); - git.commit().setMessage("main").call(); - - // merge side with master - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + writeTrashFile("b", "1\nb\n3\n"); + git.add().addFilepattern("a").addFilepattern("b").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); + + // create side branch and delete "a" + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); + git.rm().addFilepattern("a").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); + + // update a on master to generate conflict + checkoutBranch("refs/heads/master"); + writeTrashFile("a", "1\na(main)\n3\n"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("main").call(); + + // merge side with master + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + } FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); @@ -262,28 +263,28 @@ public class IndexDiffTest extends RepositoryTestCase { @Test public void testConflictingFromMultipleCreations() throws Exception { - Git git = new Git(db); + try (Git git = new Git(db)) { + writeTrashFile("a", "1\na\n3\n"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial").call(); - writeTrashFile("a", "1\na\n3\n"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial").call(); + createBranch(initialCommit, "refs/heads/side"); + checkoutBranch("refs/heads/side"); - createBranch(initialCommit, "refs/heads/side"); - checkoutBranch("refs/heads/side"); + writeTrashFile("b", "1\nb(side)\n3\n"); + git.add().addFilepattern("b").call(); + RevCommit secondCommit = git.commit().setMessage("side").call(); - writeTrashFile("b", "1\nb(side)\n3\n"); - git.add().addFilepattern("b").call(); - RevCommit secondCommit = git.commit().setMessage("side").call(); + checkoutBranch("refs/heads/master"); - checkoutBranch("refs/heads/master"); + writeTrashFile("b", "1\nb(main)\n3\n"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("main").call(); - writeTrashFile("b", "1\nb(main)\n3\n"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("main").call(); - - MergeResult result = git.merge().include(secondCommit.getId()) - .setStrategy(MergeStrategy.RESOLVE).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + MergeResult result = git.merge().include(secondCommit.getId()) + .setStrategy(MergeStrategy.RESOLVE).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + } FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); @@ -304,11 +305,12 @@ public class IndexDiffTest extends RepositoryTestCase { writeTrashFile("a.c", "a.c"); writeTrashFile("a=c", "a=c"); writeTrashFile("a=d", "a=d"); - Git git = new Git(db); - git.add().addFilepattern("a.b").call(); - git.add().addFilepattern("a.c").call(); - git.add().addFilepattern("a=c").call(); - git.add().addFilepattern("a=d").call(); + try (Git git = new Git(db)) { + git.add().addFilepattern("a.b").call(); + git.add().addFilepattern("a.c").call(); + git.add().addFilepattern("a=c").call(); + git.add().addFilepattern("a=d").call(); + } TreeFormatter tree = new TreeFormatter(); // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin @@ -338,7 +340,6 @@ public class IndexDiffTest extends RepositoryTestCase { */ @Test public void testUnchangedComplex() throws IOException, GitAPIException { - Git git = new Git(db); writeTrashFile("a.b", "a.b"); writeTrashFile("a.c", "a.c"); writeTrashFile("a/b.b/b", "a/b.b/b"); @@ -346,10 +347,12 @@ public class IndexDiffTest extends RepositoryTestCase { writeTrashFile("a/c", "a/c"); writeTrashFile("a=c", "a=c"); writeTrashFile("a=d", "a=d"); - git.add().addFilepattern("a.b").addFilepattern("a.c") - .addFilepattern("a/b.b/b").addFilepattern("a/b") - .addFilepattern("a/c").addFilepattern("a=c") - .addFilepattern("a=d").call(); + try (Git git = new Git(db)) { + git.add().addFilepattern("a.b").addFilepattern("a.c") + .addFilepattern("a/b.b/b").addFilepattern("a/b") + .addFilepattern("a/c").addFilepattern("a=c") + .addFilepattern("a=d").call(); + } // got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin @@ -397,11 +400,12 @@ public class IndexDiffTest extends RepositoryTestCase { */ @Test public void testRemovedUntracked() throws Exception{ - Git git = new Git(db); String path = "file"; - writeTrashFile(path, "content"); - git.add().addFilepattern(path).call(); - git.commit().setMessage("commit").call(); + try (Git git = new Git(db)) { + writeTrashFile(path, "content"); + git.add().addFilepattern(path).call(); + git.commit().setMessage("commit").call(); + } removeFromIndex(path); FileTreeIterator iterator = new FileTreeIterator(db); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); @@ -417,51 +421,51 @@ public class IndexDiffTest extends RepositoryTestCase { */ @Test public void testUntrackedFolders() throws Exception { - Git git = new Git(db); - - IndexDiff diff = new IndexDiff(db, Constants.HEAD, - new FileTreeIterator(db)); - diff.diff(); - assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); - - writeTrashFile("readme", ""); - writeTrashFile("src/com/A.java", ""); - writeTrashFile("src/com/B.java", ""); - writeTrashFile("src/org/A.java", ""); - writeTrashFile("src/org/B.java", ""); - writeTrashFile("target/com/A.java", ""); - writeTrashFile("target/com/B.java", ""); - writeTrashFile("target/org/A.java", ""); - writeTrashFile("target/org/B.java", ""); - - git.add().addFilepattern("src").addFilepattern("readme").call(); - git.commit().setMessage("initial").call(); - - diff = new IndexDiff(db, Constants.HEAD, - new FileTreeIterator(db)); - diff.diff(); - assertEquals(new HashSet(Arrays.asList("target")), - diff.getUntrackedFolders()); - - writeTrashFile("src/tst/A.java", ""); - writeTrashFile("src/tst/B.java", ""); - - diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); - diff.diff(); - assertEquals(new HashSet(Arrays.asList("target", "src/tst")), - diff.getUntrackedFolders()); - - git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org") - .call(); - git.commit().setMessage("second").call(); - writeTrashFile("src/org/C.java", ""); - - diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); - diff.diff(); - assertEquals( - new HashSet(Arrays.asList("src/org", "src/tst", - "target")), - diff.getUntrackedFolders()); + try (Git git = new Git(db)) { + IndexDiff diff = new IndexDiff(db, Constants.HEAD, + new FileTreeIterator(db)); + diff.diff(); + assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); + + writeTrashFile("readme", ""); + writeTrashFile("src/com/A.java", ""); + writeTrashFile("src/com/B.java", ""); + writeTrashFile("src/org/A.java", ""); + writeTrashFile("src/org/B.java", ""); + writeTrashFile("target/com/A.java", ""); + writeTrashFile("target/com/B.java", ""); + writeTrashFile("target/org/A.java", ""); + writeTrashFile("target/org/B.java", ""); + + git.add().addFilepattern("src").addFilepattern("readme").call(); + git.commit().setMessage("initial").call(); + + diff = new IndexDiff(db, Constants.HEAD, + new FileTreeIterator(db)); + diff.diff(); + assertEquals(new HashSet(Arrays.asList("target")), + diff.getUntrackedFolders()); + + writeTrashFile("src/tst/A.java", ""); + writeTrashFile("src/tst/B.java", ""); + + diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); + diff.diff(); + assertEquals(new HashSet(Arrays.asList("target", "src/tst")), + diff.getUntrackedFolders()); + + git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org") + .call(); + git.commit().setMessage("second").call(); + writeTrashFile("src/org/C.java", ""); + + diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); + diff.diff(); + assertEquals( + new HashSet(Arrays.asList("src/org", "src/tst", + "target")), + diff.getUntrackedFolders()); + } } /** @@ -471,85 +475,86 @@ public class IndexDiffTest extends RepositoryTestCase { */ @Test public void testUntrackedNotIgnoredFolders() throws Exception { - Git git = new Git(db); - - IndexDiff diff = new IndexDiff(db, Constants.HEAD, - new FileTreeIterator(db)); - diff.diff(); - assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); - - writeTrashFile("readme", ""); - writeTrashFile("sr/com/X.java", ""); - writeTrashFile("src/com/A.java", ""); - writeTrashFile("src/org/B.java", ""); - writeTrashFile("srcs/org/Y.java", ""); - writeTrashFile("target/com/A.java", ""); - writeTrashFile("target/org/B.java", ""); - writeTrashFile(".gitignore", "/target\n/sr"); - - git.add().addFilepattern("readme").addFilepattern(".gitignore") - .addFilepattern("srcs/").call(); - git.commit().setMessage("initial").call(); - - diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); - diff.diff(); - assertEquals(new HashSet(Arrays.asList("src")), - diff.getUntrackedFolders()); - - git.add().addFilepattern("src").call(); - writeTrashFile("sr/com/X1.java", ""); - writeTrashFile("src/tst/A.java", ""); - writeTrashFile("src/tst/B.java", ""); - writeTrashFile("srcs/com/Y1.java", ""); - deleteTrashFile(".gitignore"); - - diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); - diff.diff(); - assertEquals( - new HashSet(Arrays.asList("srcs/com", "sr", "src/tst", - "target")), - diff.getUntrackedFolders()); + try (Git git = new Git(db)) { + IndexDiff diff = new IndexDiff(db, Constants.HEAD, + new FileTreeIterator(db)); + diff.diff(); + assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); + + writeTrashFile("readme", ""); + writeTrashFile("sr/com/X.java", ""); + writeTrashFile("src/com/A.java", ""); + writeTrashFile("src/org/B.java", ""); + writeTrashFile("srcs/org/Y.java", ""); + writeTrashFile("target/com/A.java", ""); + writeTrashFile("target/org/B.java", ""); + writeTrashFile(".gitignore", "/target\n/sr"); + + git.add().addFilepattern("readme").addFilepattern(".gitignore") + .addFilepattern("srcs/").call(); + git.commit().setMessage("initial").call(); + + diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); + diff.diff(); + assertEquals(new HashSet(Arrays.asList("src")), + diff.getUntrackedFolders()); + + git.add().addFilepattern("src").call(); + writeTrashFile("sr/com/X1.java", ""); + writeTrashFile("src/tst/A.java", ""); + writeTrashFile("src/tst/B.java", ""); + writeTrashFile("srcs/com/Y1.java", ""); + deleteTrashFile(".gitignore"); + + diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); + diff.diff(); + assertEquals( + new HashSet(Arrays.asList("srcs/com", "sr", "src/tst", + "target")), + diff.getUntrackedFolders()); + } } @Test public void testAssumeUnchanged() throws Exception { - Git git = new Git(db); - String path = "file"; - writeTrashFile(path, "content"); - git.add().addFilepattern(path).call(); - String path2 = "file2"; - writeTrashFile(path2, "content"); - String path3 = "file3"; - writeTrashFile(path3, "some content"); - git.add().addFilepattern(path2).addFilepattern(path3).call(); - git.commit().setMessage("commit").call(); - assumeUnchanged(path2); - assumeUnchanged(path3); - writeTrashFile(path, "more content"); - deleteTrashFile(path3); - - FileTreeIterator iterator = new FileTreeIterator(db); - IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - assertEquals(2, diff.getAssumeUnchanged().size()); - assertEquals(1, diff.getModified().size()); - assertEquals(0, diff.getChanged().size()); - assertTrue(diff.getAssumeUnchanged().contains("file2")); - assertTrue(diff.getAssumeUnchanged().contains("file3")); - assertTrue(diff.getModified().contains("file")); - - git.add().addFilepattern(".").call(); - - iterator = new FileTreeIterator(db); - diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - assertEquals(2, diff.getAssumeUnchanged().size()); - assertEquals(0, diff.getModified().size()); - assertEquals(1, diff.getChanged().size()); - assertTrue(diff.getAssumeUnchanged().contains("file2")); - assertTrue(diff.getAssumeUnchanged().contains("file3")); - assertTrue(diff.getChanged().contains("file")); - assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); + try (Git git = new Git(db)) { + String path = "file"; + writeTrashFile(path, "content"); + git.add().addFilepattern(path).call(); + String path2 = "file2"; + writeTrashFile(path2, "content"); + String path3 = "file3"; + writeTrashFile(path3, "some content"); + git.add().addFilepattern(path2).addFilepattern(path3).call(); + git.commit().setMessage("commit").call(); + assumeUnchanged(path2); + assumeUnchanged(path3); + writeTrashFile(path, "more content"); + deleteTrashFile(path3); + + FileTreeIterator iterator = new FileTreeIterator(db); + IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + assertEquals(2, diff.getAssumeUnchanged().size()); + assertEquals(1, diff.getModified().size()); + assertEquals(0, diff.getChanged().size()); + assertTrue(diff.getAssumeUnchanged().contains("file2")); + assertTrue(diff.getAssumeUnchanged().contains("file3")); + assertTrue(diff.getModified().contains("file")); + + git.add().addFilepattern(".").call(); + + iterator = new FileTreeIterator(db); + diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + assertEquals(2, diff.getAssumeUnchanged().size()); + assertEquals(0, diff.getModified().size()); + assertEquals(1, diff.getChanged().size()); + assertTrue(diff.getAssumeUnchanged().contains("file2")); + assertTrue(diff.getAssumeUnchanged().contains("file3")); + assertTrue(diff.getChanged().contains("file")); + assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); + } } @Test @@ -575,147 +580,148 @@ public class IndexDiffTest extends RepositoryTestCase { @Test public void testStageState_mergeAndReset_bug() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "content"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - - // create branch and add a new file - final String branchName = Constants.R_HEADS + "branch"; - createBranch(initialCommit, branchName); - checkoutBranch(branchName); - writeTrashFile("b", "second file content - branch"); - git.add().addFilepattern("b").call(); - RevCommit branchCommit = git.commit().setMessage("branch commit") - .call(); - - // checkout master and add the same new file - checkoutBranch(Constants.R_HEADS + Constants.MASTER); - writeTrashFile("b", "second file content - master"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("master commit").call(); - - // try and merge - MergeResult result = git.merge().include(branchCommit).call(); - assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); - - FileTreeIterator iterator = new FileTreeIterator(db); - IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - - assertTrue(diff.getChanged().isEmpty()); - assertTrue(diff.getAdded().isEmpty()); - assertTrue(diff.getRemoved().isEmpty()); - assertTrue(diff.getMissing().isEmpty()); - assertTrue(diff.getModified().isEmpty()); - assertEquals(1, diff.getConflicting().size()); - assertTrue(diff.getConflicting().contains("b")); - assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() - .get("b")); - assertTrue(diff.getUntrackedFolders().isEmpty()); - - // reset file b to its master state without altering the index - writeTrashFile("b", "second file content - master"); - - // we should have the same result - iterator = new FileTreeIterator(db); - diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - - assertTrue(diff.getChanged().isEmpty()); - assertTrue(diff.getAdded().isEmpty()); - assertTrue(diff.getRemoved().isEmpty()); - assertTrue(diff.getMissing().isEmpty()); - assertTrue(diff.getModified().isEmpty()); - assertEquals(1, diff.getConflicting().size()); - assertTrue(diff.getConflicting().contains("b")); - assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() - .get("b")); - assertTrue(diff.getUntrackedFolders().isEmpty()); + try (Git git = new Git(db)) { + writeTrashFile("a", "content"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + + // create branch and add a new file + final String branchName = Constants.R_HEADS + "branch"; + createBranch(initialCommit, branchName); + checkoutBranch(branchName); + writeTrashFile("b", "second file content - branch"); + git.add().addFilepattern("b").call(); + RevCommit branchCommit = git.commit().setMessage("branch commit") + .call(); + + // checkout master and add the same new file + checkoutBranch(Constants.R_HEADS + Constants.MASTER); + writeTrashFile("b", "second file content - master"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("master commit").call(); + + // try and merge + MergeResult result = git.merge().include(branchCommit).call(); + assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); + + FileTreeIterator iterator = new FileTreeIterator(db); + IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + + assertTrue(diff.getChanged().isEmpty()); + assertTrue(diff.getAdded().isEmpty()); + assertTrue(diff.getRemoved().isEmpty()); + assertTrue(diff.getMissing().isEmpty()); + assertTrue(diff.getModified().isEmpty()); + assertEquals(1, diff.getConflicting().size()); + assertTrue(diff.getConflicting().contains("b")); + assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() + .get("b")); + assertTrue(diff.getUntrackedFolders().isEmpty()); + + // reset file b to its master state without altering the index + writeTrashFile("b", "second file content - master"); + + // we should have the same result + iterator = new FileTreeIterator(db); + diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + + assertTrue(diff.getChanged().isEmpty()); + assertTrue(diff.getAdded().isEmpty()); + assertTrue(diff.getRemoved().isEmpty()); + assertTrue(diff.getMissing().isEmpty()); + assertTrue(diff.getModified().isEmpty()); + assertEquals(1, diff.getConflicting().size()); + assertTrue(diff.getConflicting().contains("b")); + assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() + .get("b")); + assertTrue(diff.getUntrackedFolders().isEmpty()); + } } @Test public void testStageState_simulated_bug() throws Exception { - Git git = new Git(db); - - writeTrashFile("a", "content"); - git.add().addFilepattern("a").call(); - RevCommit initialCommit = git.commit().setMessage("initial commit") - .call(); - - // create branch and add a new file - final String branchName = Constants.R_HEADS + "branch"; - createBranch(initialCommit, branchName); - checkoutBranch(branchName); - writeTrashFile("b", "second file content - branch"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("branch commit") - .call(); - - // checkout master and add the same new file - checkoutBranch(Constants.R_HEADS + Constants.MASTER); - writeTrashFile("b", "second file content - master"); - git.add().addFilepattern("b").call(); - git.commit().setMessage("master commit").call(); - - // Simulate a failed merge of branch into master - DirCacheBuilder builder = db.lockDirCache().builder(); - DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0, - "content"); - builder.add(entry); - entry = createEntry("b", FileMode.REGULAR_FILE, 2, - "second file content - master"); - builder.add(entry); - entry = createEntry("b", FileMode.REGULAR_FILE, 3, - "second file content - branch"); - builder.add(entry); - builder.commit(); - - FileTreeIterator iterator = new FileTreeIterator(db); - IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - - assertTrue(diff.getChanged().isEmpty()); - assertTrue(diff.getAdded().isEmpty()); - assertTrue(diff.getRemoved().isEmpty()); - assertTrue(diff.getMissing().isEmpty()); - assertTrue(diff.getModified().isEmpty()); - assertEquals(1, diff.getConflicting().size()); - assertTrue(diff.getConflicting().contains("b")); - assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() - .get("b")); - assertTrue(diff.getUntrackedFolders().isEmpty()); + try (Git git = new Git(db)) { + writeTrashFile("a", "content"); + git.add().addFilepattern("a").call(); + RevCommit initialCommit = git.commit().setMessage("initial commit") + .call(); + + // create branch and add a new file + final String branchName = Constants.R_HEADS + "branch"; + createBranch(initialCommit, branchName); + checkoutBranch(branchName); + writeTrashFile("b", "second file content - branch"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("branch commit") + .call(); + + // checkout master and add the same new file + checkoutBranch(Constants.R_HEADS + Constants.MASTER); + writeTrashFile("b", "second file content - master"); + git.add().addFilepattern("b").call(); + git.commit().setMessage("master commit").call(); + + // Simulate a failed merge of branch into master + DirCacheBuilder builder = db.lockDirCache().builder(); + DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0, + "content"); + builder.add(entry); + entry = createEntry("b", FileMode.REGULAR_FILE, 2, + "second file content - master"); + builder.add(entry); + entry = createEntry("b", FileMode.REGULAR_FILE, 3, + "second file content - branch"); + builder.add(entry); + builder.commit(); + + FileTreeIterator iterator = new FileTreeIterator(db); + IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + + assertTrue(diff.getChanged().isEmpty()); + assertTrue(diff.getAdded().isEmpty()); + assertTrue(diff.getRemoved().isEmpty()); + assertTrue(diff.getMissing().isEmpty()); + assertTrue(diff.getModified().isEmpty()); + assertEquals(1, diff.getConflicting().size()); + assertTrue(diff.getConflicting().contains("b")); + assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() + .get("b")); + assertTrue(diff.getUntrackedFolders().isEmpty()); + } } @Test public void testAutoCRLFInput() throws Exception { - Git git = new Git(db); - FileBasedConfig config = db.getConfig(); - - // Make sure core.autocrlf is false before adding - config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, - ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); - config.save(); - - // File is already in repository with CRLF - writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n"); - git.add().addFilepattern("crlf.txt").call(); - git.commit().setMessage("Add crlf.txt").call(); - - // Now set core.autocrlf to input - config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, - ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT); - config.save(); - - FileTreeIterator iterator = new FileTreeIterator(db); - IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); - diff.diff(); - - assertTrue( - "Expected no modified files, but there were: " - + diff.getModified(), diff.getModified().isEmpty()); + try (Git git = new Git(db)) { + FileBasedConfig config = db.getConfig(); + + // Make sure core.autocrlf is false before adding + config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); + config.save(); + + // File is already in repository with CRLF + writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n"); + git.add().addFilepattern("crlf.txt").call(); + git.commit().setMessage("Add crlf.txt").call(); + + // Now set core.autocrlf to input + config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT); + config.save(); + + FileTreeIterator iterator = new FileTreeIterator(db); + IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); + diff.diff(); + + assertTrue( + "Expected no modified files, but there were: " + + diff.getModified(), diff.getModified().isEmpty()); + } } private void verifyStageState(StageState expected, int... stages) From 130cf0d61aba0eff821c001b42bf87e50f590d54 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:07:22 +0900 Subject: [PATCH 10/22] GitConstructionTest: Open Git instance in try-with-resource Change-Id: Iddf658acd1c78161d6028cfcfb7e5c73534ae40b Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/api/GitConstructionTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java index 2220a536f..3bff8f2ff 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java @@ -66,11 +66,12 @@ public class GitConstructionTest extends RepositoryTestCase { @Before public void setUp() throws Exception { super.setUp(); - Git git = new Git(db); - git.commit().setMessage("initial commit").call(); - writeTrashFile("Test.txt", "Hello world"); - git.add().addFilepattern("Test.txt").call(); - git.commit().setMessage("Initial commit").call(); + try (Git git = new Git(db)) { + git.commit().setMessage("initial commit").call(); + writeTrashFile("Test.txt", "Hello world"); + git.add().addFilepattern("Test.txt").call(); + git.commit().setMessage("Initial commit").call(); + } bareRepo = Git.cloneRepository().setBare(true) .setURI(db.getDirectory().toURI().toString()) From 430b777830bad84605afdff48baa9f65bf773014 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:09:09 +0900 Subject: [PATCH 11/22] ForPathTest: Open TreeWalk in try-with-resource Change-Id: Ie4d0eb9c0fe1d8b8f41da161e701137cd7dd178f Signed-off-by: David Pursehouse --- .../eclipse/jgit/treewalk/ForPathTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java index eaee8bb4b..3d9af35a7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java @@ -84,21 +84,22 @@ public class ForPathTest extends RepositoryTestCase { ObjectId tree = tree0.writeTree(oi); // Find the directories that were implicitly created above. - TreeWalk tw = new TreeWalk(or); - tw.addTree(tree); ObjectId a = null; ObjectId aSlashC = null; - while (tw.next()) { - if (tw.getPathString().equals("a")) { - a = tw.getObjectId(0); - tw.enterSubtree(); - while (tw.next()) { - if (tw.getPathString().equals("a/c")) { - aSlashC = tw.getObjectId(0); - break; + try (TreeWalk tw = new TreeWalk(or)) { + tw.addTree(tree); + while (tw.next()) { + if (tw.getPathString().equals("a")) { + a = tw.getObjectId(0); + tw.enterSubtree(); + while (tw.next()) { + if (tw.getPathString().equals("a/c")) { + aSlashC = tw.getObjectId(0); + break; + } } + break; } - break; } } From 30c9ec88d18a50b543c5c5d94c6f5f956d538773 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:12:29 +0900 Subject: [PATCH 12/22] DirCacheIteratorTest: Open TreeWalk instances in try-with-resource Change-Id: If23597acaebf2295b85411bf87bc0292d5dc789e Signed-off-by: David Pursehouse --- .../jgit/dircache/DirCacheIteratorTest.java | 181 +++++++++--------- 1 file changed, 94 insertions(+), 87 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java index af1c8a356..dd242e5a1 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java @@ -76,9 +76,10 @@ public class DirCacheIteratorTest extends RepositoryTestCase { final DirCache dc = DirCache.newInCore(); assertEquals(0, dc.getEntryCount()); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(new DirCacheIterator(dc)); - assertFalse(tw.next()); + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(new DirCacheIterator(dc)); + assertFalse(tw.next()); + } } @Test @@ -125,19 +126,20 @@ public class DirCacheIteratorTest extends RepositoryTestCase { b.finish(); final DirCacheIterator i = new DirCacheIterator(dc); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(i); - int pathIdx = 0; - while (tw.next()) { - assertSame(i, tw.getTree(0, DirCacheIterator.class)); - assertEquals(pathIdx, i.ptr); - assertSame(ents[pathIdx], i.getDirCacheEntry()); - assertEquals(paths[pathIdx], tw.getPathString()); - assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0)); - assertSame(modes[pathIdx], tw.getFileMode(0)); - pathIdx++; + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(i); + int pathIdx = 0; + while (tw.next()) { + assertSame(i, tw.getTree(0, DirCacheIterator.class)); + assertEquals(pathIdx, i.ptr); + assertSame(ents[pathIdx], i.getDirCacheEntry()); + assertEquals(paths[pathIdx], tw.getPathString()); + assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0)); + assertSame(modes[pathIdx], tw.getFileMode(0)); + pathIdx++; + } + assertEquals(paths.length, pathIdx); } - assertEquals(paths.length, pathIdx); } @Test @@ -162,26 +164,27 @@ public class DirCacheIteratorTest extends RepositoryTestCase { final int expPos[] = { 0, -1, 4 }; final DirCacheIterator i = new DirCacheIterator(dc); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(i); - tw.setRecursive(false); - int pathIdx = 0; - while (tw.next()) { - assertSame(i, tw.getTree(0, DirCacheIterator.class)); - assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0)); - assertSame(expModes[pathIdx], tw.getFileMode(0)); - assertEquals(expPaths[pathIdx], tw.getPathString()); - - if (expPos[pathIdx] >= 0) { - assertEquals(expPos[pathIdx], i.ptr); - assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry()); - } else { - assertSame(FileMode.TREE, tw.getFileMode(0)); + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(i); + tw.setRecursive(false); + int pathIdx = 0; + while (tw.next()) { + assertSame(i, tw.getTree(0, DirCacheIterator.class)); + assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0)); + assertSame(expModes[pathIdx], tw.getFileMode(0)); + assertEquals(expPaths[pathIdx], tw.getPathString()); + + if (expPos[pathIdx] >= 0) { + assertEquals(expPos[pathIdx], i.ptr); + assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry()); + } else { + assertSame(FileMode.TREE, tw.getFileMode(0)); + } + + pathIdx++; } - - pathIdx++; + assertEquals(expPaths.length, pathIdx); } - assertEquals(expPaths.length, pathIdx); } @Test @@ -202,21 +205,22 @@ public class DirCacheIteratorTest extends RepositoryTestCase { b.finish(); final DirCacheIterator i = new DirCacheIterator(dc); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(i); - tw.setRecursive(true); - int pathIdx = 0; - while (tw.next()) { - final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); - assertNotNull(c); - assertEquals(pathIdx, c.ptr); - assertSame(ents[pathIdx], c.getDirCacheEntry()); - assertEquals(paths[pathIdx], tw.getPathString()); - assertEquals(mode.getBits(), tw.getRawMode(0)); - assertSame(mode, tw.getFileMode(0)); - pathIdx++; + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(i); + tw.setRecursive(true); + int pathIdx = 0; + while (tw.next()) { + final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); + assertNotNull(c); + assertEquals(pathIdx, c.ptr); + assertSame(ents[pathIdx], c.getDirCacheEntry()); + assertEquals(paths[pathIdx], tw.getPathString()); + assertEquals(mode.getBits(), tw.getRawMode(0)); + assertSame(mode, tw.getFileMode(0)); + pathIdx++; + } + assertEquals(paths.length, pathIdx); } - assertEquals(paths.length, pathIdx); } @Test @@ -236,21 +240,22 @@ public class DirCacheIteratorTest extends RepositoryTestCase { b.add(ents[i]); b.finish(); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(new DirCacheIterator(dc)); - tw.setRecursive(true); - int pathIdx = 0; - while (tw.next()) { - final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); - assertNotNull(c); - assertEquals(pathIdx, c.ptr); - assertSame(ents[pathIdx], c.getDirCacheEntry()); - assertEquals(paths[pathIdx], tw.getPathString()); - assertEquals(mode.getBits(), tw.getRawMode(0)); - assertSame(mode, tw.getFileMode(0)); - pathIdx++; + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(new DirCacheIterator(dc)); + tw.setRecursive(true); + int pathIdx = 0; + while (tw.next()) { + final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); + assertNotNull(c); + assertEquals(pathIdx, c.ptr); + assertSame(ents[pathIdx], c.getDirCacheEntry()); + assertEquals(paths[pathIdx], tw.getPathString()); + assertEquals(mode.getBits(), tw.getRawMode(0)); + assertSame(mode, tw.getFileMode(0)); + pathIdx++; + } + assertEquals(paths.length, pathIdx); } - assertEquals(paths.length, pathIdx); } @Test @@ -397,22 +402,23 @@ public class DirCacheIteratorTest extends RepositoryTestCase { b.add(ents[i]); b.finish(); - final TreeWalk tw = new TreeWalk(db); - for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) { - tw.reset(); - tw.addTree(new DirCacheIterator(dc)); - tw.setFilter(PathFilterGroup.createFromStrings(Collections - .singleton(paths[victimIdx]))); - tw.setRecursive(tw.getFilter().shouldBeRecursive()); - assertTrue(tw.next()); - final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); - assertNotNull(c); - assertEquals(victimIdx, c.ptr); - assertSame(ents[victimIdx], c.getDirCacheEntry()); - assertEquals(paths[victimIdx], tw.getPathString()); - assertEquals(mode.getBits(), tw.getRawMode(0)); - assertSame(mode, tw.getFileMode(0)); - assertFalse(tw.next()); + try (final TreeWalk tw = new TreeWalk(db)) { + for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) { + tw.reset(); + tw.addTree(new DirCacheIterator(dc)); + tw.setFilter(PathFilterGroup.createFromStrings(Collections + .singleton(paths[victimIdx]))); + tw.setRecursive(tw.getFilter().shouldBeRecursive()); + assertTrue(tw.next()); + final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); + assertNotNull(c); + assertEquals(victimIdx, c.ptr); + assertSame(ents[victimIdx], c.getDirCacheEntry()); + assertEquals(paths[victimIdx], tw.getPathString()); + assertEquals(mode.getBits(), tw.getRawMode(0)); + assertSame(mode, tw.getFileMode(0)); + assertFalse(tw.next()); + } } } @@ -424,18 +430,19 @@ public class DirCacheIteratorTest extends RepositoryTestCase { final DirCache dc = DirCache.read(path, FS.DETECTED); assertEquals(2, dc.getEntryCount()); - final TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc)); + try (final TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc)); - assertTrue(tw.next()); - assertEquals("a/a", tw.getPathString()); - assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); + assertTrue(tw.next()); + assertEquals("a/a", tw.getPathString()); + assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); - assertTrue(tw.next()); - assertEquals("q", tw.getPathString()); - assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); + assertTrue(tw.next()); + assertEquals("q", tw.getPathString()); + assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); - assertFalse(tw.next()); + assertFalse(tw.next()); + } } } From 259dca06ec5b3371106f0981c21ae63b95fbcff2 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:14:09 +0900 Subject: [PATCH 13/22] DirCacheCheckoutMaliciousPathTest: Open Git and RevWalk in t-w-r Change-Id: Iacb4e25f0ada74b1a01e448216cb02c7ec18b2d7 Signed-off-by: David Pursehouse --- .../DirCacheCheckoutMaliciousPathTest.java | 121 +++++++++--------- 1 file changed, 61 insertions(+), 60 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java index ca3e0666e..59a4699bc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java @@ -338,68 +338,69 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase { */ private void testMaliciousPath(boolean good, boolean secondCheckout, String... path) throws GitAPIException, IOException { - Git git = new Git(db); - ObjectInserter newObjectInserter; - newObjectInserter = git.getRepository().newObjectInserter(); - ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, - "data".getBytes()); - newObjectInserter = git.getRepository().newObjectInserter(); - FileMode mode = FileMode.REGULAR_FILE; - ObjectId insertId = blobId; - for (int i = path.length - 1; i >= 0; --i) { - TreeFormatter treeFormatter = new TreeFormatter(); - treeFormatter.append("goodpath", mode, insertId); - insertId = newObjectInserter.insert(treeFormatter); - mode = FileMode.TREE; - } - newObjectInserter = git.getRepository().newObjectInserter(); - CommitBuilder commitBuilder = new CommitBuilder(); - commitBuilder.setAuthor(author); - commitBuilder.setCommitter(committer); - commitBuilder.setMessage("foo#1"); - commitBuilder.setTreeId(insertId); - ObjectId firstCommitId = newObjectInserter.insert(commitBuilder); - - newObjectInserter = git.getRepository().newObjectInserter(); - mode = FileMode.REGULAR_FILE; - insertId = blobId; - for (int i = path.length - 1; i >= 0; --i) { - TreeFormatter treeFormatter = new TreeFormatter(); - treeFormatter.append(path[i], mode, insertId); - insertId = newObjectInserter.insert(treeFormatter); - mode = FileMode.TREE; - } + try (Git git = new Git(db); + RevWalk revWalk = new RevWalk(git.getRepository())) { + ObjectInserter newObjectInserter; + newObjectInserter = git.getRepository().newObjectInserter(); + ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, + "data".getBytes()); + newObjectInserter = git.getRepository().newObjectInserter(); + FileMode mode = FileMode.REGULAR_FILE; + ObjectId insertId = blobId; + for (int i = path.length - 1; i >= 0; --i) { + TreeFormatter treeFormatter = new TreeFormatter(); + treeFormatter.append("goodpath", mode, insertId); + insertId = newObjectInserter.insert(treeFormatter); + mode = FileMode.TREE; + } + newObjectInserter = git.getRepository().newObjectInserter(); + CommitBuilder commitBuilder = new CommitBuilder(); + commitBuilder.setAuthor(author); + commitBuilder.setCommitter(committer); + commitBuilder.setMessage("foo#1"); + commitBuilder.setTreeId(insertId); + ObjectId firstCommitId = newObjectInserter.insert(commitBuilder); + + newObjectInserter = git.getRepository().newObjectInserter(); + mode = FileMode.REGULAR_FILE; + insertId = blobId; + for (int i = path.length - 1; i >= 0; --i) { + TreeFormatter treeFormatter = new TreeFormatter(); + treeFormatter.append(path[i], mode, insertId); + insertId = newObjectInserter.insert(treeFormatter); + mode = FileMode.TREE; + } - // Create another commit - commitBuilder = new CommitBuilder(); - commitBuilder.setAuthor(author); - commitBuilder.setCommitter(committer); - commitBuilder.setMessage("foo#2"); - commitBuilder.setTreeId(insertId); - commitBuilder.setParentId(firstCommitId); - ObjectId commitId = newObjectInserter.insert(commitBuilder); - - RevWalk revWalk = new RevWalk(git.getRepository()); - if (!secondCheckout) - git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId)) - .setName("refs/heads/master").setCreateBranch(true).call(); - try { - if (secondCheckout) { - git.checkout().setStartPoint(revWalk.parseCommit(commitId)) - .setName("refs/heads/master").setCreateBranch(true) - .call(); - } else { - git.branchCreate().setName("refs/heads/next") - .setStartPoint(commitId.name()).call(); - git.checkout().setName("refs/heads/next") - .call(); + // Create another commit + commitBuilder = new CommitBuilder(); + commitBuilder.setAuthor(author); + commitBuilder.setCommitter(committer); + commitBuilder.setMessage("foo#2"); + commitBuilder.setTreeId(insertId); + commitBuilder.setParentId(firstCommitId); + ObjectId commitId = newObjectInserter.insert(commitBuilder); + + if (!secondCheckout) + git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId)) + .setName("refs/heads/master").setCreateBranch(true).call(); + try { + if (secondCheckout) { + git.checkout().setStartPoint(revWalk.parseCommit(commitId)) + .setName("refs/heads/master").setCreateBranch(true) + .call(); + } else { + git.branchCreate().setName("refs/heads/next") + .setStartPoint(commitId.name()).call(); + git.checkout().setName("refs/heads/next") + .call(); + } + if (!good) + fail("Checkout of Tree " + Arrays.asList(path) + " should fail"); + } catch (InvalidPathException e) { + if (good) + throw e; + assertTrue(e.getMessage().startsWith("Invalid path")); } - if (!good) - fail("Checkout of Tree " + Arrays.asList(path) + " should fail"); - } catch (InvalidPathException e) { - if (good) - throw e; - assertTrue(e.getMessage().startsWith("Invalid path")); } } From 0973c9fc488f99185e152179ba46d49957fff078 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:16:00 +0900 Subject: [PATCH 14/22] DirCacheCGitCompatabilityTest: Open TreeWalk in try-with-resource Change-Id: I81a8bd2aba7eb0a6efaea5d6f7720aa725052157 Signed-off-by: David Pursehouse --- .../DirCacheCGitCompatabilityTest.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java index 7f58a1cbe..3e780467b 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java @@ -98,17 +98,18 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase { assertEquals(ls.size(), dc.getEntryCount()); { final Iterator rItr = ls.values().iterator(); - final TreeWalk tw = new TreeWalk(db); - tw.setRecursive(true); - tw.addTree(new DirCacheIterator(dc)); - while (rItr.hasNext()) { - final DirCacheIterator dcItr; - - assertTrue(tw.next()); - dcItr = tw.getTree(0, DirCacheIterator.class); - assertNotNull(dcItr); - - assertEqual(rItr.next(), dcItr.getDirCacheEntry()); + try (final TreeWalk tw = new TreeWalk(db)) { + tw.setRecursive(true); + tw.addTree(new DirCacheIterator(dc)); + while (rItr.hasNext()) { + final DirCacheIterator dcItr; + + assertTrue(tw.next()); + dcItr = tw.getTree(0, DirCacheIterator.class); + assertNotNull(dcItr); + + assertEqual(rItr.next(), dcItr.getDirCacheEntry()); + } } } } From fc4ac28aa9749e277ece1f628b64900c10b85d5c Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:17:17 +0900 Subject: [PATCH 15/22] DirCacheBuilderIteratorTest: Open TreeWalk in try-with-resource Change-Id: I94836315918924cba9a2b5be6b9ae417cb2ad215 Signed-off-by: David Pursehouse --- .../dircache/DirCacheBuilderIteratorTest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java index 8561fdf35..2b108870f 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java @@ -78,23 +78,24 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase { final int expIdx = 2; final DirCacheBuilder b = dc.builder(); - final TreeWalk tw = new TreeWalk(db); - tw.addTree(new DirCacheBuildIterator(b)); - tw.setRecursive(true); - tw.setFilter(PathFilterGroup.createFromStrings(Collections - .singleton(paths[expIdx]))); + try (final TreeWalk tw = new TreeWalk(db)) { + tw.addTree(new DirCacheBuildIterator(b)); + tw.setRecursive(true); + tw.setFilter(PathFilterGroup.createFromStrings(Collections + .singleton(paths[expIdx]))); - assertTrue("found " + paths[expIdx], tw.next()); - final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); - assertNotNull(c); - assertEquals(expIdx, c.ptr); - assertSame(ents[expIdx], c.getDirCacheEntry()); - assertEquals(paths[expIdx], tw.getPathString()); - assertEquals(mode.getBits(), tw.getRawMode(0)); - assertSame(mode, tw.getFileMode(0)); - b.add(c.getDirCacheEntry()); + assertTrue("found " + paths[expIdx], tw.next()); + final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); + assertNotNull(c); + assertEquals(expIdx, c.ptr); + assertSame(ents[expIdx], c.getDirCacheEntry()); + assertEquals(paths[expIdx], tw.getPathString()); + assertEquals(mode.getBits(), tw.getRawMode(0)); + assertSame(mode, tw.getFileMode(0)); + b.add(c.getDirCacheEntry()); - assertFalse("no more entries", tw.next()); + assertFalse("no more entries", tw.next()); + } b.finish(); assertEquals(ents.length, dc.getEntryCount()); From c9e61c7b391d153884e9c8eafe3403fb93bfe8d7 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:19:17 +0900 Subject: [PATCH 16/22] DirCacheBasicTest: Open ObjectInserter.Formatter in try-with-resource Change-Id: Ie4b3e5ad9616bc56b6d8d2476d1e6c6319c1a0aa Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java index 0c1baab2b..014406eb9 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java @@ -255,9 +255,11 @@ public class DirCacheBasicTest extends RepositoryTestCase { DirCacheBuilder b = dc.builder(); DirCacheEntry e = new DirCacheEntry(path); e.setFileMode(FileMode.REGULAR_FILE); - e.setObjectId(new ObjectInserter.Formatter().idFor( - Constants.OBJ_BLOB, - Constants.encode(path))); + try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) { + e.setObjectId(formatter.idFor( + Constants.OBJ_BLOB, + Constants.encode(path))); + } b.add(e); b.commit(); db.readDirCache(); From 3a437dd655dd4620070c71774feccf908590784b Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:29:20 +0900 Subject: [PATCH 17/22] DiffAlgorithms: Fix warnings about variable hiding Local variables/parameters named 'db' and 'cmp' were hiding class member variables of the same name. Change-Id: I98b770587aaf73744a93e6a3ee33d131a9fa91e9 Signed-off-by: David Pursehouse --- .../jgit/pgm/debug/DiffAlgorithms.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java index c96f2c1ba..05d094f0d 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java @@ -155,16 +155,16 @@ class DiffAlgorithms extends TextBuiltin { else rb.findGitDir(dir); - Repository db = rb.build(); + Repository repo = rb.build(); try { - run(db); + run(repo); } finally { - db.close(); + repo.close(); } } } - private void run(Repository db) throws Exception { + private void run(Repository repo) throws Exception { List all = init(); long files = 0; @@ -173,14 +173,14 @@ class DiffAlgorithms extends TextBuiltin { int maxN = 0; AbbreviatedObjectId startId; - try (ObjectReader or = db.newObjectReader(); + try (ObjectReader or = repo.newObjectReader(); RevWalk rw = new RevWalk(or)) { final MutableObjectId id = new MutableObjectId(); TreeWalk tw = new TreeWalk(or); tw.setFilter(TreeFilter.ANY_DIFF); tw.setRecursive(true); - ObjectId start = db.resolve(Constants.HEAD); + ObjectId start = repo.resolve(Constants.HEAD); startId = or.abbreviate(start); rw.markStart(rw.parseCommit(start)); for (;;) { @@ -235,14 +235,15 @@ class DiffAlgorithms extends TextBuiltin { Collections.sort(all, new Comparator() { public int compare(Test a, Test b) { - int cmp = Long.signum(a.runningTimeNanos - b.runningTimeNanos); - if (cmp == 0) - cmp = a.algorithm.name.compareTo(b.algorithm.name); - return cmp; + int result = Long.signum(a.runningTimeNanos - b.runningTimeNanos); + if (result == 0) { + result = a.algorithm.name.compareTo(b.algorithm.name); + } + return result; } }); - File directory = db.getDirectory(); + File directory = repo.getDirectory(); if (directory != null) { String name = directory.getName(); File parent = directory.getParentFile(); From f595089be04f8357495c25c7ee336198caa7dcd7 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:36:00 +0900 Subject: [PATCH 18/22] Suppress "unchecked cast" warnings related to UploadPackFactory.DISABLED Change-Id: Id74694e18fec326df2b04eb796b46ccc6484b23f Signed-off-by: David Pursehouse --- .../eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java | 1 + .../org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java | 1 + 2 files changed, 2 insertions(+) diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java index 772865df7..f2879e0fa 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java @@ -79,6 +79,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase { factory = new DefaultReceivePackFactory(); } + @SuppressWarnings("unchecked") @Test public void testDisabledSingleton() throws ServiceNotAuthorizedException { factory = (ReceivePackFactory) ReceivePackFactory.DISABLED; diff --git a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java index c9d43cdaf..3bcb0571b 100644 --- a/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java +++ b/org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java @@ -77,6 +77,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase { factory = new DefaultUploadPackFactory(); } + @SuppressWarnings("unchecked") @Test public void testDisabledSingleton() throws ServiceNotAuthorizedException { factory = (UploadPackFactory) UploadPackFactory.DISABLED; From 8deff4b969653379c9a51d952d8c2cadae394934 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 17:41:05 +0900 Subject: [PATCH 19/22] HugeFileTest: Make Git a class member and open in try-with-resource There's only one test method in this module and it's quite long, so rather than using a try-with-resource and having to indent a huge block of existing code, make the Git a member variable that gets initialised and closed in @Before and @After annotated methods. The methods are named 'before' and 'after' rather than the conventional 'setUp' and 'tearDown' so as not to conflict with the names of the existing methods in LocalDiskRepositoryTestCase. Change-Id: I5a4a9b59f244c450dbcae9fdde7d9e0f0cd24e6f Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/api/HugeFileTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java index 5449d02a0..4208f4d8e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java @@ -51,6 +51,8 @@ import java.util.Collection; import org.eclipse.jgit.api.ResetCommand.ResetType; import org.eclipse.jgit.junit.RepositoryTestCase; +import org.junit.After; +import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase { private long lastt = t; + private Git git; + private void measure(String name) { long c = System.currentTimeMillis(); System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s"); lastt = c; } + @Before + public void before() { + git = new Git(db); + } + + @After + public void after() { + if (git != null) { + git.close(); + } + } + @Ignore("Test takes way too long (~10 minutes) to be part of the standard suite") @Test public void testAddHugeFile() throws Exception { @@ -75,7 +91,6 @@ public class HugeFileTest extends RepositoryTestCase { rf.setLength(4429185024L); rf.close(); measure("Created file"); - Git git = new Git(db); git.add().addFilepattern("a.txt").call(); measure("Added file"); From cf8e0f34d93abdd9b06aeb9570f6fc0bed972d28 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 18:21:49 +0900 Subject: [PATCH 20/22] MockServletConfig: Fix warning about unchecked conversion of Enumeration Change-Id: Ic5ce6d220e3b644032819ce4b2f31c669be1cdb9 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/junit/http/MockServletConfig.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java index 0b4530ded..59765890b 100644 --- a/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java +++ b/org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java @@ -62,7 +62,7 @@ public class MockServletConfig implements ServletConfig { return parameters.get(name); } - public Enumeration getInitParameterNames() { + public Enumeration getInitParameterNames() { final Iterator i = parameters.keySet().iterator(); return new Enumeration() { public boolean hasMoreElements() { From 979fa19110df0906a82e92e32d7d3ccf7eca3712 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 18:22:53 +0900 Subject: [PATCH 21/22] Fix warnings about unchecked conversion of MergeResult Change-Id: I1490b2209fa7b39676849c624adbc262a672f6df Signed-off-by: David Pursehouse --- .../tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java | 2 +- org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java index d4a3d62da..284657c59 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java @@ -259,7 +259,7 @@ public class MergeAlgorithmTest { } private String merge(String commonBase, String ours, String theirs) throws IOException { - MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT, + MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT, T(commonBase), T(ours), T(theirs)); ByteArrayOutputStream bo=new ByteArrayOutputStream(50); fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java index 977f95341..a9a8231ee 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java @@ -102,7 +102,7 @@ public class MergeFormatter { * metadata * @throws IOException */ - public void formatMerge(OutputStream out, MergeResult res, String baseName, + public void formatMerge(OutputStream out, MergeResult res, String baseName, String oursName, String theirsName, String charsetName) throws IOException { List names = new ArrayList(3); names.add(baseName); From e96cb22a43e8e67274e39b3d5fb852a20e9b3a04 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 15 Feb 2016 18:44:24 +0900 Subject: [PATCH 22/22] Don't use deprecated LockFile constructor Change-Id: Ibc3e2f3372e1a65732dd6d3c71cec53fb1aa15e2 Signed-off-by: David Pursehouse --- .../src/org/eclipse/jgit/junit/TestRepository.java | 2 +- .../org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java | 4 ++-- .../jgit/internal/storage/file/GcPackRefsTest.java | 2 +- .../eclipse/jgit/internal/storage/file/LockFileTest.java | 2 +- .../eclipse/jgit/internal/storage/file/RefUpdateTest.java | 8 +++----- .../src/org/eclipse/jgit/dircache/DirCache.java | 6 +----- .../jgit/internal/storage/file/FileRepository.java | 2 +- .../org/eclipse/jgit/internal/storage/file/PackLock.java | 4 +--- .../eclipse/jgit/internal/storage/file/RefDirectory.java | 8 +++----- .../jgit/internal/storage/file/RefDirectoryUpdate.java | 2 +- .../org/eclipse/jgit/storage/file/FileBasedConfig.java | 5 +---- .../src/org/eclipse/jgit/transport/FetchProcess.java | 3 +-- 12 files changed, 17 insertions(+), 31 deletions(-) diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java index 8439c39c8..e259156c3 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java @@ -905,7 +905,7 @@ public class TestRepository { private void writeFile(final File p, final byte[] bin) throws IOException, ObjectWritingException { - final LockFile lck = new LockFile(p, db.getFS()); + final LockFile lck = new LockFile(p); if (!lck.lock()) throw new ObjectWritingException("Can't write " + p); try { diff --git a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java index e2f93f481..8cfcba911 100644 --- a/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java +++ b/org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java @@ -235,7 +235,7 @@ class RebuildCommitGraph extends TextBuiltin { final ObjectId id = db.resolve(Constants.HEAD); if (!ObjectId.isId(head) && id != null) { final LockFile lf; - lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS()); + lf = new LockFile(new File(db.getDirectory(), Constants.HEAD)); if (!lf.lock()) throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD)); lf.write(id); @@ -263,7 +263,7 @@ class RebuildCommitGraph extends TextBuiltin { protected void writeFile(final String name, final byte[] content) throws IOException { final File file = new File(db.getDirectory(), name); - final LockFile lck = new LockFile(file, db.getFS()); + final LockFile lck = new LockFile(file); if (!lck.lock()) throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file)); try { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java index fa40458f3..48ea13b98 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java @@ -118,7 +118,7 @@ public class GcPackRefsTest extends GcTestCase { tr.lightweightTag("t1", a); tr.lightweightTag("t2", a); LockFile refLock = new LockFile(new File(repo.getDirectory(), - "refs/tags/t1"), repo.getFS()); + "refs/tags/t1")); try { refLock.lock(); gc.packRefs(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java index 520721b6a..f1bc7c8f6 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java @@ -71,7 +71,7 @@ public class LockFileTest extends RepositoryTestCase { git.add().addFilepattern("file.txt").call(); assertNotNull(git.commit().setMessage("edit file").call()); - LockFile lf = new LockFile(db.getIndexFile(), db.getFS()); + LockFile lf = new LockFile(db.getIndexFile()); assertTrue(lf.lock()); try { git.checkout().setName(commit1.name()).call(); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java index 48434189e..7adf07421 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java @@ -581,14 +581,13 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { RefUpdate updateRef = db.updateRef("refs/heads/master"); updateRef.setNewObjectId(pid); LockFile lockFile1 = new LockFile(new File(db.getDirectory(), - "refs/heads/master"), db.getFS()); + "refs/heads/master")); try { assertTrue(lockFile1.lock()); // precondition to test Result update = updateRef.update(); assertEquals(Result.LOCK_FAILURE, update); assertEquals(opid, db.resolve("refs/heads/master")); - LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"), - db.getFS()); + LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master")); assertFalse(lockFile2.lock()); // was locked, still is } finally { lockFile1.unlock(); @@ -731,8 +730,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { "logs/" + fromName).exists()); // "someone" has branch X locked - LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock), - db.getFS()); + LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock)); try { assertTrue(lockFile.lock()); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java index ecdfe823a..b9101c028 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java @@ -344,9 +344,6 @@ public class DirCache { /** Our active lock (if we hold it); null if we don't have it locked. */ private LockFile myLock; - /** file system abstraction **/ - private final FS fs; - /** Keep track of whether the index has changed or not */ private FileSnapshot snapshot; @@ -376,7 +373,6 @@ public class DirCache { */ public DirCache(final File indexLocation, final FS fs) { liveFile = indexLocation; - this.fs = fs; clear(); } @@ -611,7 +607,7 @@ public class DirCache { public boolean lock() throws IOException { if (liveFile == null) throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile); - final LockFile tmp = new LockFile(liveFile, fs); + final LockFile tmp = new LockFile(liveFile); if (tmp.lock()) { tmp.setNeedStatInformation(true); myLock = tmp; diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java index 62d2d6969..b02efedea 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java @@ -354,7 +354,7 @@ public class FileRepository extends Repository { ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree() .getAbsolutePath()); LockFile dotGitLockFile = new LockFile(new File(workTree, - Constants.DOT_GIT), getFS()); + Constants.DOT_GIT)); try { if (dotGitLockFile.lock()) { dotGitLockFile.write(Constants.encode(Constants.GITDIR diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java index b671b0341..a433dec54 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java @@ -53,7 +53,6 @@ import org.eclipse.jgit.util.FileUtils; /** Keeps track of a {@link PackFile}'s associated .keep file. */ public class PackLock { private final File keepFile; - private final FS fs; /** * Create a new lock for a pack file. @@ -67,7 +66,6 @@ public class PackLock { final File p = packFile.getParentFile(); final String n = packFile.getName(); keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ - this.fs = fs; } /** @@ -84,7 +82,7 @@ public class PackLock { return false; if (!msg.endsWith("\n")) //$NON-NLS-1$ msg += "\n"; //$NON-NLS-1$ - final LockFile lf = new LockFile(keepFile, fs); + final LockFile lf = new LockFile(keepFile); if (!lf.lock()) return false; lf.write(Constants.encode(msg)); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java index 2c8e5f9d1..b8c2fb4a5 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java @@ -588,8 +588,7 @@ public class RefDirectory extends RefDatabase { // we don't miss an edit made externally. final PackedRefList packed = getPackedRefs(); if (packed.contains(name)) { - LockFile lck = new LockFile(packedRefsFile, - update.getRepository().getFS()); + LockFile lck = new LockFile(packedRefsFile); if (!lck.lock()) throw new LockFailedException(packedRefsFile); try { @@ -639,7 +638,7 @@ public class RefDirectory extends RefDatabase { FS fs = parent.getFS(); // Lock the packed refs file and read the content - LockFile lck = new LockFile(packedRefsFile, fs); + LockFile lck = new LockFile(packedRefsFile); if (!lck.lock()) throw new IOException(MessageFormat.format( JGitText.get().cannotLock, packedRefsFile)); @@ -670,8 +669,7 @@ public class RefDirectory extends RefDatabase { File refFile = fileFor(refName); if (!fs.exists(refFile)) continue; - LockFile rLck = new LockFile(refFile, - parent.getFS()); + LockFile rLck = new LockFile(refFile); if (!rLck.lock()) continue; try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java index 7858ee140..0d16f79ea 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java @@ -79,7 +79,7 @@ class RefDirectoryUpdate extends RefUpdate { if (deref) dst = dst.getLeaf(); String name = dst.getName(); - lock = new LockFile(database.fileFor(name), getRepository().getFS()); + lock = new LockFile(database.fileFor(name)); if (lock.lock()) { dst = database.getRef(name); setOldObjectId(dst != null ? dst.getObjectId() : null); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java index 29c7f9841..702fd7076 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java @@ -74,8 +74,6 @@ import org.eclipse.jgit.util.RawParseUtils; public class FileBasedConfig extends StoredConfig { private final File configFile; - private final FS fs; - private boolean utf8Bom; private volatile FileSnapshot snapshot; @@ -109,7 +107,6 @@ public class FileBasedConfig extends StoredConfig { public FileBasedConfig(Config base, File cfgLocation, FS fs) { super(base); configFile = cfgLocation; - this.fs = fs; this.snapshot = FileSnapshot.DIRTY; this.hash = ObjectId.zeroId(); } @@ -203,7 +200,7 @@ public class FileBasedConfig extends StoredConfig { out = Constants.encode(text); } - final LockFile lf = new LockFile(getFile(), fs); + final LockFile lf = new LockFile(getFile()); if (!lf.lock()) throw new LockFailedException(getFile()); try { diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java index c4b3f8304..8cb36c791 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java @@ -314,8 +314,7 @@ class FetchProcess { File meta = transport.local.getDirectory(); if (meta == null) return; - final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"), //$NON-NLS-1$ - transport.local.getFS()); + final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD")); //$NON-NLS-1$ try { if (lock.lock()) { final Writer w = new OutputStreamWriter(lock.getOutputStream());