diff --git a/src/cli_util.rs b/src/cli_util.rs index c532b2507..fbb33f15c 100644 --- a/src/cli_util.rs +++ b/src/cli_util.rs @@ -1395,9 +1395,19 @@ pub fn run_ui_editor(settings: &UserSettings, edit_path: &PathBuf) -> Result<(), Ok(()) } +// TODO: Consider basing this function on `write_commit_summary`. It will need +// more arguments passed to it, but the output will be more consistent. pub fn short_commit_description(commit: &Commit) -> String { let first_line = commit.description().split('\n').next().unwrap(); - format!("{} ({})", short_commit_hash(commit.id()), first_line) + format!( + "{} ({})", + short_commit_hash(commit.id()), + if first_line.is_empty() { + "no description set" + } else { + first_line + } + ) } pub fn short_commit_hash(commit_id: &CommitId) -> String { diff --git a/tests/test_checkout.rs b/tests/test_checkout.rs index c71c673d7..0220ebaae 100644 --- a/tests/test_checkout.rs +++ b/tests/test_checkout.rs @@ -66,7 +66,7 @@ fn test_checkout_not_single_rev() { insta::assert_snapshot!(stderr, @r###" Error: Revset "root..@" resolved to more than one revision Hint: The revset resolved to these revisions: - 2f8593712db5 () + 2f8593712db5 (no description set) 5c1afd8b074f (fifth) 009f88bf7141 (fourth) 3fa8931e7b89 (third)