mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-16 08:10:40 +08:00
Help the user when creating a patch by listing the messages of all commits associated with the patch in almost the same format as git uses for squashing.
54 lines
1.2 KiB
Rust
54 lines
1.2 KiB
Rust
use super::*;
|
|
|
|
use radicle::cob::patch;
|
|
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.id.into();
|
|
let target = patch.target();
|
|
|
|
patch.transaction("Edit", &signer, |tx| {
|
|
if let Some(t) = title {
|
|
tx.edit(t, target)?;
|
|
}
|
|
if let Some(d) = description {
|
|
tx.edit_revision(root, d)?;
|
|
}
|
|
Ok(())
|
|
})?;
|
|
|
|
Ok(())
|
|
}
|