Fetch refs in compliance tools (#53412)

Conrad Irwin created

v0.232.x

Release Notes:

- N/A

Change summary

tooling/compliance/src/git.rs         | 26 ++++++++++++++++++++++++++
tooling/xtask/src/tasks/compliance.rs |  8 ++++++--
2 files changed, 32 insertions(+), 2 deletions(-)

Detailed changes

tooling/compliance/src/git.rs 🔗

@@ -343,6 +343,32 @@ impl FromStr for NoOutput {
     }
 }
 
+pub struct FetchRefs {
+    branch: String,
+}
+
+impl FetchRefs {
+    pub fn new(branch: String) -> Self {
+        Self { branch }
+    }
+}
+
+impl Subcommand for FetchRefs {
+    type ParsedOutput = NoOutput;
+
+    fn args(&self) -> impl IntoIterator<Item = String> {
+        [
+            "fetch".to_string(),
+            "origin".to_string(),
+            "refs/tags/*:refs/tags/*".to_string(),
+            format!(
+                "refs/heads/{}:refs/remotes/origin/{}",
+                self.branch, self.branch
+            ),
+        ]
+    }
+}
+
 #[cfg(test)]
 mod tests {
     use super::*;

tooling/xtask/src/tasks/compliance.rs 🔗

@@ -5,7 +5,7 @@ use clap::Parser;
 
 use compliance::{
     checks::Reporter,
-    git::{CommitsFromVersionToHead, GetVersionTags, GitCommand, VersionTag},
+    git::{CommitsFromVersionToHead, FetchRefs, GetVersionTags, GitCommand, VersionTag},
     github::GitHubClient,
     report::ReportReviewSummary,
 };
@@ -44,6 +44,10 @@ async fn check_compliance_impl(args: ComplianceArgs) -> Result<()> {
     let key = std::env::var("GITHUB_APP_KEY").context("Missing GITHUB_APP_KEY")?;
 
     let tag = args.version_tag();
+    let version_branch = args.version_branch();
+
+    println!("Fetching tags and branch {version_branch}...");
+    GitCommand::run(FetchRefs::new(version_branch.clone()))?;
 
     let previous_version = GitCommand::run(GetVersionTags)?
         .sorted()
@@ -64,7 +68,7 @@ async fn check_compliance_impl(args: ComplianceArgs) -> Result<()> {
 
     let commits = GitCommand::run(CommitsFromVersionToHead::new(
         previous_version,
-        args.version_branch(),
+        version_branch,
     ))?;
 
     let Some(range) = commits.range() else {