Skip to content

Commit ce7a314

Browse files
author
Karol Lassak
committed
Added auto discovery of .git links for submodules
- The same methos witch is done for ste directories - Added extra directory retrieval for nested directories
1 parent 8fbb1b3 commit ce7a314

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/main/java/pl/project13/maven/git/GitDirLocator.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,28 @@ private File findProjectGitDirectory() {
8484

8585
if (isExistingDirectory(dir)) {
8686
return dir;
87+
}
88+
// If the path exists but is not a directory it might be a git submodule "gitdir" link.
89+
File gitDirLinkPath = processGitDirFile(dir);
90+
91+
// If the linkPath was found from the file and it exists then use it.
92+
if (isExistingDirectory(gitDirLinkPath)) {
93+
return gitDirLinkPath;
94+
}
95+
96+
/**
97+
* project.getParent always returns NULL for me, but if getParentArtifact returns
98+
* not null then there is actually a parent - seems like a bug in maven to me.
99+
*/
100+
if (currentProject.getParent() == null && currentProject.getParentArtifact() != null) {
101+
Optional<MavenProject> maybeFoundParentProject = getReactorParentProject(currentProject);
102+
103+
if (maybeFoundParentProject.isPresent())
104+
currentProject = maybeFoundParentProject.get();
105+
87106
} else {
88-
/**
89-
* project.getParent always returns NULL for me, but if getParentArtifact returns
90-
* not null then there is actually a parent - seems like a bug in maven to me.
91-
*/
92-
if (currentProject.getParent() == null && currentProject.getParentArtifact() != null) {
93-
Optional<MavenProject> maybeFoundParentProject = getReactorParentProject(currentProject);
94-
95-
if (maybeFoundParentProject.isPresent())
96-
currentProject = maybeFoundParentProject.get();
97-
98-
} else {
99-
// Get the parent, or NULL if no parent AND no parentArtifact.
100-
currentProject = currentProject.getParent();
101-
}
107+
// Get the parent, or NULL if no parent AND no parentArtifact.
108+
currentProject = currentProject.getParent();
102109
}
103110
}
104111

@@ -151,7 +158,7 @@ private File processGitDirFile(@NotNull File file) {
151158
}
152159

153160
// All seems ok so return the "gitdir" value read from the file.
154-
return new File(parts[1]);
161+
return new File(file.getParentFile(), parts[1]);
155162
} catch (FileNotFoundException e) {
156163
return null;
157164
} finally {

0 commit comments

Comments
 (0)