From d4ddb6fc2b2402aa78520bcffce6dc784c5c27bd Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Tue, 2 Feb 2016 18:22:32 +0900 Subject: [PATCH] ApplyCommandTest: Open Git in try-with-resource Also, add missing braces around if-block. Change-Id: I9390b2c7d5c4507923b6f06271a070dc868534e5 Signed-off-by: David Pursehouse --- .../eclipse/jgit/api/ApplyCommandTest.java | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) 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 -- 2.39.5