Apache Solr open-source search software
LUCENE-9077: Allow locally staged files in git status precommit check.
Dawid Weiss1ad6bc9361bb
diff --git a/gradle/validation/git-status.gradle b/gradle/validation/git-status.gradleindex afcca827628..37eaf132dce 100644--- a/gradle/validation/git-status.gradle+++ b/gradle/validation/git-status.gradle@@ -17,35 +17,47 @@ buildscript {}}+def gitStatus(dir) {+ try {+ def repository = new FileRepositoryBuilder()+ .setWorkTree(dir)+ .setMustExist(true)+ .build()++ def status = new Git(repository).status().call()+ return status+ } catch (RepositoryNotFoundException | NoWorkTreeException e) {+ logger.warn("WARNING: Directory is not a valid GIT checkout (won't check dirty files): ${dir}")+ return null+ } catch (NotSupportedException e) {+ throw new GradleException("jgit does not support git repository version at this location: ${dir}", e)+ }+}+configure(rootProject) {- // Verify git working copy does not have any modified files.- task checkWorkingCopyPristine() {+ // Verify git working copy does not have any unstaged modified files.+ task checkWorkingCopyClean() {doFirst {- def gitDir = rootProject.projectDir- try {- def repository = new FileRepositoryBuilder()- .setWorkTree(gitDir)- .setMustExist(true)- .build()-- def status = new Git(repository).status().call()- if (!status.clean) {- def offenders = [- "(added)": status.added,- "(changed)": status.changed,- "(conflicting)": status.conflicting,- "(missing)": status.missing,- "(modified)": status.modified,- "(removed)": status.removed,- "(untracked)": [status.untracked, status.untrackedFolders].flatten()- ].collectMany { fileStatus, files ->- files.collect {file -> " - ${file} ${fileStatus}" }- }.sort()+ def status = gitStatus(rootProject.projectDir)+ if (status == null) {+ // Ignore the check. This isn't a git checkout.+ } else {+ def offenders = [+ // Exclude staged changes. These are fine in precommit.+ // "(added)": status.added,+ // "(changed)": status.changed,+ // "(removed)": status.removed,+ "(conflicting)": status.conflicting,+ "(missing)": status.missing,+ "(modified)": status.modified,+ "(untracked)": [status.untracked, status.untrackedFolders].flatten()+ ].collectMany { fileStatus, files ->+ files.collect {file -> " - ${file} ${fileStatus}" }+ }.sort()+ if (offenders) {throw new GradleException("Working copy is not a clean git checkout, offending files:\n${offenders.join("\n")}")}- } catch (RepositoryNotFoundException | NoWorkTreeException | NotSupportedException e) {- logger.warn("WARNING: Directory is not a valid GIT checkout (won't check dirty files): ${gitDir}")}}}diff --git a/gradle/validation/precommit.gradle b/gradle/validation/precommit.gradleindex f68b9c6597f..21d25b9fdd7 100644--- a/gradle/validation/precommit.gradle+++ b/gradle/validation/precommit.gradle@@ -8,7 +8,7 @@ configure(rootProject) {// Root-level validation tasks.dependsOn ":verifyLocks"dependsOn ":versionsPropsAreSorted"- dependsOn ":checkWorkingCopyPristine"+ dependsOn ":checkWorkingCopyClean"dependsOn ":validateSourcePatterns"// Solr validation tasks.