Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ci): bump check error when PR is behind master #13581

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
LuuuXXX marked this conversation as resolved.
Show resolved Hide resolved
}

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