ok/jj
1
0
Fork 0
forked from mirrors/jj

Improve short_commit_description for commits without a description

This commit is contained in:
Ilya Grigoriev 2023-01-07 16:23:25 -08:00
parent 6765850c7d
commit ef3071ba09
2 changed files with 12 additions and 2 deletions

View file

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

View file

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