Error if there is nothing to pull

This commit is contained in:
Jakub Beránek 2025-01-08 17:17:03 +01:00
parent c92957d38a
commit 482ebfbbae
1 changed files with 10 additions and 0 deletions

View File

@ -81,12 +81,22 @@ impl GitSync {
};
let num_roots_before = num_roots()?;
let sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
// Merge the fetched commit.
const MERGE_COMMIT_MESSAGE: &str = "Merge from rustc";
cmd!(sh, "git merge FETCH_HEAD --no-verify --no-ff -m {MERGE_COMMIT_MESSAGE}")
.run()
.context("FAILED to merge new commits, something went wrong")?;
let current_sha = cmd!(sh, "git rev-parse HEAD").output().context("FAILED to get current commit")?.stdout;
if current_sha == sha {
cmd!(sh, "git reset --hard HEAD^")
.run()
.expect("FAILED to clean up after creating the preparation commit");
return Err(anyhow::anyhow!("No merge was performed, nothing to pull. Rolled back the preparation commit."));
}
// Check that the number of roots did not increase.
if num_roots()? != num_roots_before {
bail!("Josh created a new root commit. This is probably not the history you want.");