]> source.dussan.org Git - jgit.git/commitdiff
ApplyCommandTest: Open Git in try-with-resource 34/65634/1
authorDavid Pursehouse <david.pursehouse@sonymobile.com>
Tue, 2 Feb 2016 09:22:32 +0000 (18:22 +0900)
committerDavid Pursehouse <david.pursehouse@sonymobile.com>
Tue, 2 Feb 2016 09:22:32 +0000 (18:22 +0900)
Also, add missing braces around if-block.

Change-Id: I9390b2c7d5c4507923b6f06271a070dc868534e5
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ApplyCommandTest.java

index ad3ff60a00b44599bb258b9b29a76451b3b66165..d842046bb762b921fb6550e0c7c74754c9708669 100644 (file)
@@ -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