From cf1acf7e24738f6e2833d5cd62432f18c381bf3a Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Fri, 17 Mar 2023 09:31:36 +0100 Subject: [PATCH] Fix patch `description` method The description is not actually optional, so don't return an `Option`. --- radicle-cli/src/commands/merge.rs | 2 +- radicle-cli/src/commands/patch/show.rs | 5 +++-- radicle/src/cob/patch.rs | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/radicle-cli/src/commands/merge.rs b/radicle-cli/src/commands/merge.rs index 1207befc..9691ebad 100644 --- a/radicle-cli/src/commands/merge.rs +++ b/radicle-cli/src/commands/merge.rs @@ -291,7 +291,7 @@ fn merge_commit( patch: &Patch, whoami: &PublicKey, ) -> anyhow::Result<()> { - let description = patch.description().unwrap_or_default().trim(); + let description = patch.description().trim(); let mut merge_opts = git::raw::MergeOptions::new(); let mut merge_msg = format!( "Merge patch '{}' from {}", diff --git a/radicle-cli/src/commands/patch/show.rs b/radicle-cli/src/commands/patch/show.rs index 54ebe71e..635f6623 100644 --- a/radicle-cli/src/commands/patch/show.rs +++ b/radicle-cli/src/commands/patch/show.rs @@ -43,8 +43,9 @@ pub fn run( term::info!("{}", term::format::bold(patch.title())); term::blank(); - if let Some(desc) = patch.description() { - term::blob(desc.trim()); + let description = patch.description().trim(); + if !description.is_empty() { + term::blob(description); term::blank(); } diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index 35fdf69f..f1b4c63d 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -188,8 +188,8 @@ impl Patch { self.tags.iter() } - pub fn description(&self) -> Option<&str> { - Some(self.description.get().get()) + pub fn description(&self) -> &str { + self.description.get().get() } pub fn author(&self) -> &Author { @@ -1091,7 +1091,7 @@ mod test { let patch = patches.get(&id).unwrap().unwrap(); assert_eq!(patch.title(), "My first patch"); - assert_eq!(patch.description(), Some("Blah blah blah.")); + assert_eq!(patch.description(), "Blah blah blah."); assert_eq!(patch.author().id(), &author); assert_eq!(patch.state(), State::Proposed); assert_eq!(patch.target(), target); @@ -1365,7 +1365,7 @@ mod test { .unwrap(); assert_eq!(patch.clock.get(), 1); - assert_eq!(patch.description(), Some("Blah blah blah.")); + assert_eq!(patch.description(), "Blah blah blah."); assert_eq!(patch.version(), 0); let _ = patch