summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConcelare <113200622+Concelare@users.noreply.github.com>2024-03-22 22:12:08 +0000
committerGitHub <noreply@github.com>2024-03-22 15:12:08 -0700
commitb15c8643c8692fc9f01508120709e12d50d8e26a (patch)
tree68288845b2eb7dfbef81215595a2d4a2c7f946b2
parent3d06b54d2ce0bac8ea4b64c8cb6d6ce318bade2e (diff)
Git Config Commit Comments (#2145)
Closes #2136
-rw-r--r--asyncgit/src/sync/commit.rs19
-rw-r--r--asyncgit/src/sync/mod.rs2
-rw-r--r--src/popups/commit.rs10
3 files changed, 25 insertions, 6 deletions
diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs
index b2b7a474..36884a0b 100644
--- a/asyncgit/src/sync/commit.rs
+++ b/asyncgit/src/sync/commit.rs
@@ -1,9 +1,12 @@
+//! Git Api for Commits
use super::{CommitId, RepoPath};
use crate::{
error::Result,
sync::{repository::repo, utils::get_head_repo},
};
-use git2::{ErrorCode, ObjectType, Repository, Signature};
+use git2::{
+ message_prettify, ErrorCode, ObjectType, Repository, Signature,
+};
use scopetime::scope_time;
///
@@ -119,6 +122,20 @@ pub fn tag_commit(
Ok(c)
}
+/// Loads the comment prefix from config & uses it to prettify commit messages
+pub fn commit_message_prettify(
+ repo_path: &RepoPath,
+ message: String,
+) -> Result<String> {
+ let comment_char = repo(repo_path)?
+ .config()?
+ .get_string("core.commentChar")
+ .map(|char_string| char_string.chars().next())?
+ .unwrap_or('#') as u8;
+
+ Ok(message_prettify(message, Some(comment_char))?)
+}
+
#[cfg(test)]
mod tests {
use crate::error::Result;
diff --git a/asyncgit/src/sync/mod.rs b/asyncgit/src/sync/mod.rs
index c188f28c..dcc3419e 100644
--- a/asyncgit/src/sync/mod.rs
+++ b/asyncgit/src/sync/mod.rs
@@ -5,7 +5,7 @@
pub mod blame;
pub mod branch;
-mod commit;
+pub mod commit;
mod commit_details;
pub mod commit_files;
mod commit_filter;
diff --git a/src/popups/commit.rs b/src/popups/commit.rs
index cb68bd1f..36cef4e3 100644
--- a/src/popups/commit.rs
+++ b/src/popups/commit.rs
@@ -11,8 +11,9 @@ use crate::{
ui::style::SharedTheme,
};
use anyhow::{bail, Ok, Result};
+use asyncgit::sync::commit::commit_message_prettify;
use asyncgit::{
- cached, message_prettify,
+ cached,
sync::{
self, get_config_string, CommitId, HookResult,
PrepareCommitMsgSource, RepoPathRef, RepoState,
@@ -195,7 +196,8 @@ impl CommitPopup {
drop(file);
std::fs::remove_file(&file_path)?;
- message = message_prettify(message, Some(b'#'))?;
+ message =
+ commit_message_prettify(&self.repo.borrow(), message)?;
self.input.set_text(message);
self.input.show()?;
@@ -254,8 +256,8 @@ impl CommitPopup {
}
}
- //TODO: honor `core.commentChar`
- let mut msg = message_prettify(msg, Some(b'#'))?;
+ let mut msg =
+ commit_message_prettify(&self.repo.borrow(), msg)?;
if verify {
// run commit message check hook - can reject commit