Skip to content

Commit 221c2c7

Browse files
committed
Use try with resources to close repository after use
1 parent c6884b1 commit 221c2c7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/test/java/hudson/plugins/git/AbstractGitProject.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
import jenkins.MasterToSlaveFileCallable;
5252
import org.eclipse.jgit.lib.ObjectId;
53+
import org.eclipse.jgit.lib.Repository;
5354

5455
import org.jenkinsci.plugins.gitclient.Git;
5556
import org.jenkinsci.plugins.gitclient.JGitTool;
@@ -239,9 +240,8 @@ protected MatrixBuild build(final MatrixProject project, final Result expectedRe
239240
protected String getHeadRevision(AbstractBuild build, final String branch) throws IOException, InterruptedException {
240241
return build.getWorkspace().act(new MasterToSlaveFileCallable<String>() {
241242
public String invoke(File f, VirtualChannel channel) throws IOException, InterruptedException {
242-
try {
243-
ObjectId oid = Git.with(null, null).in(f).getClient().getRepository().resolve("refs/heads/" + branch);
244-
return oid.name();
243+
try (Repository repo = Git.with(null, null).in(f).getClient().getRepository()) {
244+
return repo.resolve("refs/heads/" + branch).name();
245245
} catch (GitException e) {
246246
throw new RuntimeException(e);
247247
}

0 commit comments

Comments
 (0)