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

[PATCH 9/9] commit: suppress status summary when no changes staged

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Jul 25, 2010, 01:02 UTC
Message-ID
<20100725010230.GI18420@burratino>
In-Reply-To
<20100725005443.GA18370@burratino>

Starting out, it can be unnerving that “git commit” spews out a list of changes instead of just making a commit when the user has forgotten to stage any changes.

So give some focused advice in that case, by suppressing the status summary so the existing message about the need to stage changes can be read more easily.

Example: before:
	$ git commit
	# On branch master
	# Changed but not updated:
	#   (use "git add <file>..." to update what will be committed)
	#   (use "git checkout -- <file>..." to discard changes in working directory)
	#
	#	modified:   dir1/modified
	#
	# Untracked files:
	#   (use "git add <file>..." to include in what will be committed)
	#
	#	actual
	#	dir1/untracked
	#	dir2/modified
	#	dir2/untracked
	#	expect
	#	output
	#	untracked
	no changes added to commit (use "git add" and/or "git commit -a")
	$
After:
	$ git commit
	no changes added to commit (use "git add" and/or "git commit -a")
	$
Cc: Jakub Narebski <jnareb@gmail.com>
Cc: Jeff King <peff@peff.net>
Cc: Thomas Rast <trast@student.ethz.ch>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
That’s the end of the series.  Thanks for reading.
 builtin/commit.c  |   10 +++++++++-
 t/t7508-status.sh |    7 ++++---
 wt-status.c       |    2 +-
 wt-status.h       |    1 +
 4 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 9a4ea34..a2588a9 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -96,7 +96,8 @@ static int null_termination;
 static enum {
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
-	STATUS_FORMAT_PORCELAIN
+	STATUS_FORMAT_PORCELAIN,
+	STATUS_FORMAT_NOCHANGES
 } status_format = STATUS_FORMAT_LONG;
 static int status_show_branch;
 
@@ -443,6 +444,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_LONG:
 		wt_status_print(s);
 		break;
+	case STATUS_FORMAT_NOCHANGES:
+		wt_status_print_nochanges(s);
+		break;
 	}
 
 	return s->commitable;
@@ -711,6 +715,8 @@ static int empty_commit_ok(const char *index_file, const char *prefix,
 	if (in_merge || allow_empty || (amend && is_a_merge(head_sha1)))
 		return 1;
 
+	if (status_format == STATUS_FORMAT_LONG)
+		status_format = STATUS_FORMAT_NOCHANGES;
 	run_status(stdout, index_file, prefix, 0, s);
 	if (amend)
 		fputs(empty_amend_advice, stderr);
@@ -1170,6 +1176,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		s.ignore_submodule_arg = ignore_submodule_arg;
 		wt_status_print(&s);
 		break;
+	case STATUS_FORMAT_NOCHANGES:
+		return error("unexpected status format");
 	}
 	return 0;
 }
diff --git a/t/t7508-status.sh b/t/t7508-status.sh
index 882e5d7..c41a54c 100755
--- a/t/t7508-status.sh
+++ b/t/t7508-status.sh
@@ -800,10 +800,11 @@ test_expect_success 'status submodule summary (clean submodule)' '
 	git commit -m "commit submodule" &&
 	git config status.submodulesummary 10 &&
 	test_when_finished "git config --unset status.submodulesummary" &&
-	test_must_fail git commit --dry-run >output &&
+	test_must_fail git commit --dry-run >actual &&
+	git status >output &&
 	test_cmp expect output &&
-	git status >output &&
-	test_cmp expect output
+	echo '\''no changes added to commit (use "git add" and/or "git commit -a")'\'' >expect &&
+	test_cmp expect actual
 '
 
 test_expect_success 'status -s submodule summary (clean submodule)' '
diff --git a/wt-status.c b/wt-status.c
index 90a0824..83d2ae2 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -612,7 +612,7 @@ static void wt_status_print_verbose(struct wt_status *s)
 	run_diff_index(&rev, 1);
 }
 
