You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ds...@apache.org on 2026/05/28 03:32:21 UTC
(solr) 02/03: Build: Run checkWorkingCopyClean as a Test-task finalizer (#4417)
This is an automated email from the ASF dual-hosted git repository.
dsmiley pushed a commit to branch branch_10x
in repository https://gitbox.apache.org/repos/asf/solr.git
commit e235e99c63b620b93aeb310c39594a665dcdd8a9
Author: David Smiley <ds...@apache.org>
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.
(cherry picked from commit d7e33b1041df1eef2c672162e81bab2355351c15)
---
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)
+ }
+ }
+ }
}