diff --git a/radicle-cli/examples/rad-patch-via-push.md b/radicle-cli/examples/rad-patch-via-push.md index de81e068..892ba734 100644 --- a/radicle-cli/examples/rad-patch-via-push.md +++ b/radicle-cli/examples/rad-patch-via-push.md @@ -222,3 +222,15 @@ $ rad patch show b8ab1c9 │ ↑ updated to f24334f8cea7b7a5bcaf3bc6deb1408c9bf507ad (9304dbc) [ ... ] │ ╰──────────────────────────────────────────────────────────────────────────────╯ ``` + +## Empty patch + +If we try to open a patch without making any changes to our base branch (`master`), +we should get an error: + +``` (stderr) (fail) +$ git push rad master:refs/patches +To rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi + ! [remote rejected] master -> refs/patches (patch commits are already included in the base branch) +error: failed to push some refs to 'rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi' +``` diff --git a/radicle-remote-helper/src/push.rs b/radicle-remote-helper/src/push.rs index 0206c111..c1d68ff3 100644 --- a/radicle-remote-helper/src/push.rs +++ b/radicle-remote-helper/src/push.rs @@ -71,6 +71,9 @@ pub enum Error { /// Patch not found in store. #[error("patch `{0}` not found")] NotFound(patch::PatchId), + /// Patch is empty. + #[error("patch commits are already included in the base branch")] + EmptyPatch, /// COB store error. #[error(transparent)] Cob(#[from] radicle::cob::store::Error), @@ -259,6 +262,9 @@ fn patch_open( let (_, target) = stored.canonical_head()?; let base = stored.backend.merge_base(*target, commit.id())?; + if base == commit.id() { + return Err(Error::EmptyPatch); + } let (title, description) = cli::patch::get_create_message( opts.message, &stored.backend,