mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 17:34:17 -04:00
Add support for Git submodules to GitInfo (#89741)
This commit is contained in:
parent
284dce6a2a
commit
12b841e048
1 changed files with 18 additions and 11 deletions
|
@ -75,18 +75,25 @@ public class GitInfo {
|
||||||
head = dotGit.resolve("HEAD");
|
head = dotGit.resolve("HEAD");
|
||||||
gitDir = dotGit;
|
gitDir = dotGit;
|
||||||
} else {
|
} else {
|
||||||
// this is a git worktree, follow the pointer to the repository
|
// this is a git worktree or submodule, follow the pointer to the repository
|
||||||
final Path workTree = Paths.get(readFirstLine(dotGit).substring("gitdir:".length()).trim());
|
final Path reference = Paths.get(readFirstLine(dotGit).substring("gitdir:".length()).trim());
|
||||||
if (Files.exists(workTree) == false) {
|
if (reference.getParent().endsWith("modules")) {
|
||||||
return new GitInfo("unknown", "unknown");
|
// this is a git submodule so follow the reference to the git repo
|
||||||
}
|
gitDir = rootDir.toPath().resolve(reference);
|
||||||
head = workTree.resolve("HEAD");
|
head = gitDir.resolve("HEAD");
|
||||||
final Path commonDir = Paths.get(readFirstLine(workTree.resolve("commondir")));
|
|
||||||
if (commonDir.isAbsolute()) {
|
|
||||||
gitDir = commonDir;
|
|
||||||
} else {
|
} else {
|
||||||
// this is the common case
|
// this is a worktree so resolve the root repo directory
|
||||||
gitDir = workTree.resolve(commonDir);
|
if (Files.exists(reference) == false) {
|
||||||
|
return new GitInfo("unknown", "unknown");
|
||||||
|
}
|
||||||
|
head = reference.resolve("HEAD");
|
||||||
|
final Path commonDir = Paths.get(readFirstLine(reference.resolve("commondir")));
|
||||||
|
if (commonDir.isAbsolute()) {
|
||||||
|
gitDir = commonDir;
|
||||||
|
} else {
|
||||||
|
// this is the common case
|
||||||
|
gitDir = reference.resolve(commonDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String ref = readFirstLine(head);
|
final String ref = readFirstLine(head);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue