@matheusbsbs / matheus-bagliano / commits / 2a3a3c247e
Fork 0

Provide better feedback for the untracked only case in status output

Since 98bf8a47c296f51ea9722fef4bb81dbfb70cd4bb status would claim that git-commit could be useful even if there are no changes except untracked files. Since wt-status is already computing all the information needed go the whole way and actually track the (non-)emptiness of all three sections separately, unify the code, and provide useful messages for each individual case. Thanks to Junio and Michael Loeffler for suggestions. Signed-off-by: Jürgen Rühle <j-r@online.de>

Jürgen Rühle committed Jan 10, 2007 at 23:25 UTC 2a3a3c247e7f1f257e9c6762e48b98f08a30011a
2 files changed +16 -11
wt-status.c
+12 -9
@@ -47,10 +47,11 @@ void wt_status_prepare(struct wt_status *s)
47 s->reference = "HEAD";
48 s->amend = 0;
49 s->verbose = 0;
50 - s->commitable = 0;
50 s->untracked = 0;
51
53 - s->workdir_clean = 1;
52 + s->commitable = 0;
53 + s->workdir_dirty = 0;
54 + s->workdir_untracked = 0;
55 }
56
57 static void wt_status_print_cached_header(const char *reference)
@@ -176,7 +177,7 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
177 struct wt_status *s = data;
178 int i;
179 if (q->nr) {
179 - s->workdir_clean = 0;
180 + s->workdir_dirty = 1;
181 wt_status_print_header("Changed but not added", use_add_msg);
182 }
183 for (i = 0; i < q->nr; i++)
@@ -263,7 +264,7 @@ static void wt_status_print_untracked(struct wt_status *s)
264 continue;
265 }
266 if (!shown_header) {
266 - s->workdir_clean = 0;
267 + s->workdir_untracked = 1;
268 wt_status_print_header("Untracked files", use_add_msg);
269 shown_header = 1;
270 }
@@ -311,12 +312,14 @@ void wt_status_print(struct wt_status *s)
312 if (!s->commitable) {
313 if (s->amend)
314 printf("# No changes\n");
314 - else if (s->workdir_clean)
315 - printf(s->is_initial
316 - ? "nothing to commit\n"
317 - : "nothing to commit (working directory matches HEAD)\n");
318 - else
315 + else if (s->workdir_dirty)
316 printf("no changes added to commit (use \"git add\" and/or \"git commit [-a|-i|-o]\")\n");
317 + else if (s->workdir_untracked)
318 + printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
319 + else if (s->is_initial)
320 + printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
321 + else
322 + printf("nothing to commit (working directory clean)\n");
323 }
324 }
325
wt-status.h
+4 -2
@@ -12,11 +12,13 @@ struct wt_status {
12 int is_initial;
13 char *branch;
14 const char *reference;
15 - int commitable;
15 int verbose;
16 int amend;
17 int untracked;
19 - int workdir_clean;
18 + /* These are computed during processing of the individual sections */
19 + int commitable;
20 + int workdir_dirty;
21 + int workdir_untracked;
22 };
23
24 int git_status_config(const char *var, const char *value);