From: David Pursehouse Date: Tue, 2 Feb 2016 09:22:32 +0000 (+0900) Subject: ApplyCommandTest: Open Git in try-with-resource X-Git-Tag: v4.3.0.201603230630-rc1~36^2~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d4ddb6fc2b2402aa78520bcffce6dc784c5c27bd;p=jgit.git ApplyCommandTest: Open Git in try-with-resource Also, add missing braces around if-block. Change-Id: I9390b2c7d5c4507923b6f06271a070dc868534e5 Signed-off-by: David Pursehouse --- diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java index ad3ff60a00..d842046bb7 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java @@ -69,23 +69,24 @@ public class ApplyCommandTest extends RepositoryTestCase { private ApplyResult init(final String name, final boolean preExists, final boolean postExists) throws Exception { - Git git = new Git(db); - - if (preExists) { - a = new RawText(readFile(name + "_PreImage")); - write(new File(db.getDirectory().getParent(), name), - a.getString(0, a.size(), false)); - - git.add().addFilepattern(name).call(); - git.commit().setMessage("PreImage").call(); + try (Git git = new Git(db)) { + if (preExists) { + a = new RawText(readFile(name + "_PreImage")); + write(new File(db.getDirectory().getParent(), name), + a.getString(0, a.size(), false)); + + git.add().addFilepattern(name).call(); + git.commit().setMessage("PreImage").call(); + } + + if (postExists) { + b = new RawText(readFile(name + "_PostImage")); + } + + return git + .apply() + .setPatch(getTestResource(name + ".patch")).call(); } - - if (postExists) - b = new RawText(readFile(name + "_PostImage")); - - return git - .apply() - .setPatch(getTestResource(name + ".patch")).call(); } @Test