cli: make short_commit_description() compatible with default summary template

This commit is contained in:
Yuya Nishihara 2023-01-14 19:00:22 +09:00
parent 3e50844afa
commit 15e51315ec
2 changed files with 13 additions and 13 deletions

View File

@ -1422,10 +1422,10 @@ pub fn run_ui_editor(settings: &UserSettings, edit_path: &PathBuf) -> Result<(),
pub fn short_commit_description(commit: &Commit) -> String { pub fn short_commit_description(commit: &Commit) -> String {
let first_line = commit.description().split('\n').next().unwrap(); let first_line = commit.description().split('\n').next().unwrap();
format!( format!(
"{} ({})", "{} {}",
short_commit_hash(commit.id()), short_commit_hash(commit.id()),
if first_line.is_empty() { if first_line.is_empty() {
"no description set" "(no description set)"
} else { } else {
first_line first_line
} }

View File

@ -67,10 +67,10 @@ fn test_checkout_not_single_rev() {
Error: Revset "root..@" resolved to more than one revision Error: Revset "root..@" resolved to more than one revision
Hint: The revset resolved to these revisions: Hint: The revset resolved to these revisions:
2f8593712db5 (no description set) 2f8593712db5 (no description set)
5c1afd8b074f (fifth) 5c1afd8b074f fifth
009f88bf7141 (fourth) 009f88bf7141 fourth
3fa8931e7b89 (third) 3fa8931e7b89 third
5c52832c3483 (second) 5c52832c3483 second
... ...
"###); "###);
@ -78,19 +78,19 @@ fn test_checkout_not_single_rev() {
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
Error: Revset "root..@-" resolved to more than one revision Error: Revset "root..@-" resolved to more than one revision
Hint: The revset resolved to these revisions: Hint: The revset resolved to these revisions:
5c1afd8b074f (fifth) 5c1afd8b074f fifth
009f88bf7141 (fourth) 009f88bf7141 fourth
3fa8931e7b89 (third) 3fa8931e7b89 third
5c52832c3483 (second) 5c52832c3483 second
69542c1984c1 (first) 69542c1984c1 first
"###); "###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "@-|@--"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "@-|@--"]);
insta::assert_snapshot!(stderr, @r###" insta::assert_snapshot!(stderr, @r###"
Error: Revset "@-|@--" resolved to more than one revision Error: Revset "@-|@--" resolved to more than one revision
Hint: The revset resolved to these revisions: Hint: The revset resolved to these revisions:
5c1afd8b074f (fifth) 5c1afd8b074f fifth
009f88bf7141 (fourth) 009f88bf7141 fourth
"###); "###);
let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "none()"]); let stderr = test_env.jj_cmd_failure(&repo_path, &["checkout", "none()"]);