git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tay Ray Chuan <rctay89@gmail.com>
To: "Git Mailing List" <git@vger.kernel.org>
Cc: "Junio C Hamano" <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: [PATCH v2 2/2] make commit --verbose work with --no-status
Date: Fri,  5 Jun 2015 01:56:31 +0800	[thread overview]
Message-ID: <1433440591-30917-3-git-send-email-rctay89@gmail.com> (raw)
In-Reply-To: <1433440591-30917-2-git-send-email-rctay89@gmail.com>

When running git-commit`, --verbose appends a diff to the prepared
message, while --no-status omits git-status output; thus, one would
expect --verbose --no-status to give a commit message with a diff of
the commit without git-status output.

However, this is not what happens - the prepared commit message body is
empty, entirely. (Needless to say, no diff is appended.) This is because
internally the git-status machinery is used to provide both the diff and
status output, but this machinery is skipped over entirely due to
--no-status.

We introduce a new status_format, STATUS_FORMAT_DIFFONLY, which triggers
the setting of the commitable flag, and the printing of the diff. This
is set only by git-commit, and when it detects that --verbose and
--no-status have been used.

Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
---

Changed since v1: adopted peff's suggestion in
20140224083312.GB32594@sigill.intra.peff.net, added tests.

 builtin/commit.c          | 12 +++++++++++-
 t/t7507-commit-verbose.sh | 34 +++++++++++++++++++++++++++++++++-
 wt-status.c               |  2 +-
 wt-status.h               |  3 +++
 4 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 254477f..d752899 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -144,6 +144,7 @@ static enum status_format {
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
 	STATUS_FORMAT_PORCELAIN,
+	STATUS_FORMAT_DIFFONLY,
 
 	STATUS_FORMAT_UNSPECIFIED
 } status_format = STATUS_FORMAT_UNSPECIFIED;
@@ -510,6 +511,10 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_UNSPECIFIED:
 		die("BUG: finalize_deferred_config() should have been called");
 		break;
+	case STATUS_FORMAT_DIFFONLY:
+		wt_status_mark_commitable(s);
+		wt_status_print_verbose(s);
+		break;
 	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		wt_status_print(s);
@@ -1213,7 +1218,12 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (all && argc > 0)
 		die(_("Paths with -a does not make sense."));
 
-	if (status_format != STATUS_FORMAT_NONE)
+	if (status_format == STATUS_FORMAT_NONE) {
+		if (verbose && !include_status) {
+			include_status = 1;
+			status_format = STATUS_FORMAT_DIFFONLY;
+		}
+	} else
 		dry_run = 1;
 
 	return argc;
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
index 2ddf28c..9027dd4 100755
--- a/t/t7507-commit-verbose.sh
+++ b/t/t7507-commit-verbose.sh
@@ -26,7 +26,39 @@ test_expect_success 'initial commit shows verbose diff' '
 	git commit --amend -v
 '
 
-test_expect_success 'second commit' '
+test_expect_success '--verbose appends diff' '
+	cat >expected <<-\EOF &&
+	# ------------------------ >8 ------------------------
+	# Do not touch the line above.
+	# Everything below will be removed.
+	diff --git a/file b/file
+	index d95f3ad..94ab063 100644
+	--- a/file
+	+++ b/file
+	@@ -1 +1,2 @@
+	 content
+	+content content
+	EOF
+	cat >editor <<-\EOF &&
+	#!/bin/sh
+	awk "/^# -+ >8 -+$/ { p=1 } p" "$1" >actual
+	echo commit > "$1"
+	EOF
+	chmod 755 editor &&
+	echo content content >> file &&
+	git add file &&
+	test_tick &&
+	EDITOR=./editor git commit --verbose &&
+	test_cmp expected actual
+'
+
+test_expect_success '--verbose --no-status appends diff' '
+	git reset --soft HEAD^ &&
+	EDITOR=./editor git commit --verbose --no-status &&
+	test_cmp expected actual
+'
+
+test_expect_success 'commit' '
 	echo content modified >file &&
 	git add file &&
 	git commit -F message
diff --git a/wt-status.c b/wt-status.c
index 87550ae..c4f7e48 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -857,7 +857,7 @@ void wt_status_add_cut_line(FILE *fp)
 	strbuf_release(&buf);
 }
 
-static void wt_status_print_verbose(struct wt_status *s)
+void wt_status_print_verbose(struct wt_status *s)
 {
 	struct rev_info rev;
 	struct setup_revision_opt opt;
diff --git a/wt-status.h b/wt-status.h
index e0a99f7..4388296 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -98,8 +98,11 @@ void wt_status_add_cut_line(FILE *fp);
 void wt_status_prepare(struct wt_status *s);
 void wt_status_print(struct wt_status *s);
 void wt_status_collect(struct wt_status *s);
+void wt_status_mark_commitable(struct wt_status *state);
 void wt_status_get_state(struct wt_status_state *state, int get_detached_from);
 
+void wt_status_print_verbose(struct wt_status *s);
+
 void wt_shortstatus_print(struct wt_status *s);
 void wt_porcelain_print(struct wt_status *s);
 
-- 
2.0.0.581.g64f2558

  reply	other threads:[~2015-06-04 17:57 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-04 17:56 [PATCH v2 0/2] make commit --verbose work with --no-status Tay Ray Chuan
2015-06-04 17:56 ` [PATCH v2 1/2] extract setting of wt_status.commitable flag out of wt_status_print_updated() Tay Ray Chuan
2015-06-04 17:56   ` Tay Ray Chuan [this message]
2015-06-04 21:34   ` Junio C Hamano
2015-06-04 18:39 ` [PATCH v2 0/2] make commit --verbose work with --no-status Junio C Hamano
2015-06-05 12:40   ` Tay Ray Chuan
2015-06-05 16:03     ` Junio C Hamano
2015-06-05 16:48       ` Tay Ray Chuan
2015-06-05 17:13         ` 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=1433440591-30917-3-git-send-email-rctay89@gmail.com \
    --to=rctay89@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /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).