Fix patch `description` method

The description is not actually optional, so don't return an `Option`.
This commit is contained in:
Alexis Sellier 2023-03-17 09:31:36 +01:00
parent d40f40b9af
commit cf1acf7e24
No known key found for this signature in database
3 changed files with 8 additions and 7 deletions

View File

@ -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 {}",

View File

@ -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();
}

View File

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