From 0b1a6cd9e01b0fd37a10601e64da4789bf094002 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 5 Aug 2024 20:29:04 +0900 Subject: [PATCH] cli: allow any number of trailing dashes in "JJ: describe" line Because a line without " -------" is allowed, it makes sense to strip other variants like " --". --- cli/src/description_util.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/src/description_util.rs b/cli/src/description_util.rs index e76c789c2..394dbe617 100644 --- a/cli/src/description_util.rs +++ b/cli/src/description_util.rs @@ -121,7 +121,8 @@ where let mut messages: Vec<(&str, Vec<&str>)> = vec![]; for line in message.lines() { if let Some(commit_id_prefix) = line.strip_prefix("JJ: describe ") { - let commit_id_prefix = commit_id_prefix.trim_end_matches(" -------"); + let commit_id_prefix = + commit_id_prefix.trim_end_matches(|c: char| c.is_ascii_whitespace() || c == '-'); messages.push((commit_id_prefix, vec![])); } else if let Some((_, lines)) = messages.last_mut() { lines.push(line); @@ -257,12 +258,16 @@ mod tests { JJ: describe 1 ------- Description 1 - JJ: describe 2 ------- + JJ: describe 2 Description 2 + + JJ: describe 3 -- + Description 3 "}, &indexmap! { "1".to_string() => &1, "2".to_string() => &2, + "3".to_string() => &3, }, ) .unwrap(); @@ -271,6 +276,7 @@ mod tests { hashmap! { 1 => "Description 1\n".to_string(), 2 => "Description 2\n".to_string(), + 3 => "Description 3\n".to_string(), } ); assert!(result.missing.is_empty());