Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
remote-helper: Don't allow opening an empty patch
Alexis Sellier committed 2 years ago
commit 0319bbb9035f0fe73ab8a7bd8f3791b5ca95b9c9
parent 431a38994496ee9d9d5a785065a68a7ea10c471f
2 files changed +18 -0
modified 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'
+
```
modified 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<G: Signer>(

    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,