Skip to content

Commit b15c864

Browse files
authored
Git Config Commit Comments (#2145)
Closes #2136
1 parent 3d06b54 commit b15c864

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

asyncgit/src/sync/commit.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
//! Git Api for Commits
12
use super::{CommitId, RepoPath};
23
use crate::{
34
error::Result,
45
sync::{repository::repo, utils::get_head_repo},
56
};
6-
use git2::{ErrorCode, ObjectType, Repository, Signature};
7+
use git2::{
8+
message_prettify, ErrorCode, ObjectType, Repository, Signature,
9+
};
710
use scopetime::scope_time;
811

912
///
@@ -119,6 +122,20 @@ pub fn tag_commit(
119122
Ok(c)
120123
}
121124

125+
/// Loads the comment prefix from config & uses it to prettify commit messages
126+
pub fn commit_message_prettify(
127+
repo_path: &RepoPath,
128+
message: String,
129+
) -> Result<String> {
130+
let comment_char = repo(repo_path)?
131+
.config()?
132+
.get_string("core.commentChar")
133+
.map(|char_string| char_string.chars().next())?
134+
.unwrap_or('#') as u8;
135+
136+
Ok(message_prettify(message, Some(comment_char))?)
137+
}
138+
122139
#[cfg(test)]
123140
mod tests {
124141
use crate::error::Result;

asyncgit/src/sync/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
pub mod blame;
77
pub mod branch;
8-
mod commit;
8+
pub mod commit;
99
mod commit_details;
1010
pub mod commit_files;
1111
mod commit_filter;

src/popups/commit.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ use crate::{
1111
ui::style::SharedTheme,
1212
};
1313
use anyhow::{bail, Ok, Result};
14+
use asyncgit::sync::commit::commit_message_prettify;
1415
use asyncgit::{
15-
cached, message_prettify,
16+
cached,
1617
sync::{
1718
self, get_config_string, CommitId, HookResult,
1819
PrepareCommitMsgSource, RepoPathRef, RepoState,
@@ -195,7 +196,8 @@ impl CommitPopup {
195196
drop(file);
196197
std::fs::remove_file(&file_path)?;
197198

198-
message = message_prettify(message, Some(b'#'))?;
199+
message =
200+
commit_message_prettify(&self.repo.borrow(), message)?;
199201
self.input.set_text(message);
200202
self.input.show()?;
201203

@@ -254,8 +256,8 @@ impl CommitPopup {
254256
}
255257
}
256258

257-
//TODO: honor `core.commentChar`
258-
let mut msg = message_prettify(msg, Some(b'#'))?;
259+
let mut msg =
260+
commit_message_prettify(&self.repo.borrow(), msg)?;
259261

260262
if verify {
261263
// run commit message check hook - can reject commit

0 commit comments

Comments
 (0)