59 lines
1.4 KiB
Rust
59 lines
1.4 KiB
Rust
use super::*;
|
|
|
|
use radicle::cob::{patch, resolve_embed};
|
|
use radicle::prelude::*;
|
|
use radicle::storage::git::Repository;
|
|
|
|
use crate::terminal as term;
|
|
|
|
pub fn run(
|
|
patch_id: &PatchId,
|
|
message: term::patch::Message,
|
|
profile: &Profile,
|
|
repository: &Repository,
|
|
) -> anyhow::Result<()> {
|
|
let signer = term::signer(profile)?;
|
|
let mut patches = patch::Patches::open(repository)?;
|
|
let Ok(mut patch) = patches.get_mut(patch_id) else {
|
|
anyhow::bail!("Patch `{patch_id}` not found");
|
|
};
|
|
|
|
let (title, description) = term::patch::get_edit_message(message, &patch)?;
|
|
|
|
let title = if title != patch.title() {
|
|
Some(title)
|
|
} else {
|
|
None
|
|
};
|
|
let description = if description != patch.description() {
|
|
Some(description)
|
|
} else {
|
|
None
|
|
};
|
|
|
|
if title.is_none() && description.is_none() {
|
|
// Nothing to do.
|
|
return Ok(());
|
|
}
|
|
|
|
let (root, _) = patch.root();
|
|
let target = patch.target();
|
|
let embeds = patch
|
|
.embeds()
|
|
.into_iter()
|
|
.filter_map(|embed| resolve_embed(repository, embed.clone()))
|
|
.collect::<Vec<_>>();
|
|
|
|
patch.transaction("Edit", &signer, |tx| {
|
|
if let Some(t) = title {
|
|
tx.edit(t, target)?;
|
|
}
|
|
if let Some(d) = description {
|
|
tx.edit_revision(root, d, embeds)?;
|
|
}
|
|
Ok(())
|
|
})?;
|
|
|
|
Ok(())
|
|
}
|