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

Re: [PATCH 1/2] Suggest use of "git add file1 file2" when there is nothing to commit.

From
Junio C Hamano <junkio@cox.net>
Date
Jan 6, 2007, 05:57 UTC
Message-ID
<7vodpcae9s.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<7virfldryw.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano <junkio@cox.net> writes:
Show 24 quoted lines
> Michael Loeffler <zvpunry@zvpunry.de> writes:
>
>> Am Freitag, den 15.12.2006, 21:53 -0500 schrieb Shawn O. Pearce:
>> ...
>>> +		printf("%s (%s)\n",
>>> +			s->amend ? "# No changes" : "nothing to commit",
>>> +			use_add_msg);
>>>  }
>> I don't like the new 'nothing to commit (use "git add ... message")'
>> message. I use git status very often to see if there is something to
>> commit, but now there is always this annoying "use git add ..." message.
>
> I tend to not like _ANY_ change at all, but I've learned to wait
> and see if I get used to it when I see something that annoys me
> initially, to see if the annoyance is because what it does is
> truly wrong or it is because what it does is merely different
> from what I am used to.
>
> So I've been trying it out myself as one of the guinea pigs on
> this one as well.
>
> So far, my judgement is that this is of the better kind; it is
> easy to get used to, and once you get used to it, it is easily
> ignorable.
How about doing this?

-- >8 -- git-status: squelch "use 'git add file...'" message when unneeded

Add a field in wt_status to record if there are any uncached changes, and use it to decide when there is no point to add the "use 'git add'" message.

---
diff --git a/wt-status.c b/wt-status.c
index db42738..1037c94 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -15,7 +15,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {
 	"\033[31m", /* WT_STATUS_CHANGED: red */
 	"\033[31m", /* WT_STATUS_UNTRACKED: red */
 };
-static const char* use_add_msg = "use \"git add file1 file2\" to include for commit";
+static const char* use_add_msg = "use \"git add file...\" to include for commit";
 
 static int parse_status_slot(const char *var, int offset)
 {
@@ -162,13 +162,17 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
                         struct diff_options *options,
                         void *data)
 {
+	struct wt_status *s = (struct wt_status *)data;
 	int i;
-	if (q->nr)
-		wt_status_print_header("Changed but not added", use_add_msg);
+
+	s->modified = q->nr;
+	if (!q->nr)
+		return;
+
+	wt_status_print_header("Changed but not added", use_add_msg);
 	for (i = 0; i < q->nr; i++)
 		wt_status_print_filepair(WT_STATUS_CHANGED, q->queue[i]);
-	if (q->nr)
-		wt_status_print_trailer();
+	wt_status_print_trailer();
 }
 
 void wt_status_print_initial(struct wt_status *s)
@@ -291,10 +295,14 @@ void wt_status_print(struct wt_status *s)
 
 	if (s->verbose && !s->is_initial)
 		wt_status_print_verbose(s);
-	if (!s->commitable)
-		printf("%s (%s)\n",
-			s->amend ? "# No changes" : "nothing to commit",
-			use_add_msg);
+	if (!s->commitable) {
+		const char *msg =
+			s->amend ? "# No changes" : "nothing to commit";
+		if (s->modified)
+			printf("%s (%s)\n", msg, use_add_msg);
+		else
+			printf("%s\n", msg);
+	}
 }
 
 int git_status_config(const char *k, const char *v)
diff --git a/wt-status.h b/wt-status.h
index 0a5a5b7..72df1b3 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -13,6 +13,7 @@ struct wt_status {
 	char *branch;
 	const char *reference;
 	int commitable;
+	int modified;
 	int verbose;
 	int amend;
 	int untracked;
Previous: Junio C HamanoNext: Juergen Ruehle
Message 4 of 26 in “Suggest use of "git add file1 file2" when there is nothing to commit.”
  1. 1/2 Suggest use of "git add file1 file2" when there is nothing to commit.Shawn O. Pearce, Dec 16, 2006
  2. Michael LoefflerJan 5, 2007
  3. Junio C HamanoJan 5, 2007
  4. Junio C HamanoJan 6, 2007
  5. Juergen RuehleJan 6, 2007
  6. Junio C HamanoJan 6, 2007
  7. Juergen RuehleJan 6, 2007
  8. Junio C HamanoJan 8, 2007
  9. Juergen RuehleJan 8, 2007
  10. Junio C HamanoJan 8, 2007
  11. Provide better feedback for the untracked only case in status outputJuergen Ruehle, Jan 10, 2007
  12. Juergen RuehleJan 10, 2007
  13. Juergen RuehleJan 10, 2007
  14. Junio C HamanoJan 10, 2007
  15. Juergen RuehleJan 10, 2007
  16. Quick hack to avoid double qp encodingJuergen Ruehle, Jan 10, 2007
  17. Juergen RuehleJan 10, 2007
  18. Junio C HamanoJan 10, 2007
  19. Michael LoefflerJan 10, 2007
  20. Juergen RuehleJan 10, 2007
  21. Provide better feedback for the untracked only case in status outputJuergen Ruehle, Jan 10, 2007
  22. Jeff KingJan 10, 2007
  23. Juergen RuehleJan 11, 2007
  24. Juergen RuehleJan 6, 2007
  25. Michael LoefflerJan 8, 2007
  26. Juergen RuehleJan 9, 2007

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.