mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-06-28 01:22:26 -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");
|
||||
gitDir = dotGit;
|
||||
} else {
|
||||
// this is a git worktree, follow the pointer to the repository
|
||||
final Path workTree = Paths.get(readFirstLine(dotGit).substring("gitdir:".length()).trim());
|
||||
if (Files.exists(workTree) == false) {
|
||||
return new GitInfo("unknown", "unknown");
|
||||
}
|
||||
head = workTree.resolve("HEAD");
|
||||
final Path commonDir = Paths.get(readFirstLine(workTree.resolve("commondir")));
|
||||
if (commonDir.isAbsolute()) {
|
||||
gitDir = commonDir;
|
||||
// this is a git worktree or submodule, follow the pointer to the repository
|
||||
final Path reference = Paths.get(readFirstLine(dotGit).substring("gitdir:".length()).trim());
|
||||
if (reference.getParent().endsWith("modules")) {
|
||||
// this is a git submodule so follow the reference to the git repo
|
||||
gitDir = rootDir.toPath().resolve(reference);
|
||||
head = gitDir.resolve("HEAD");
|
||||
} else {
|
||||
// this is the common case
|
||||
gitDir = workTree.resolve(commonDir);
|
||||
// this is a worktree so resolve the root repo directory
|
||||
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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue