git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/5] status: show "-v" diff even for initial commit

From
Jeff King <peff@peff.net>
Date
Nov 12, 2008, 08:23 UTC
Message-ID
<20081112082337.GC3751@coredump.intra.peff.net>
In-Reply-To
<20081112081609.GA3720@coredump.intra.peff.net>

Since we can use the same "diff against empty tree" trick as we do for the non-initial case, it is trivial to make this work.

Signed-off-by: Jeff King <peff@peff.net>
---
I ran across this while writing my test cases for the later patches. I
don't see any reason why it shouldn't behave this way, and I suspect the
reason was just that the original author saw how we did
"wt_status_print_initial" and didn't want to have to do the equivalent
for generating diff output.
 t/t7507-commit-verbose.sh |   29 +++++++++++++++++++++++++++++
 wt-status.c               |    5 +++--
 2 files changed, 32 insertions(+), 2 deletions(-)
 create mode 100755 t/t7507-commit-verbose.sh
diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh
new file mode 100755
index 0000000..94b12e9
--- /dev/null
+++ b/t/t7507-commit-verbose.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+test_description='verbose commit template'
+. ./test-lib.sh
+
+cat >check-for-diff <<EOF
+#!$SHELL_PATH
+exec grep '^diff --git' "\$1"
+EOF
+chmod +x check-for-diff
+test_set_editor "$PWD/check-for-diff"
+
+cat >message <<'EOF'
+subject
+
+body
+EOF
+
+test_expect_success 'setup' '
+	echo content >file &&
+	git add file &&
+	git commit -F message
+'
+
+test_expect_success 'initial commit shows verbose diff' '
+	git commit --amend -v
+'
+
+test_done
diff --git a/wt-status.c b/wt-status.c
index c78588e..3edae43 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -279,7 +279,8 @@ static void wt_status_print_verbose(struct wt_status *s)
 	struct rev_info rev;
 
 	init_revisions(&rev, NULL);
-	setup_revisions(0, NULL, &rev, s->reference);
+	setup_revisions(0, NULL, &rev,
+		s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
 	rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
 	rev.diffopt.detect_rename = 1;
 	DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
@@ -352,7 +353,7 @@ void wt_status_print(struct wt_status *s)
 	else if (s->commitable)
 		 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
 
-	if (s->verbose && !s->is_initial)
+	if (s->verbose)
 		wt_status_print_verbose(s);
 	if (!s->commitable) {
 		if (s->amend)
-- 
1.6.0.4.883.g4593ee.dirty
Previous: Jeff KingNext: Jeff King
Message 13 of 22 in “git commit -v does not removes the patch”
  1. Santi BéjarNov 10, 2008
  2. Jeff KingNov 10, 2008
  3. Santi BéjarNov 10, 2008
  4. Junio C HamanoNov 10, 2008
  5. Jeff KingNov 11, 2008
  6. Santi BéjarNov 11, 2008
  7. Jeff KingNov 11, 2008
  8. Santi BéjarNov 11, 2008
  9. Junio C HamanoNov 11, 2008
  10. Jeff KingNov 12, 2008
  11. 1/5 define empty tree sha1 as a macroJeff King, Nov 12, 2008
  12. 2/5 wt-status: refactor initial commit printingJeff King, Nov 12, 2008
  13. 3/5 status: show "-v" diff even for initial commitJeff King, Nov 12, 2008
  14. 4/5 commit: loosen pattern for matching "-v" diffJeff King, Nov 12, 2008
  15. 5/5 commit: only strip diff from message in verbose modeJeff King, Nov 12, 2008
  16. Jeff KingNov 12, 2008
  17. Junio C HamanoNov 13, 2008
  18. SZEDER GáborNov 20, 2008
  19. Jeff KingNov 20, 2008
  20. SZEDER GáborNov 22, 2008
  21. Jeff KingNov 22, 2008
  22. Junio C HamanoNov 22, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.