git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Boris Faure <billiob@gmail.com>
To: git@vger.kernel.org
Cc: Boris Faure <billiob@gmail.com>
Subject: [PATCH/RFC v2] Do not strip empty lines / trailing spaces from a commit message template
Date: Sun,  8 May 2011 12:31:02 +0200	[thread overview]
Message-ID: <1304850662-6424-1-git-send-email-billiob@gmail.com> (raw)
In-Reply-To: <4DC65888.7090309@gmail.com>

Templates should be just that: A form that the user fills out, and forms
have blanks. If people are attached to not having extra whitespace in the
editor, they can simply clean up their templates.

Added test with editor adding even more whitespace.

Signed-off-by: Boris Faure <billiob@gmail.com>
Based-on-patch-by:Sebastian Schuberth <sschuberth@gmail.com>
---
 builtin/commit.c                |    4 +++-
 t/t7500-commit.sh               |   14 ++++++++++++++
 t/t7500/add-whitespaced-content |    3 +++
 3 files changed, 20 insertions(+), 1 deletions(-)
 create mode 100755 t/t7500/add-whitespaced-content

diff --git a/builtin/commit.c b/builtin/commit.c
index 67757e9..411d5e4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -615,6 +615,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	const char *hook_arg1 = NULL;
 	const char *hook_arg2 = NULL;
 	int ident_shown = 0;
+	int clean_message_contents = (cleanup_mode != CLEANUP_NONE);
 
 	if (!no_verify && run_hook(index_file, "pre-commit", NULL))
 		return 0;
@@ -681,6 +682,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 		if (strbuf_read_file(&sb, template_file, 0) < 0)
 			die_errno(_("could not read '%s'"), template_file);
 		hook_arg1 = "template";
+		clean_message_contents = 0;
 	}
 
 	/*
@@ -708,7 +710,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
 	if (s->fp == NULL)
 		die_errno(_("could not open '%s'"), git_path(commit_editmsg));
 
-	if (cleanup_mode != CLEANUP_NONE)
+	if (clean_message_contents)
 		stripspace(&sb, 0);
 
 	if (signoff) {
diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh
index 47096f9..dedbc0d 100755
--- a/t/t7500-commit.sh
+++ b/t/t7500-commit.sh
@@ -123,6 +123,20 @@ test_expect_success 'commit message from file should override template' '
 	commit_msg_is "standard input msg"
 '
 
+cat > "$TEMPLATE" << EOF
+
+
+### template
+
+EOF
+test_expect_success 'commit message from template with whitespace issue' '
+	echo "content galore" >> foo &&
+	git add foo &&
+	GIT_EDITOR="$TEST_DIRECTORY"/t7500/add-whitespaced-content git commit \
+		--template "$TEMPLATE" &&
+	commit_msg_is "commit message"
+'
+
 test_expect_success 'using alternate GIT_INDEX_FILE (1)' '
 
 	cp .git/index saved-index &&
diff --git a/t/t7500/add-whitespaced-content b/t/t7500/add-whitespaced-content
new file mode 100755
index 0000000..3d71c68
--- /dev/null
+++ b/t/t7500/add-whitespaced-content
@@ -0,0 +1,3 @@
+#!/bin/sh
+echo -e "\n \ncommit message  	 \n\n" >> "$1"
+exit 0
-- 
1.7.5.1.217.g4e3aa.dirty

  reply	other threads:[~2011-05-08 10:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-07 15:53 [PATCH 1/2] commit: do not cleanup template Boris Faure
2011-05-07 15:53 ` [PATCH 2/2] commit: do not add a newline after a template Boris Faure
2011-05-07 20:13 ` [PATCH 1/2] commit: do not cleanup template Junio C Hamano
2011-05-07 21:17   ` Boris 'billiob' Faure
2011-05-07 22:31     ` Junio C Hamano
2011-05-08  8:38   ` Sebastian Schuberth
2011-05-08  8:47   ` Sebastian Schuberth
2011-05-08 10:31     ` Boris Faure [this message]
2011-05-08 12:28       ` [PATCH/RFC v2] Do not strip empty lines / trailing spaces from a commit message template Sebastian Schuberth
2011-05-08 18:14         ` Junio C Hamano
2011-05-08 18:55           ` [PATCH/RFC v3] " Boris Faure

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1304850662-6424-1-git-send-email-billiob@gmail.com \
    --to=billiob@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).