mirror of
https://github.com/gitui-org/gitui
synced 2026-05-23 17:08:21 +00:00
limit log message to first line of commit msg (#662)
This commit is contained in:
parent
97985bfe62
commit
95c41dbf45
2 changed files with 28 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
### Fixed
|
||||
- debug print when adding a file to ignore
|
||||
- limit log messages in log tab ([#652](https://github.com/extrawurst/gitui/issues/652))
|
||||
- fetch crashed when no upstream of branch is set ([#637](https://github.com/extrawurst/gitui/issues/637))
|
||||
- `enter` key panics in empty remote branch list ([#643](https://github.com/extrawurst/gitui/issues/643))
|
||||
|
||||
|
|
|
|||
|
|
@ -115,17 +115,21 @@ pub fn get_commit_info(
|
|||
})
|
||||
}
|
||||
|
||||
///
|
||||
/// if `message_limit` is set the message will be
|
||||
/// limited to the first line and truncated to fit
|
||||
pub fn get_message(
|
||||
c: &Commit,
|
||||
message_length_limit: Option<usize>,
|
||||
message_limit: Option<usize>,
|
||||
) -> String {
|
||||
let msg = String::from_utf8_lossy(c.message_bytes());
|
||||
let msg = msg.trim();
|
||||
|
||||
message_length_limit.map_or_else(
|
||||
message_limit.map_or_else(
|
||||
|| msg.to_string(),
|
||||
|limit| msg.unicode_truncate(limit).0.to_string(),
|
||||
|limit| {
|
||||
let msg = msg.lines().next().unwrap_or_default();
|
||||
msg.unicode_truncate(limit).0.to_string()
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -164,6 +168,25 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_log_first_msg_line() -> Result<()> {
|
||||
let file_path = Path::new("foo");
|
||||
let (_td, repo) = repo_init_empty().unwrap();
|
||||
let root = repo.path().parent().unwrap();
|
||||
let repo_path = root.as_os_str().to_str().unwrap();
|
||||
|
||||
File::create(&root.join(file_path))?.write_all(b"a")?;
|
||||
stage_add_file(repo_path, file_path).unwrap();
|
||||
let c1 = commit(repo_path, "subject\nbody").unwrap();
|
||||
|
||||
let res = get_commits_info(repo_path, &vec![c1], 50).unwrap();
|
||||
|
||||
assert_eq!(res.len(), 1);
|
||||
assert_eq!(res[0].message.as_str(), "subject");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_invalid_utf8() -> Result<()> {
|
||||
let file_path = Path::new("foo");
|
||||
|
|
|
|||
Loading…
Reference in a new issue