From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/3] commit: add --cleanup=scissors
Date: Sun, 16 Feb 2014 10:37:20 +0700 [thread overview]
Message-ID: <1392521840-21628-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1392521840-21628-1-git-send-email-pclouds@gmail.com>
Since 1a72cfd (commit -v: strip diffs and submodule shortlogs from the
commit message - 2013-12-05) we have a less fragile way to cut out
"git status" at the end of a commit message but it's only enabled for
stripping submodule shortlogs. Add new cleanup option that reuses the
same mechanism for the entire "git status" without accidentally remove
lines starting with '#'
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/git-commit.txt | 7 ++++++-
builtin/commit.c | 9 +++++++--
t/t7502-commit.sh | 16 ++++++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 1a7616c..98f976a 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -176,7 +176,7 @@ OPTIONS
--cleanup=<mode>::
This option determines how the supplied commit message should be
cleaned up before committing. The '<mode>' can be `strip`,
- `whitespace`, `verbatim`, or `default`.
+ `whitespace`, `verbatim`, `scissors` or `default`.
+
--
strip::
@@ -186,6 +186,11 @@ whitespace::
Same as `strip` except #commentary is not removed.
verbatim::
Do not change the message at all.
+scissors::
+ Same as `whitespace`, except that everything from the line
+ "`# ------------------------ >8 ------------------------`"
+ is truncated if the message is to be edited. "`#`" could be
+ customized with core.commentChar.
default::
Same as `strip` if the message is to be edited.
Otherwise `whitespace`.
diff --git a/builtin/commit.c b/builtin/commit.c
index 3767478..ea2912f 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -113,6 +113,7 @@ static char *sign_commit;
static enum {
CLEANUP_SPACE,
CLEANUP_NONE,
+ CLEANUP_SCISSORS,
CLEANUP_ALL
} cleanup_mode;
static const char *cleanup_arg;
@@ -777,6 +778,8 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
_("Please enter the commit message for your changes."
" Lines starting\nwith '%c' will be ignored, and an empty"
" message aborts the commit.\n"), comment_line_char);
+ else if (cleanup_mode == CLEANUP_SCISSORS)
+ wt_status_add_cut_line(s->fp);
else /* CLEANUP_SPACE, that is. */
status_printf(s, GIT_COLOR_NORMAL,
_("Please enter the commit message for your changes."
@@ -1132,6 +1135,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
cleanup_mode = CLEANUP_SPACE;
else if (!strcmp(cleanup_arg, "strip"))
cleanup_mode = CLEANUP_ALL;
+ else if (!strcmp(cleanup_arg, "scissors"))
+ cleanup_mode = use_editor ? CLEANUP_SCISSORS : CLEANUP_SPACE;
else
die(_("Invalid cleanup mode %s"), cleanup_arg);
@@ -1600,8 +1605,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
die(_("could not read commit message: %s"), strerror(saved_errno));
}
- /* Truncate the message just before the diff, if any. */
- if (verbose)
+ if (verbose || /* Truncate the message just before the diff, if any. */
+ cleanup_mode == CLEANUP_SCISSORS)
wt_status_truncate_message_at_cut_line(&sb);
if (cleanup_mode != CLEANUP_NONE)
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 6313da2..9a3f3a1 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -223,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' '
'
+test_expect_success 'cleanup commit messages (scissors option,-F,-e)' '
+
+ echo >>negative &&
+ cat >text <<EOF &&
+
+# to be kept
+# ------------------------ >8 ------------------------
+to be removed
+EOF
+ echo "# to be kept" >expect &&
+ 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 &&
--
1.8.5.2.240.g8478abd
next prev parent reply other threads:[~2014-02-16 3:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-02-16 3:37 [PATCH 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
2014-02-16 3:37 ` [PATCH 1/3] wt-status.c: make cut_lines[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
2014-02-16 16:21 ` brian m. carlson
2014-02-16 3:37 ` [PATCH 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
2014-02-16 3:37 ` Nguyễn Thái Ngọc Duy [this message]
2014-02-16 3:44 ` [PATCH 3/3] commit: add --cleanup=scissors Eric Sunshine
2014-02-17 12:15 ` [PATCH v2 0/3] commit --cleanup=<scissors marker> Nguyễn Thái Ngọc Duy
2014-02-17 12:15 ` [PATCH v2 1/3] wt-status.c: make cut_line[] const to shrink .data section a bit Nguyễn Thái Ngọc Duy
2014-02-17 12:15 ` [PATCH v2 2/3] wt-status.c: move cut-line print code out to wt_status_add_cut_line Nguyễn Thái Ngọc Duy
2014-02-17 12:15 ` [PATCH v2 3/3] commit: add --cleanup=scissors Nguyễn Thái Ngọc Duy
2014-02-22 0:58 ` Duy Nguyen
2014-02-24 17:20 ` Junio C Hamano
2014-02-24 23:28 ` Duy Nguyen
2014-02-25 0:18 ` Junio C Hamano
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=1392521840-21628-4-git-send-email-pclouds@gmail.com \
--to=pclouds@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.