CC: | Mark Grimes <mgrimes [...] peculier.com> |
Subject: | [PATCH] Only strip off the indentation added to the log messages by git |
Date: | Fri, 9 Apr 2010 09:18:00 -0400 |
To: | bug-Git-Wrapper [...] rt.cpan.org |
From: | Mark Grimes <mgrimes [...] cpan.org> |
From: Mark Grimes <mgrimes@peculier.com>
Thanks for Git::Wrapper--it has been a very helpful module.
This patch preserves any indentation that the user included in their
log messages. It find the indentation of the first line of the log
message and then strips off only that much indentation from
following line.
I have also update the tests in basic.t to check for this
behavior.
---
lib/Git/Wrapper.pm | 3 ++-
t/basic.t | 5 +++--
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/lib/Git/Wrapper.pm b/lib/Git/Wrapper.pm
index 2375a03..7098824 100644
--- a/lib/Git/Wrapper.pm
+++ b/lib/Git/Wrapper.pm
@@ -113,8 +113,9 @@ sub log {
}
die "no blank line separating head from message" if $_;
my $message = '';
+ my ( $initial_indent ) = $out[0] =~ /^(\s*)/ if @out;
while (@out and length($_ = shift @out)) {
- s/^\s+//;
+ s/^$initial_indent//; # strip just the indenting added by git
$message .= "$_\n";
}
$current->message($message);
diff --git a/t/basic.t b/t/basic.t
index 4f65ac0..ba76f12 100644
--- a/t/basic.t
+++ b/t/basic.t
@@ -32,7 +32,7 @@ is_deeply(
);
my $time = time;
-$git->commit({ message => "FIRST" });
+$git->commit({ message => "FIRST\n\n\tBODY\n" });
my @rev_list =
$git->rev_list({ all => 1, pretty => 'oneline' });
@@ -52,5 +52,6 @@ my @log = $git->log({ date => 'iso' });
is(@log, 1, 'one log entry');
my $log = $log[0];
is($log->id, (split /\s/, $rev_list[0])[0], 'id');
-is($log->message, "FIRST\n", "message");
+is($log->message, "FIRST\n\n\tBODY\n", "message");
is($log->date, $date, "date");
+
--
1.7.0.2