Improve "nothing to commit" part of status output
Previously git-status in a clean working directory would advice the user to use git add. This isn't very helpful when there is nothing to add in the working directory, therefore note a clean working directory while displaying the other sections and print the appropriate message for each case. Signed-off-by: Jürgen Rühle <j-r@online.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jürgen Rühle committed
Jan 2, 2007 at 20:26 UTC
6e458bf63f48fb7d15cb70ad7c7b7b71915d94a2
2 files changed
+19
-6
wt-status.c
+18
-6
@@ -51,6 +51,8 @@ void wt_status_prepare(struct wt_status *s)
51
s->verbose = 0;
52
s->commitable = 0;
53
s->untracked = 0;
54
+
55
+ s->workdir_clean = 1;
56
}
57
58
static void wt_status_print_header(const char *main, const char *sub)
@@ -162,9 +164,12 @@ static void wt_status_print_changed_cb(struct diff_queue_struct *q,
164
struct diff_options *options,
165
void *data)
166
{
167
+ struct wt_status *s = data;
168
int i;
166
- if (q->nr)
169
+ if (q->nr) {
170
+ s->workdir_clean = 0;
171
wt_status_print_header("Changed but not added", use_add_msg);
172
+ }
173
for (i = 0; i < q->nr; i++)
174
wt_status_print_filepair(WT_STATUS_CHANGED, q->queue[i]);
175
if (q->nr)
@@ -215,7 +220,7 @@ static void wt_status_print_changed(struct wt_status *s)
220
run_diff_files(&rev, 0);
221
}
222
218
-static void wt_status_print_untracked(const struct wt_status *s)
223
+static void wt_status_print_untracked(struct wt_status *s)
224
{
225
struct dir_struct dir;
226
const char *x;
@@ -250,6 +255,7 @@ static void wt_status_print_untracked(const struct wt_status *s)
255
continue;
256
}
257
if (!shown_header) {
258
+ s->workdir_clean = 0;
259
wt_status_print_header("Untracked files", use_add_msg);
260
shown_header = 1;
261
}
@@ -291,10 +297,16 @@ void wt_status_print(struct wt_status *s)
297
298
if (s->verbose && !s->is_initial)
299
wt_status_print_verbose(s);
294
- if (!s->commitable)
295
- printf("%s (%s)\n",
296
- s->amend ? "# No changes" : "nothing to commit",
297
- use_add_msg);
300
+ if (!s->commitable) {
301
+ if (s->amend)
302
+ printf("# No changes\n");
303
+ else if (s->workdir_clean)
304
+ printf(s->is_initial
305
+ ? "nothing to commit\n"
306
+ : "nothing to commit (working directory matches HEAD)\n");
307
+ else
308
+ printf("no changes added to commit (use \"git add\" and/or \"git commit [-a|-i|-o]\")\n");
309
+ }
310
}
311
312
int git_status_config(const char *k, const char *v)
wt-status.h
+1
@@ -16,6 +16,7 @@ struct wt_status {
16
int verbose;
17
int amend;
18
int untracked;
19
+ int workdir_clean;
20
};
21
22
int git_status_config(const char *var, const char *value);