-static void wt_status_print_nochanges(struct wt_status *s)
+void wt_status_print_nochanges(struct wt_status *s)
 {
 	if (s->amend)
 		fprintf(s->fp, "# No changes\n");
diff --git a/wt-status.h b/wt-status.h
index 9df9c9f..1cee54b 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -65,5 +65,6 @@ void wt_status_collect(struct wt_status *s);
 
 void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch);
 void wt_porcelain_print(struct wt_status *s, int null_termination);
+void wt_status_print_nochanges(struct wt_status *s);
 
 #endif /* STATUS_H */
-- 
1.7.2.9.ge3789.dirty
Previous: Jonathan NiederNext: Thomas Rast
Message 11 of 38 in “commit: more focused advice in the no-changes-staged case”
  1. 0/9 commit: more focused advice in the no-changes-staged caseJonathan Nieder, Jul 25, 2010
  2. 1/9 wt-status: split wt_status_print into digestible piecesJonathan Nieder, Jul 25, 2010
  3. 2/9 wt-status: split off a function for printing submodule summaryJonathan Nieder, Jul 25, 2010
  4. 3/9 commit: split off a function to fetch the default log messageJonathan Nieder, Jul 25, 2010
  5. 4/9 commit: split commit -s handling into its own functionJonathan Nieder, Jul 25, 2010
  6. 5/9 commit: split off the piece that writes statusJonathan Nieder, Jul 25, 2010
  7. 6/9 t7508 (status): modernize styleJonathan Nieder, Jul 25, 2010
  8. Ævar Arnfjörð BjarmasonJul 25, 2010
  9. 7/9 commit: give empty-commit avoidance code its own functionJonathan Nieder, Jul 25, 2010
  10. 8/9 commit --dry-run: give advice on empty amendJonathan Nieder, Jul 25, 2010
  11. 9/9 commit: suppress status summary when no changes stagedJonathan Nieder, Jul 25, 2010
  12. Thomas RastAug 11, 2010
  13. Jonathan NiederAug 11, 2010
  14. t6040 (branch tracking): check “status” instead of “commit”Jonathan Nieder, Aug 11, 2010
  15. Ævar Arnfjörð BjarmasonAug 12, 2010
  16. Ævar Arnfjörð BjarmasonAug 11, 2010
  17. Jonathan NiederAug 11, 2010
  18. Ævar Arnfjörð BjarmasonAug 12, 2010
  19. Jonathan NiederAug 12, 2010
  20. Ævar Arnfjörð BjarmasonJul 25, 2010
  21. Thomas RastJul 25, 2010
  22. Making error messages stand out (Re: [RFC/PATCH 0/9] commit: more focused advice in the no-changes-staged case)Jonathan Nieder, Jul 29, 2010
  23. Sverre RabbelierJul 30, 2010
  24. 0/4 Re: Making error messages stand outJonathan Nieder, Aug 11, 2010
  25. 1/4 Eliminate “Finished cherry-pick/revert” messageJonathan Nieder, Aug 11, 2010
  26. 2/4 Introduce advise() to print hintsJonathan Nieder, Aug 11, 2010
  27. 3/4 cherry-pick/revert: Use error() for failure messageJonathan Nieder, Aug 11, 2010
  28. 4/4 cherry-pick/revert: Use advise() for hintsJonathan Nieder, Aug 11, 2010
  29. Nguyen Thai Ngoc DuyAug 11, 2010
  30. Matthieu MoyAug 11, 2010
  31. Nguyen Thai Ngoc DuyAug 11, 2010
  32. Sverre RabbelierAug 11, 2010
  33. tests: fix syntax error in "Use advise() for hints" testÆvar Arnfjörð Bjarmason, Aug 18, 2010
  34. Jonathan NiederAug 19, 2010
  35. Ævar Arnfjörð BjarmasonAug 19, 2010
  36. Raja R HarinathAug 20, 2010
  37. Ævar Arnfjörð BjarmasonAug 20, 2010
  38. Junio C HamanoAug 20, 2010

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.