Skip to content

Commit

Permalink
Properly close JGit repository
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin authored and michael-o committed Apr 7, 2024
1 parent f7a4b57 commit 4343fb9
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 4343fb9

Please sign in to comment.