diff --git a/crates/xtask-bump-check/src/xtask.rs b/crates/xtask-bump-check/src/xtask.rs index 2ae97b2f7df..0e05b120ad0 100644 --- a/crates/xtask-bump-check/src/xtask.rs +++ b/crates/xtask-bump-check/src/xtask.rs @@ -333,10 +333,8 @@ fn changed<'r, 'ws>( (relative_pkg_root, pkg) }) .collect::>(); - 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() { @@ -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> { + 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.