Skip to content

Commit c9cb50d

Browse files
committed
git: Fix git message parsing
- Add data of Author and Date to footer
1 parent f7e3f93 commit c9cb50d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/git.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub fn read(options: ReadCommitMessageOptions) -> Vec<String> {
3232
// See https://git-scm.com/docs/git-log
3333
let stdout = Command::new("git")
3434
.arg("log")
35-
.arg("--pretty=%B")
35+
.arg("--pretty=%B%n|%n%nAuthor: %aN <%aE>%nDate: %ad%ncommit %H")
3636
.arg("--no-merges")
3737
.arg("--no-decorate")
3838
.arg("--reverse")
@@ -48,15 +48,17 @@ pub fn read(options: ReadCommitMessageOptions) -> Vec<String> {
4848
}
4949

5050
fn extract_commit_messages(input: &str) -> Vec<String> {
51-
let commit_delimiter = Regex::new(r"(?m)^commit [0-9a-f]{40}$").unwrap();
51+
let commit_delimiter = Regex::new(r"(?m)^commit [0-9a-f]{40}").unwrap();
5252
let commits: Vec<&str> = commit_delimiter.split(input).collect();
5353

5454
let mut messages: Vec<String> = Vec::new();
5555

5656
for commit in commits {
5757
let message_lines: Vec<&str> = commit.trim().lines().collect();
58-
let message = message_lines.join("\n");
59-
messages.push(message);
58+
if !message_lines.is_empty() {
59+
let message = message_lines.join("\n");
60+
messages.push(message);
61+
}
6062
}
6163

6264
messages
@@ -89,7 +91,7 @@ pub fn parse_commit_message(
8991

9092
for line in lines_iter {
9193
if line.trim().is_empty() {
92-
if in_body {
94+
if in_body || line.trim() == "|" {
9395
in_body = false;
9496
in_footer = true;
9597
}

0 commit comments

Comments
 (0)