mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-09 23:38:10 -05:00
fix(bench-compare): validate remote git references (#19569)
This commit is contained in:
@@ -181,45 +181,43 @@ impl GitManager {
|
||||
/// Validate that the specified git references exist (branches, tags, or commits)
|
||||
pub(crate) fn validate_refs(&self, refs: &[&str]) -> Result<()> {
|
||||
for &git_ref in refs {
|
||||
// Try branch first, then tag, then commit
|
||||
let branch_check = Command::new("git")
|
||||
.args(["rev-parse", "--verify", &format!("refs/heads/{git_ref}")])
|
||||
// Try to resolve the ref similar to `git checkout` by peeling to a commit.
|
||||
// First try the ref as-is with ^{commit}, then fall back to origin/{ref}^{commit}.
|
||||
let as_is = format!("{git_ref}^{{commit}}");
|
||||
let ref_check = Command::new("git")
|
||||
.args(["rev-parse", "--verify", &as_is])
|
||||
.current_dir(&self.repo_root)
|
||||
.output();
|
||||
|
||||
let tag_check = Command::new("git")
|
||||
.args(["rev-parse", "--verify", &format!("refs/tags/{git_ref}")])
|
||||
.current_dir(&self.repo_root)
|
||||
.output();
|
||||
|
||||
let commit_check = Command::new("git")
|
||||
.args(["rev-parse", "--verify", &format!("{git_ref}^{{commit}}")])
|
||||
.current_dir(&self.repo_root)
|
||||
.output();
|
||||
|
||||
let found = if let Ok(output) = branch_check &&
|
||||
let found = if let Ok(output) = ref_check &&
|
||||
output.status.success()
|
||||
{
|
||||
info!("Validated branch exists: {}", git_ref);
|
||||
true
|
||||
} else if let Ok(output) = tag_check &&
|
||||
output.status.success()
|
||||
{
|
||||
info!("Validated tag exists: {}", git_ref);
|
||||
true
|
||||
} else if let Ok(output) = commit_check &&
|
||||
output.status.success()
|
||||
{
|
||||
info!("Validated commit exists: {}", git_ref);
|
||||
info!("Validated reference exists: {}", git_ref);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
// Try remote-only branches via origin/{ref}
|
||||
let origin_ref = format!("origin/{git_ref}^{{commit}}");
|
||||
let origin_check = Command::new("git")
|
||||
.args(["rev-parse", "--verify", &origin_ref])
|
||||
.current_dir(&self.repo_root)
|
||||
.output();
|
||||
|
||||
if let Ok(output) = origin_check &&
|
||||
output.status.success()
|
||||
{
|
||||
info!("Validated remote reference exists: origin/{}", git_ref);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
};
|
||||
|
||||
if !found {
|
||||
return Err(eyre!(
|
||||
"Git reference '{}' does not exist as branch, tag, or commit",
|
||||
git_ref
|
||||
"Git reference '{}' does not exist as branch, tag, or commit (tried '{}' and 'origin/{}^{{commit}}')",
|
||||
git_ref,
|
||||
format!("{git_ref}^{{commit}}"),
|
||||
git_ref,
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user