Skip to content

Git Config Commit Comments #2145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion asyncgit/src/sync/commit.rs
Original file line number Diff line number Diff line change
@@ -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;

///
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion asyncgit/src/sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions src/popups/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()?;

Expand Down Expand Up @@ -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
Expand Down