Skip to content

Commit 0016aa4

Browse files
authored
Do not try to fail .git folder provider, fail at runtime if it's not available (#14951)
* Fix early resolution of git dir property which may not be available for source bundles. * Fail at runtime if .git is not available. environment doesn't support providers. * Don't return anything from dotgit provider if .git cannot be located. * Add a comment.
1 parent a02f6b7 commit 0016aa4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

build-tools/build-infra/src/main/java/org/apache/lucene/gradle/plugins/gitinfo/GitInfoPlugin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public void apply(Project project) {
5353
project.getRootProject().getLayout().getProjectDirectory();
5454
Path gitLocation = projectDirectory.getAsFile().toPath().resolve(".git");
5555
if (!Files.exists(gitLocation)) {
56-
throw new GradleException(
57-
"Can't locate .git (probably not a git clone?): "
58-
+ gitLocation.toAbsolutePath());
56+
// don't return anything from the provider if we can't locate the .git
57+
// folder. This will result in the property returning false from isPresent.
58+
return null;
5959
}
6060

6161
if (Files.isDirectory(gitLocation)) {

lucene/distribution/build.gradle

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,13 @@ tasks.register("assembleSourceTgz", QuietExec, {
5353
workingDir = project.rootDir
5454

5555
// An explicit GIT_DIR to prevent .git upward scanning if something goes wrong.
56-
environment("GIT_DIR", "${gitInfoExt.getDotGitDir().get().asFile.toString()}")
56+
if (gitInfoExt.getDotGitDir().isPresent()) {
57+
environment("GIT_DIR", gitInfoExt.getDotGitDir().get().asFile.toString())
58+
} else {
59+
doFirst {
60+
throw new GradleException("Can't assemble source tgz without a full git clone.")
61+
}
62+
}
5763

5864
args += [
5965
"archive",

0 commit comments

Comments
 (0)