From: "SZEDER Gábor" <szeder@ira.uka.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org, "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [PATCH] commit: cope with scissors lines in commit message
Date: Mon, 8 Jun 2015 03:40:39 +0200 [thread overview]
Message-ID: <1433727639-5927-1-git-send-email-szeder@ira.uka.de> (raw)
The diff and submodule shortlog appended to the commit message template
by 'git commit --verbose' are not stripped when the commit message
contains an indented scissors line.
When cleaning up a commit message with 'git commit --verbose' or
'--cleanup=scissors' the code is careful and triggers only on a pure
scissors line, i.e. a line containing nothing but a comment character, a
space, and the scissors cut. This is good, because people can embed
scissor lines in the commit message while using 'git commit --verbose',
and the text they write after their indented scissors line doesn't get
deleted.
While doing so, however, the cleanup function only looks at the first
line matching the scissors pattern and if it doesn't start at the
beginning of the line, then the function just returns without performing
any cleanup. This is bad, because a "real" scissors line added by 'git
commit --verbose' might follow, and in that case the diff and submodule
shortlog get included in the commit message.
Don't bail out if a scissors line doesn't start at the beginning of the
line, but keep looking for a non-indented scissors line to fix this.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
t/t7502-commit.sh | 25 +++++++++++++++++++++++++
wt-status.c | 12 ++++++++----
2 files changed, 33 insertions(+), 4 deletions(-)
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 2e0d557243..77db3a31c3 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -239,6 +239,31 @@ EOF
'
+test_expect_success 'cleanup commit messages (scissors option,-F,-e, scissors line in commit message)' '
+ echo >>negative &&
+ cat >text <<EOF &&
+
+ # to be kept
+
+ # ------------------------ >8 ------------------------
+ # to be kept, too
+# ------------------------ >8 ------------------------
+to be removed
+# ------------------------ >8 ------------------------
+to be removed, too
+EOF
+
+ cat >expect <<EOF &&
+ # to be kept
+
+ # ------------------------ >8 ------------------------
+ # to be kept, too
+EOF
+ git commit --cleanup=scissors -e -F text -a &&
+ git cat-file -p HEAD |sed -e "1,/^\$/d">actual &&
+ test_cmp expect actual
+'
+
test_expect_success 'cleanup commit messages (strip option,-F)' '
echo >>negative &&
diff --git a/wt-status.c b/wt-status.c
index c56c78fb6f..e6d171a0cb 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -822,13 +822,17 @@ conclude:
void wt_status_truncate_message_at_cut_line(struct strbuf *buf)
{
- const char *p;
+ const char *p = buf->buf;
struct strbuf pattern = STRBUF_INIT;
strbuf_addf(&pattern, "%c %s", comment_line_char, cut_line);
- p = strstr(buf->buf, pattern.buf);
- if (p && (p == buf->buf || p[-1] == '\n'))
- strbuf_setlen(buf, p - buf->buf);
+ while ((p = strstr(p, pattern.buf))) {
+ if (p == buf->buf || p[-1] == '\n') {
+ strbuf_setlen(buf, p - buf->buf);
+ break;
+ }
+ p++;
+ }
strbuf_release(&pattern);
}
--
2.4.2.423.gad3a03f
next reply other threads:[~2015-06-08 1:41 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-08 1:40 SZEDER Gábor [this message]
2015-06-08 15:36 ` [PATCH] commit: cope with scissors lines in commit message Junio C Hamano
2015-06-08 16:30 ` SZEDER Gábor
2015-06-09 0:24 ` [PATCH v2] " SZEDER Gábor
2015-06-09 0:28 ` [PATCH v3] " SZEDER Gábor
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=1433727639-5927-1-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/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).