This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/main by this push:
new d7e33b1041d Build: Run checkWorkingCopyClean as a Test-task finalizer
(#4417)
d7e33b1041d is described below
commit d7e33b1041df1eef2c672162e81bab2355351c15
Author: David Smiley <[email protected]>
AuthorDate: Wed May 20 13:31:08 2026 -0400
Build: Run checkWorkingCopyClean as a Test-task finalizer (#4417)
Use checkWorkingCopyClean as a test taming mechanism which will fail the
build if a test writes changes that it should not. Presently the Java
SecurityManager enforces this comprehensively but that's going away.
---
gradle/validation/git-status.gradle | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/gradle/validation/git-status.gradle
b/gradle/validation/git-status.gradle
index 36c1b4e5f60..8893ff7b552 100644
--- a/gradle/validation/git-status.gradle
+++ b/gradle/validation/git-status.gradle
@@ -49,11 +49,9 @@ configure(rootProject) {
def ref = repository.findRef("HEAD").getObjectId()
project.ext.gitRev = ref.name()
project.ext.gitRevShort = ref.abbreviate(8).name()
- project.ext.gitStatus = new Git(repository).status().call()
} catch (RepositoryNotFoundException | NoWorkTreeException e) {
project.ext.gitRev = "(not a git checkout)"
project.ext.gitRevShort = "(not a git checkout)"
- project.ext.gitStatus = null
} catch (NotSupportedException e) {
throw new GradleException("jgit does not support git repository
version at this location: ${dir}",
e)
@@ -62,10 +60,19 @@ configure(rootProject) {
}
// Verify git working copy does not have any unstaged modified files.
+ // Status is captured here (not in gitStatus) so it reflects changes from
tests that finalize with this task.
task checkWorkingCopyClean() {
- dependsOn gitStatus
doFirst {
- def status = rootProject.ext.gitStatus
+ def status
+ try {
+ def repository = new FileRepositoryBuilder()
+ .setWorkTree(rootProject.projectDir)
+ .setMustExist(true)
+ .build()
+ status = new Git(repository).status().call()
+ } catch (RepositoryNotFoundException | NoWorkTreeException e) {
+ status = null
+ }
if (status == null) {
if (file("${rootProject.projectDir}/.git").exists()) {
// Ignore git worktree branches until jgit supports them.
@@ -121,4 +128,16 @@ configure(rootProject) {
}
}
}
+
+ // Catch tests that write into the working tree.
+ // On CI: finalize every Test task with the clean check (runs even on test
failure).
+ // Locally: only enforce ordering when both are already scheduled (e.g. via
`check`).
+ allprojects {
+ tasks.withType(Test).configureEach { testTask ->
+ rootProject.checkWorkingCopyClean.mustRunAfter(testTask)
+ if (isCIBuild) {
+ testTask.finalizedBy(rootProject.checkWorkingCopyClean)
+ }
+ }
+ }
}