Skip to content

Commit

Permalink
Auto merge of #13581 - LuuuXXX:issue-12692, r=weihanglo
Browse files Browse the repository at this point in the history
fix(ci): bump check error when PR is behind master

### What does this PR try to resolve?

Fixes: #12692
  • Loading branch information
bors committed Mar 14, 2024
2 parents 7065f0e + fb616a0 commit 601670a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions crates/xtask-bump-check/src/xtask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,8 @@ fn changed<'r, 'ws>(
(relative_pkg_root, pkg)
})
.collect::<Vec<_>>();
let base_tree = base_commit.as_object().peel_to_tree()?;
let head_tree = head.as_object().peel_to_tree()?;
let diff = repo.diff_tree_to_tree(Some(&base_tree), Some(&head_tree), Default::default())?;

let diff = symmetric_diff(repo, base_commit, head)?;
let mut changed_members = HashMap::new();

for delta in diff.deltas() {
Expand All @@ -354,6 +352,22 @@ fn changed<'r, 'ws>(
Ok(changed_members)
}

/// Using a "symmetric difference" between base and head.
fn symmetric_diff<'a>(
repo: &'a git2::Repository,
base: &'a git2::Commit<'a>,
head: &'a git2::Commit<'a>,
) -> CargoResult<git2::Diff<'a>> {
let ancestor_oid = repo.merge_base(base.id(), head.id())?;
let ancestor_commit = repo.find_commit(ancestor_oid)?;
let ancestor_tree = ancestor_commit.as_object().peel_to_tree()?;
let head_tree = head.as_object().peel_to_tree()?;
let diff =
repo.diff_tree_to_tree(Some(&ancestor_tree), Some(&head_tree), Default::default())?;
tracing::info!(merge_base = %ancestor_commit.id(), base = %base.id(), head = %head.id(), "git diff base...head");
Ok(diff)
}

/// Compares version against published crates on crates.io.
///
/// Assumption: We always release a version larger than all existing versions.
Expand Down

0 comments on commit 601670a

Please sign in to comment.