diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ac2ae8da3..023054bf5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Fixed - appropriate error message when pulling deleted remote branch ([#911](https://github.com/extrawurst/gitui/issues/991)) - improved color contrast in branches popup for light themes [[@Cottser](https://github.com/Cottser)] ([#922](https://github.com/extrawurst/gitui/issues/922)) +- use git_message_prettify for commit messages ([#917](https://github.com/extrawurst/gitui/issues/917)) ## [0.17.1] - 2021-09-10 diff --git a/asyncgit/src/lib.rs b/asyncgit/src/lib.rs index 9530817ccf..3dffa22d05 100644 --- a/asyncgit/src/lib.rs +++ b/asyncgit/src/lib.rs @@ -57,6 +57,7 @@ pub use crate::{ }, tags::AsyncTags, }; +pub use git2::message_prettify; use std::{ collections::hash_map::DefaultHasher, hash::{Hash, Hasher}, diff --git a/src/components/commit.rs b/src/components/commit.rs index 851bbb1f75..9835b30332 100644 --- a/src/components/commit.rs +++ b/src/components/commit.rs @@ -11,7 +11,7 @@ use crate::{ }; use anyhow::Result; use asyncgit::{ - cached, + cached, message_prettify, sync::{ self, get_config_string, CommitId, HookResult, RepoState, }, @@ -149,19 +149,7 @@ impl CommitComponent { drop(file); std::fs::remove_file(&file_path)?; - let message: String = message - .lines() - .flat_map(|l| { - if l.starts_with('#') { - vec![] - } else { - vec![l, "\n"] - } - }) - .collect(); - - let message = message.trim().to_string(); - + message = message_prettify(message, Some(b'#'))?; self.input.set_text(message); self.input.show()?; @@ -193,7 +181,7 @@ impl CommitComponent { ))); return Ok(()); } - let mut msg = msg; + let mut msg = message_prettify(msg, Some(b'#'))?; if let HookResult::NotOk(e) = sync::hooks_commit_msg(CWD, &mut msg)? {