Skip to content

Handle empty diff more precisely #10

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

Merged
merged 1 commit into from
Jul 9, 2025
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
16 changes: 14 additions & 2 deletions src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ This updates the rust-version file to {upstream_sha}."#,
};
let num_roots_before = num_roots()?;

let sha = get_current_head_sha()?;
let sha_pre_merge = get_current_head_sha()?;

// The filtered SHA of upstream
let incoming_ref = run_command(["git", "rev-parse", "FETCH_HEAD"])?;
Expand Down Expand Up @@ -169,14 +169,26 @@ This merge was created using https://github.com/rust-lang/josh-sync.
])
.context("FAILED to merge new commits, something went wrong")?;

// Now detect if something has actually been pulled
let current_sha = get_current_head_sha()?;
if current_sha == sha {

// This is the easy case, no merge was performed, so we bail
if current_sha == sha_pre_merge {
eprintln!(
"No merge was performed, no changes to pull were found. Rolling back the preparation commit."
);
return Err(RustcPullError::NothingToPull);
}

// But it can be more tricky - we can have only empty merge/rollup merge commits from
// rustc, so a merge was created, but the in-tree diff can still be empty.
// In that case we also bail.
// `git diff --exit-code` "succeeds" if the diff is empty.
if run_command(&["git", "diff", "--exit-code", &sha_pre_merge]).is_ok() {
eprintln!("Only empty changes were pulled. Rolling back the preparation commit.");
return Err(RustcPullError::NothingToPull);
}

git_reset.disarm();

// Check that the number of roots did not change.
Expand Down
Loading