remote-helper: Don't allow opening an empty patch

If the commit range is empty, return an error.
This commit is contained in:
Alexis Sellier 2023-06-08 15:01:22 +02:00
parent 431a389944
commit 0319bbb903
No known key found for this signature in database
2 changed files with 18 additions and 0 deletions

View File

@ -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'
```

View File

@ -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,