Skip to content

Commit d1d52c6

Browse files
committed
Ensure we use the absolute path of the git repo, fix exception if module basedir is git repo root.
1 parent 0c754f9 commit d1d52c6

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/pl/project13/core/JGitProvider.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,16 @@ public void prepareGitToExtractMoreDetailedRepoInformation() throws GitCommitIdE
102102
private RevCommit getCommitFromModuleDirectory(File moduleBaseDir) throws GitAPIException, GitCommitIdExecutionException {
103103
//retrieve last commit in folder moduleBaseDir
104104
try (Git gitInstance = new Git(git)) {
105-
String relativePath = git.getDirectory().getParentFile().toPath().relativize(moduleBaseDir.getAbsoluteFile().toPath()).toString();
106-
Iterator<RevCommit> iterator = gitInstance.log()
107-
.addPath(relativePath).call().iterator();
105+
String relativePath = git.getDirectory().getParentFile().getAbsoluteFile().toPath().relativize(moduleBaseDir.getAbsoluteFile().toPath()).toString();
106+
Iterator<RevCommit> iterator;
107+
if (relativePath.trim().isEmpty()) {
108+
// if the relative path is empty, we are in the root of the repository
109+
iterator = gitInstance.log().call().iterator();
110+
} else {
111+
// otherwise, we need to specify the path to get commits for that specific directory
112+
iterator = gitInstance.log()
113+
.addPath(relativePath).call().iterator();
114+
}
108115
if (!iterator.hasNext()) {
109116
throw new GitCommitIdExecutionException(
110117
"Could not get commit from folder " + relativePath + " , are you sure you have some " +

0 commit comments

Comments
 (0)