From 482ebfbbae7d4a4b20b25378c4ba2d13a1734101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ber=C3=A1nek?= Date: Wed, 8 Jan 2025 17:17:03 +0100 Subject: [PATCH] Error if there is nothing to pull --- josh-sync/src/sync.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/josh-sync/src/sync.rs b/josh-sync/src/sync.rs index 1c1757a4..eff80b10 100644 --- a/josh-sync/src/sync.rs +++ b/josh-sync/src/sync.rs @@ -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.");