From 3d12fd38d239577c631b48db51e4d4c92e17684f Mon Sep 17 00:00:00 2001 From: Concelare <113200622+Concelare@users.noreply.github.com> Date: Sun, 24 Mar 2024 23:36:57 +0000 Subject: [PATCH] Added: - Tests for git config comment char when set and when not --- asyncgit/src/sync/commit.rs | 39 ++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs index 01d8a878d5..18b381fd5a 100644 --- a/asyncgit/src/sync/commit.rs +++ b/asyncgit/src/sync/commit.rs @@ -211,7 +211,7 @@ mod tests { utils::get_head, LogWalker, }; - use commit::{amend, tag_commit}; + use commit::{amend, commit_message_prettify, tag_commit}; use git2::Repository; use std::{fs::File, io::Write, path::Path}; @@ -463,4 +463,41 @@ mod tests { Ok(()) } + + #[test] + fn test_empty_comment_char() -> Result<()> { + let (_td, repo) = repo_init_empty().unwrap(); + + let root = repo.path().parent().unwrap(); + let repo_path: &RepoPath = + &root.as_os_str().to_str().unwrap().into(); + + let message = commit_message_prettify( + repo_path, + "#This is a test message\nTest".to_owned(), + )?; + + assert_eq!(message, "Test\n"); + Ok(()) + } + + #[test] + fn test_with_comment_char() -> Result<()> { + let (_td, repo) = repo_init_empty().unwrap(); + + let root = repo.path().parent().unwrap(); + let repo_path: &RepoPath = + &root.as_os_str().to_str().unwrap().into(); + + repo.config()?.set_str("core.commentChar", ";")?; + + let message = commit_message_prettify( + repo_path, + ";This is a test message\nTest".to_owned(), + )?; + + assert_eq!(message, "Test\n"); + + Ok(()) + } }