Skip to content

Commit 41cc9f6

Browse files
committed
wrap Git.wrap in try block so the resources are closed properly (should be no functional change)
1 parent 804a185 commit 41cc9f6

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

src/main/java/pl/project13/core/jgit/JGitCommon.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -358,25 +358,25 @@ private void seeAllParents(@Nonnull RevWalk revWalk, RevCommit child, @Nonnull S
358358
}
359359

360360
public static boolean isRepositoryInDirtyState(Repository repo, String pathFilter) throws GitAPIException {
361-
// TODO close?
362-
Git git = Git.wrap(repo);
363-
Status status;
364-
if (pathFilter != null && !pathFilter.isEmpty()) {
365-
// When path filter is present, check dirty state only for that path
366-
status = git.status().addPath(pathFilter).call();
367-
} else {
368-
// Fallback to normal behavior - check entire repository
369-
status = git.status().call();
361+
try (Git git = Git.wrap(repo)) {
362+
Status status;
363+
if (pathFilter != null && !pathFilter.isEmpty()) {
364+
// When path filter is present, check dirty state only for that path
365+
status = git.status().addPath(pathFilter).call();
366+
} else {
367+
// Fallback to normal behavior - check entire repository
368+
status = git.status().call();
369+
}
370+
// Git describe doesn't mind about untracked files when checking if
371+
// repo is dirty. JGit does this, so we cannot use the isClean method
372+
// to get the same behaviour. Instead check dirty state without
373+
// status.getUntracked().isEmpty()
374+
return !(status.getAdded().isEmpty()
375+
&& status.getChanged().isEmpty()
376+
&& status.getRemoved().isEmpty()
377+
&& status.getMissing().isEmpty()
378+
&& status.getModified().isEmpty()
379+
&& status.getConflicting().isEmpty());
370380
}
371-
// Git describe doesn't mind about untracked files when checking if
372-
// repo is dirty. JGit does this, so we cannot use the isClean method
373-
// to get the same behaviour. Instead check dirty state without
374-
// status.getUntracked().isEmpty()
375-
return !(status.getAdded().isEmpty()
376-
&& status.getChanged().isEmpty()
377-
&& status.getRemoved().isEmpty()
378-
&& status.getMissing().isEmpty()
379-
&& status.getModified().isEmpty()
380-
&& status.getConflicting().isEmpty());
381381
}
382382
}

0 commit comments

Comments
 (0)