Fix git info within VM for worktrees (#51119)

If a worktree is used, say for 7.x, and packaging tests are run, the
build within the VM will fail due to the parent checkout not being
accessible. This is because the path of the worktree is for the host
systtem, not the VM. This commit makes the git info unknown, just as if
the .git directory did not exist.
This commit is contained in:
Ryan Ernst 2020-01-25 10:49:38 -08:00 committed by Ryan Ernst
parent 3e3673b518
commit 87b926aa22
1 changed files with 3 additions and 0 deletions

View File

@ -260,6 +260,9 @@ public class GlobalBuildInfoPlugin implements Plugin<Project> {
} 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 "unknown";
}
head = workTree.resolve("HEAD");
final Path commonDir = Paths.get(readFirstLine(workTree.resolve("commondir")));
if (commonDir.isAbsolute()) {