Skip to content

Commit

Permalink
git: Fix git message parsing
Browse files Browse the repository at this point in the history
- Add data of Author and Date to footer
  • Loading branch information
Daniel Havlíček committed Jul 25, 2024
1 parent f7e3f93 commit 4cc9dcb
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ pub fn read(options: ReadCommitMessageOptions) -> Vec<String> {
(None, None) => "HEAD".to_string(),
};

let opt_target = if let "HEAD" = range.as_str() {
"^FETCH_HEAD".to_string()
} else {
String::new()
};

// See https://git-scm.com/docs/git-log
let stdout = Command::new("git")
.arg("log")
.arg("--pretty=%B")
.arg("--pretty=%B%n|%n%nAuthor: %aN <%aE>%nDate: %ad%ncommit %H")
.arg("--no-merges")
.arg("--no-decorate")
.arg("--reverse")
.arg(range)
.arg(opt_target)
.arg("--") // Explicitly specify the end of options as described https://git-scm.com/docs/git-log#Documentation/git-log.txt---ltpathgt82308203
.arg(options.path)
.output()
Expand All @@ -55,8 +62,10 @@ fn extract_commit_messages(input: &str) -> Vec<String> {

for commit in commits {
let message_lines: Vec<&str> = commit.trim().lines().collect();
let message = message_lines.join("\n");
messages.push(message);
if !message_lines.is_empty() {
let message = message_lines.join("\n");
messages.push(message);
}
}

messages
Expand Down Expand Up @@ -89,7 +98,7 @@ pub fn parse_commit_message(

for line in lines_iter {
if line.trim().is_empty() {
if in_body {
if in_body || line.trim() == "|" {
in_body = false;
in_footer = true;
}
Expand Down

0 comments on commit 4cc9dcb

Please sign in to comment.