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@xxxxxxxxx> --- Changed since v1: adopted peff's suggestion in 20140224083312.GB32594@xxxxxxxxxxxxxxxxxxxxx, 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 -- 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