[PATCH 4/5] commit: loosen pattern for matching "-v" diff

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



When a user asks to see the diff to be applied via "git
commit -v", the diff ends up in the commit template, and we
must later remove it.

To detect the start of the included diff, we used to search
for a line beginning with "diff --git a/". However, in the
face of diff.mnemonicprefix, that will actually be "diff
--git i/".

So let's just loosen the pattern a bit to handle either
case.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
And this is the fix from before, with a test case.

 builtin-commit.c          |    2 +-
 t/t7507-commit-verbose.sh |   16 ++++++++++++++++
 2 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/builtin-commit.c b/builtin-commit.c
index 93ca496..a721990 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -1015,7 +1015,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 	}
 
 	/* Truncate the message just before the diff, if any. */
-	p = strstr(sb.buf, "\ndiff --git a/");
+	p = strstr(sb.buf, "\ndiff --git ");
 	if (p != NULL)
 		strbuf_setlen(&sb, p - sb.buf + 1);
 
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 94b12e9..be70166 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -26,4 +26,20 @@ test_expect_success 'initial commit shows verbose diff' '
 	git commit --amend -v
 '
 
+check_message() {
+	git log -1 --pretty=format:%s%n%n%b >actual &&
+	test_cmp "$1" actual
+}
+
+test_expect_success 'verbose diff is stripped out' '
+	git commit --amend -v &&
+	check_message message
+'
+
+test_expect_success 'verbose diff is stripped out (mnemonicprefix)' '
+	git config diff.mnemonicprefix true &&
+	git commit --amend -v &&
+	check_message message
+'
+
 test_done
-- 
1.6.0.4.883.g4593ee.dirty

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux