PullRequestImportJob: Open Git in try-with-resource
Change-Id: Icb7c335ba4153735137df30e4c7fa07cb5a64239
diff --git a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
index aed77e8..a07adf3 100644
--- a/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
+++ b/github-plugin/src/main/java/com/googlesource/gerrit/plugins/github/git/PullRequestImportJob.java
@@ -225,14 +225,15 @@
throws GitAPIException, InvalidRemoteException, TransportException {
status.update(Code.SYNC, "Fetching", "Fetching PullRequests from GitHub");
- Git git = Git.wrap(gitRepo);
- FetchCommand fetch = git.fetch();
- fetch.setRemote(ghRepository.getCloneUrl());
- fetch.setRefSpecs(new RefSpec("+refs/pull/" + pr.getNumber()
- + "/head:refs/remotes/origin/pr/" + pr.getNumber()));
- fetch.setProgressMonitor(this);
- fetch.setCredentialsProvider(ghRepository.getCredentialsProvider());
- fetch.call();
+ try (Git git = Git.wrap(gitRepo)) {
+ FetchCommand fetch = git.fetch();
+ fetch.setRemote(ghRepository.getCloneUrl());
+ fetch.setRefSpecs(new RefSpec("+refs/pull/" + pr.getNumber()
+ + "/head:refs/remotes/origin/pr/" + pr.getNumber()));
+ fetch.setProgressMonitor(this);
+ fetch.setCredentialsProvider(ghRepository.getCredentialsProvider());
+ fetch.call();
+ }
}
private GHPullRequest fetchGitHubPullRequestInfo() throws IOException {