Skip to content

Commit

Permalink
Properly close JGit repository
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin committed Mar 29, 2024
1 parent 8ad0ba8 commit 914dd6f
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 914dd6f

Please sign in to comment.