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

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Junio C Hamano
Date: Friday, January 5, 2007 - 10:57 pm

Junio C Hamano <junkio@cox.net> writes:


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;

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH 1/2] Suggest use of "git add file1 file2" when ..., Junio C Hamano, (Fri Jan 5, 10:57 pm)