From 914dd6f11ec8b98c794cf94eab57309bc0f58ae3 Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Fri, 29 Mar 2024 09:54:20 +0100 Subject: [PATCH] Properly close JGit repository --- .../scm/provider/git/jgit/command/info/JGitInfoCommand.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java index edf562d81..06a93dc0c 100644 --- a/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java +++ b/maven-scm-providers/maven-scm-providers-git/maven-scm-provider-jgit/src/main/java/org/apache/maven/scm/provider/git/jgit/command/info/JGitInfoCommand.java @@ -54,7 +54,9 @@ public class JGitInfoCommand extends AbstractCommand implements GitCommand { protected ScmResult executeCommand( ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException { File basedir = fileSet.getBasedir(); - try (Git git = JGitUtils.openRepo(basedir); ) { + Git git = null; + try { + git = JGitUtils.openRepo(basedir); ObjectId objectId = git.getRepository().resolve(Constants.HEAD); if (objectId == null) { throw new ScmException("Cannot resolve HEAD in git repository at " + basedir); @@ -74,6 +76,8 @@ protected ScmResult executeCommand( return new InfoScmResult(infoItems, new ScmResult("JGit.resolve(HEAD)", "", objectId.toString(), true)); } catch (Exception e) { throw new ScmException("JGit resolve failure!", e); + } finally { + JGitUtils.closeRepo(git); } }