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

cli: remove trailing blank lines from commit description after editing

This commit is contained in:
Martin von Zweigbergk 2021-05-16 00:10:31 -07:00
parent f96130d21c
commit e29cef7918

View file

@ -1348,10 +1348,14 @@ fn edit_description(repo: &ReadonlyRepo, description: &str) -> String {
// Delete the file only if everything went well.
// TODO: Tell the user the name of the file we left behind.
std::fs::remove_file(description_file_path).ok();
let lines: Vec<_> = description
let mut lines: Vec<_> = description
.split_inclusive('\n')
.filter(|line| !line.starts_with("JJ: "))
.collect();
// Remove trailing blank lines
while matches!(lines.last(), Some(&"\n") | Some(&"\r\n")) {
lines.pop().unwrap();
}
lines.join("")
}