cli: prevent identical revision for `rad patch update`

Prevent `rad patch update` to create an identical revision to any
other revision in the patch, rather than just the latest revision.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
Fintan Halpenny 2024-01-08 09:55:40 +00:00 committed by cloudhead
parent e4f06e9c9d
commit 9f9df6264e
No known key found for this signature in database
1 changed files with 7 additions and 3 deletions

View File

@ -30,12 +30,16 @@ pub fn run(
None => storage.backend.merge_base(*target_oid, *head_oid)?,
};
let (_, revision) = patch.latest();
// N.b. we don't update if both the head and base are the same
if revision.head() == head_oid && **revision.base() == base_oid {
// N.b. we don't update if both the head and base are the same as
// any previous revision
if patch
.revisions()
.any(|(_, revision)| revision.head() == head_oid && **revision.base() == base_oid)
{
return Ok(());
}
let (_, revision) = patch.latest();
let message = term::patch::get_update_message(message, workdir, revision, &head_oid)?;
let signer = term::signer(profile)?;
let revision = patch.update(message, base_oid, *head_oid, &signer)?;