]> git.ipfire.org Git - thirdparty/git.git/blame - wt-status.c
wt-status: move many global settings to wt_status structure
[thirdparty/git.git] / wt-status.c
CommitLineData
85023577 1#include "cache.h"
c91f0d92
JK
2#include "wt-status.h"
3#include "color.h"
c91f0d92
JK
4#include "object.h"
5#include "dir.h"
6#include "commit.h"
7#include "diff.h"
8#include "revision.h"
9#include "diffcore.h"
a734d0b1 10#include "quote.h"
ac8d5afc 11#include "run-command.h"
b6975ab5 12#include "remote.h"
c91f0d92 13
c91f0d92 14static char wt_status_colors[][COLOR_MAXLEN] = {
dc6ebd4c
AL
15 GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
16 GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */
17 GIT_COLOR_RED, /* WT_STATUS_CHANGED */
18 GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */
19 GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */
4d4d5726 20 GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
c91f0d92 21};
4d229653 22
c91f0d92
JK
23static int parse_status_slot(const char *var, int offset)
24{
25 if (!strcasecmp(var+offset, "header"))
26 return WT_STATUS_HEADER;
82dca848
SP
27 if (!strcasecmp(var+offset, "updated")
28 || !strcasecmp(var+offset, "added"))
c91f0d92
JK
29 return WT_STATUS_UPDATED;
30 if (!strcasecmp(var+offset, "changed"))
31 return WT_STATUS_CHANGED;
32 if (!strcasecmp(var+offset, "untracked"))
33 return WT_STATUS_UNTRACKED;
950ce2e2
CP
34 if (!strcasecmp(var+offset, "nobranch"))
35 return WT_STATUS_NOBRANCH;
4d4d5726
JH
36 if (!strcasecmp(var+offset, "unmerged"))
37 return WT_STATUS_UNMERGED;
c91f0d92
JK
38 die("bad config variable '%s'", var);
39}
40
d249b098 41static const char *color(int slot, struct wt_status *s)
c91f0d92 42{
d249b098 43 return s->use_color > 0 ? wt_status_colors[slot] : "";
c91f0d92
JK
44}
45
46void wt_status_prepare(struct wt_status *s)
47{
48 unsigned char sha1[20];
49 const char *head;
50
cc46a743 51 memset(s, 0, sizeof(*s));
d249b098
JH
52 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
53 s->use_color = -1;
54 s->relative_paths = 1;
8da19775 55 head = resolve_ref("HEAD", sha1, 0, NULL);
f62363fb 56 s->branch = head ? xstrdup(head) : NULL;
c91f0d92 57 s->reference = "HEAD";
f26a0012 58 s->fp = stdout;
0f729f21 59 s->index_file = get_index_file();
50b7e70f 60 s->change.strdup_strings = 1;
c91f0d92
JK
61}
62
4d4d5726
JH
63static void wt_status_print_unmerged_header(struct wt_status *s)
64{
d249b098 65 const char *c = color(WT_STATUS_HEADER, s);
4d4d5726
JH
66 color_fprintf_ln(s->fp, c, "# Unmerged paths:");
67 if (!s->is_initial)
68 color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
69 else
70 color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
71 color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to mark resolution)");
72 color_fprintf_ln(s->fp, c, "#");
73}
74
f26a0012 75static void wt_status_print_cached_header(struct wt_status *s)
3c1eb9cb 76{
d249b098 77 const char *c = color(WT_STATUS_HEADER, s);
f26a0012 78 color_fprintf_ln(s->fp, c, "# Changes to be committed:");
ff58b9aa 79 if (!s->is_initial) {
f26a0012 80 color_fprintf_ln(s->fp, c, "# (use \"git reset %s <file>...\" to unstage)", s->reference);
3c1eb9cb 81 } else {
f26a0012 82 color_fprintf_ln(s->fp, c, "# (use \"git rm --cached <file>...\" to unstage)");
3c1eb9cb 83 }
f26a0012 84 color_fprintf_ln(s->fp, c, "#");
3c1eb9cb
JR
85}
86
bb914b14
AM
87static void wt_status_print_dirty_header(struct wt_status *s,
88 int has_deleted)
c91f0d92 89{
d249b098 90 const char *c = color(WT_STATUS_HEADER, s);
bb914b14
AM
91 color_fprintf_ln(s->fp, c, "# Changed but not updated:");
92 if (!has_deleted)
93 color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to update what will be committed)");
94 else
95 color_fprintf_ln(s->fp, c, "# (use \"git add/rm <file>...\" to update what will be committed)");
4d6e4c4d 96 color_fprintf_ln(s->fp, c, "# (use \"git checkout -- <file>...\" to discard changes in working directory)");
bb914b14
AM
97 color_fprintf_ln(s->fp, c, "#");
98}
99
100static void wt_status_print_untracked_header(struct wt_status *s)
101{
d249b098 102 const char *c = color(WT_STATUS_HEADER, s);
bb914b14
AM
103 color_fprintf_ln(s->fp, c, "# Untracked files:");
104 color_fprintf_ln(s->fp, c, "# (use \"git add <file>...\" to include in what will be committed)");
f26a0012 105 color_fprintf_ln(s->fp, c, "#");
c91f0d92
JK
106}
107
f26a0012 108static void wt_status_print_trailer(struct wt_status *s)
c91f0d92 109{
d249b098 110 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
c91f0d92
JK
111}
112
a734d0b1 113#define quote_path quote_path_relative
3a946802 114
4d4d5726
JH
115static void wt_status_print_unmerged_data(struct wt_status *s,
116 struct string_list_item *it)
117{
d249b098 118 const char *c = color(WT_STATUS_UNMERGED, s);
4d4d5726
JH
119 struct wt_status_change_data *d = it->util;
120 struct strbuf onebuf = STRBUF_INIT;
121 const char *one, *how = "bug";
122
123 one = quote_path(it->string, -1, &onebuf, s->prefix);
d249b098 124 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
4d4d5726
JH
125 switch (d->stagemask) {
126 case 1: how = "both deleted:"; break;
127 case 2: how = "added by us:"; break;
128 case 3: how = "deleted by them:"; break;
129 case 4: how = "added by them:"; break;
130 case 5: how = "deleted by us:"; break;
131 case 6: how = "both added:"; break;
132 case 7: how = "both modified:"; break;
133 }
134 color_fprintf(s->fp, c, "%-20s%s\n", how, one);
135 strbuf_release(&onebuf);
136}
137
50b7e70f
JH
138static void wt_status_print_change_data(struct wt_status *s,
139 int change_type,
140 struct string_list_item *it)
c91f0d92 141{
50b7e70f 142 struct wt_status_change_data *d = it->util;
d249b098 143 const char *c = color(change_type, s);
50b7e70f
JH
144 int status = status;
145 char *one_name;
146 char *two_name;
3a946802 147 const char *one, *two;
f285a2d7 148 struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
3a946802 149
50b7e70f
JH
150 one_name = two_name = it->string;
151 switch (change_type) {
152 case WT_STATUS_UPDATED:
153 status = d->index_status;
154 if (d->head_path)
155 one_name = d->head_path;
156 break;
157 case WT_STATUS_CHANGED:
158 status = d->worktree_status;
159 break;
160 }
161
162 one = quote_path(one_name, -1, &onebuf, s->prefix);
163 two = quote_path(two_name, -1, &twobuf, s->prefix);
3a946802 164
d249b098 165 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
50b7e70f 166 switch (status) {
c91f0d92 167 case DIFF_STATUS_ADDED:
f26a0012 168 color_fprintf(s->fp, c, "new file: %s", one);
3a946802 169 break;
c91f0d92 170 case DIFF_STATUS_COPIED:
f26a0012 171 color_fprintf(s->fp, c, "copied: %s -> %s", one, two);
c91f0d92
JK
172 break;
173 case DIFF_STATUS_DELETED:
f26a0012 174 color_fprintf(s->fp, c, "deleted: %s", one);
3a946802 175 break;
c91f0d92 176 case DIFF_STATUS_MODIFIED:
f26a0012 177 color_fprintf(s->fp, c, "modified: %s", one);
3a946802 178 break;
c91f0d92 179 case DIFF_STATUS_RENAMED:
f26a0012 180 color_fprintf(s->fp, c, "renamed: %s -> %s", one, two);
c91f0d92
JK
181 break;
182 case DIFF_STATUS_TYPE_CHANGED:
f26a0012 183 color_fprintf(s->fp, c, "typechange: %s", one);
3a946802 184 break;
c91f0d92 185 case DIFF_STATUS_UNKNOWN:
f26a0012 186 color_fprintf(s->fp, c, "unknown: %s", one);
3a946802 187 break;
c91f0d92 188 case DIFF_STATUS_UNMERGED:
f26a0012 189 color_fprintf(s->fp, c, "unmerged: %s", one);
3a946802 190 break;
c91f0d92 191 default:
50b7e70f 192 die("bug: unhandled diff status %c", status);
c91f0d92 193 }
f26a0012 194 fprintf(s->fp, "\n");
367c9886
JS
195 strbuf_release(&onebuf);
196 strbuf_release(&twobuf);
c91f0d92
JK
197}
198
50b7e70f
JH
199static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
200 struct diff_options *options,
201 void *data)
c91f0d92
JK
202{
203 struct wt_status *s = data;
c91f0d92 204 int i;
50b7e70f
JH
205
206 if (!q->nr)
207 return;
208 s->workdir_dirty = 1;
c91f0d92 209 for (i = 0; i < q->nr; i++) {
50b7e70f
JH
210 struct diff_filepair *p;
211 struct string_list_item *it;
212 struct wt_status_change_data *d;
213
214 p = q->queue[i];
215 it = string_list_insert(p->one->path, &s->change);
216 d = it->util;
217 if (!d) {
218 d = xcalloc(1, sizeof(*d));
219 it->util = d;
c91f0d92 220 }
50b7e70f
JH
221 if (!d->worktree_status)
222 d->worktree_status = p->status;
c91f0d92 223 }
c91f0d92
JK
224}
225
4d4d5726
JH
226static int unmerged_mask(const char *path)
227{
228 int pos, mask;
229 struct cache_entry *ce;
230
231 pos = cache_name_pos(path, strlen(path));
232 if (0 <= pos)
233 return 0;
234
235 mask = 0;
236 pos = -pos-1;
237 while (pos < active_nr) {
238 ce = active_cache[pos++];
239 if (strcmp(ce->name, path) || !ce_stage(ce))
240 break;
241 mask |= (1 << (ce_stage(ce) - 1));
242 }
243 return mask;
244}
245
50b7e70f
JH
246static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
247 struct diff_options *options,
248 void *data)
c91f0d92 249{
6e458bf6 250 struct wt_status *s = data;
c91f0d92 251 int i;
50b7e70f
JH
252
253 for (i = 0; i < q->nr; i++) {
254 struct diff_filepair *p;
255 struct string_list_item *it;
256 struct wt_status_change_data *d;
257
258 p = q->queue[i];
259 it = string_list_insert(p->two->path, &s->change);
260 d = it->util;
261 if (!d) {
262 d = xcalloc(1, sizeof(*d));
263 it->util = d;
264 }
265 if (!d->index_status)
266 d->index_status = p->status;
267 switch (p->status) {
268 case DIFF_STATUS_COPIED:
269 case DIFF_STATUS_RENAMED:
270 d->head_path = xstrdup(p->one->path);
271 break;
4d4d5726
JH
272 case DIFF_STATUS_UNMERGED:
273 d->stagemask = unmerged_mask(p->two->path);
274 break;
50b7e70f 275 }
6e458bf6 276 }
c91f0d92
JK
277}
278
50b7e70f 279static void wt_status_collect_changes_worktree(struct wt_status *s)
c91f0d92
JK
280{
281 struct rev_info rev;
50b7e70f
JH
282
283 init_revisions(&rev, NULL);
284 setup_revisions(0, NULL, &rev, NULL);
285 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
286 rev.diffopt.format_callback = wt_status_collect_changed_cb;
287 rev.diffopt.format_callback_data = s;
288 run_diff_files(&rev, 0);
289}
290
291static void wt_status_collect_changes_index(struct wt_status *s)
292{
293 struct rev_info rev;
294
c91f0d92 295 init_revisions(&rev, NULL);
c1e255b7
JK
296 setup_revisions(0, NULL, &rev,
297 s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
c91f0d92 298 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
50b7e70f 299 rev.diffopt.format_callback = wt_status_collect_updated_cb;
c91f0d92
JK
300 rev.diffopt.format_callback_data = s;
301 rev.diffopt.detect_rename = 1;
50705915 302 rev.diffopt.rename_limit = 200;
f714fb84 303 rev.diffopt.break_opt = 0;
c91f0d92
JK
304 run_diff_index(&rev, 1);
305}
306
50b7e70f
JH
307static void wt_status_collect_changes_initial(struct wt_status *s)
308{
309 int i;
310
311 for (i = 0; i < active_nr; i++) {
312 struct string_list_item *it;
313 struct wt_status_change_data *d;
314 struct cache_entry *ce = active_cache[i];
315
316 it = string_list_insert(ce->name, &s->change);
317 d = it->util;
318 if (!d) {
319 d = xcalloc(1, sizeof(*d));
320 it->util = d;
321 }
4d4d5726 322 if (ce_stage(ce)) {
50b7e70f 323 d->index_status = DIFF_STATUS_UNMERGED;
4d4d5726
JH
324 d->stagemask |= (1 << (ce_stage(ce) - 1));
325 }
50b7e70f
JH
326 else
327 d->index_status = DIFF_STATUS_ADDED;
328 }
329}
330
331void wt_status_collect_changes(struct wt_status *s)
332{
333 wt_status_collect_changes_worktree(s);
334
335 if (s->is_initial)
336 wt_status_collect_changes_initial(s);
337 else
338 wt_status_collect_changes_index(s);
339}
340
4d4d5726
JH
341static void wt_status_print_unmerged(struct wt_status *s)
342{
343 int shown_header = 0;
344 int i;
345
346 for (i = 0; i < s->change.nr; i++) {
347 struct wt_status_change_data *d;
348 struct string_list_item *it;
349 it = &(s->change.items[i]);
350 d = it->util;
351 if (!d->stagemask)
352 continue;
353 if (!shown_header) {
354 wt_status_print_unmerged_header(s);
355 shown_header = 1;
356 }
357 wt_status_print_unmerged_data(s, it);
358 }
359 if (shown_header)
360 wt_status_print_trailer(s);
361
362}
363
50b7e70f
JH
364static void wt_status_print_updated(struct wt_status *s)
365{
366 int shown_header = 0;
367 int i;
368
369 for (i = 0; i < s->change.nr; i++) {
370 struct wt_status_change_data *d;
371 struct string_list_item *it;
372 it = &(s->change.items[i]);
373 d = it->util;
374 if (!d->index_status ||
375 d->index_status == DIFF_STATUS_UNMERGED)
376 continue;
377 if (!shown_header) {
378 wt_status_print_cached_header(s);
379 s->commitable = 1;
380 shown_header = 1;
381 }
382 wt_status_print_change_data(s, WT_STATUS_UPDATED, it);
383 }
384 if (shown_header)
385 wt_status_print_trailer(s);
386}
387
388/*
389 * -1 : has delete
390 * 0 : no change
391 * 1 : some change but no delete
392 */
393static int wt_status_check_worktree_changes(struct wt_status *s)
394{
395 int i;
396 int changes = 0;
397
398 for (i = 0; i < s->change.nr; i++) {
399 struct wt_status_change_data *d;
400 d = s->change.items[i].util;
4d4d5726
JH
401 if (!d->worktree_status ||
402 d->worktree_status == DIFF_STATUS_UNMERGED)
50b7e70f
JH
403 continue;
404 changes = 1;
405 if (d->worktree_status == DIFF_STATUS_DELETED)
406 return -1;
407 }
408 return changes;
409}
410
c91f0d92
JK
411static void wt_status_print_changed(struct wt_status *s)
412{
50b7e70f
JH
413 int i;
414 int worktree_changes = wt_status_check_worktree_changes(s);
415
416 if (!worktree_changes)
417 return;
418
419 wt_status_print_dirty_header(s, worktree_changes < 0);
420
421 for (i = 0; i < s->change.nr; i++) {
422 struct wt_status_change_data *d;
423 struct string_list_item *it;
424 it = &(s->change.items[i]);
425 d = it->util;
4d4d5726
JH
426 if (!d->worktree_status ||
427 d->worktree_status == DIFF_STATUS_UNMERGED)
50b7e70f
JH
428 continue;
429 wt_status_print_change_data(s, WT_STATUS_CHANGED, it);
430 }
431 wt_status_print_trailer(s);
c91f0d92
JK
432}
433
ac8d5afc
PY
434static void wt_status_print_submodule_summary(struct wt_status *s)
435{
436 struct child_process sm_summary;
437 char summary_limit[64];
438 char index[PATH_MAX];
439 const char *env[] = { index, NULL };
440 const char *argv[] = {
441 "submodule",
442 "summary",
443 "--cached",
444 "--for-status",
445 "--summary-limit",
446 summary_limit,
447 s->amend ? "HEAD^" : "HEAD",
448 NULL
449 };
450
d249b098 451 sprintf(summary_limit, "%d", s->submodule_summary);
ac8d5afc
PY
452 snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
453
454 memset(&sm_summary, 0, sizeof(sm_summary));
455 sm_summary.argv = argv;
456 sm_summary.env = env;
457 sm_summary.git_cmd = 1;
458 sm_summary.no_stdin = 1;
459 fflush(s->fp);
460 sm_summary.out = dup(fileno(s->fp)); /* run_command closes it */
461 run_command(&sm_summary);
462}
463
6e458bf6 464static void wt_status_print_untracked(struct wt_status *s)
c91f0d92
JK
465{
466 struct dir_struct dir;
c91f0d92
JK
467 int i;
468 int shown_header = 0;
f285a2d7 469 struct strbuf buf = STRBUF_INIT;
c91f0d92
JK
470
471 memset(&dir, 0, sizeof(dir));
d249b098 472 if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
7c4c97c0
JS
473 dir.flags |=
474 DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
039bc64e 475 setup_standard_excludes(&dir);
c91f0d92 476
1d8842d9 477 fill_directory(&dir, NULL);
c91f0d92 478 for(i = 0; i < dir.nr; i++) {
c91f0d92 479 struct dir_entry *ent = dir.entries[i];
98fa4738
JK
480 if (!cache_name_is_other(ent->name, ent->len))
481 continue;
c91f0d92 482 if (!shown_header) {
2a3a3c24 483 s->workdir_untracked = 1;
bb914b14 484 wt_status_print_untracked_header(s);
c91f0d92
JK
485 shown_header = 1;
486 }
d249b098
JH
487 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "#\t");
488 color_fprintf_ln(s->fp, color(WT_STATUS_UNTRACKED, s), "%s",
367c9886
JS
489 quote_path(ent->name, ent->len,
490 &buf, s->prefix));
c91f0d92 491 }
367c9886 492 strbuf_release(&buf);
c91f0d92
JK
493}
494
495static void wt_status_print_verbose(struct wt_status *s)
496{
497 struct rev_info rev;
99a12694 498
c91f0d92 499 init_revisions(&rev, NULL);
5ec11af6 500 DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
1324fb6f
JK
501 setup_revisions(0, NULL, &rev,
502 s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference);
c91f0d92
JK
503 rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
504 rev.diffopt.detect_rename = 1;
4ba0cb27
KH
505 rev.diffopt.file = s->fp;
506 rev.diffopt.close_file = 0;
4f672ad6
JK
507 /*
508 * If we're not going to stdout, then we definitely don't
509 * want color, since we are going to the commit message
510 * file (and even the "auto" setting won't work, since it
511 * will have checked isatty on stdout).
512 */
513 if (s->fp != stdout)
514 DIFF_OPT_CLR(&rev.diffopt, COLOR_DIFF);
c91f0d92
JK
515 run_diff_index(&rev, 1);
516}
517
b6975ab5
JH
518static void wt_status_print_tracking(struct wt_status *s)
519{
520 struct strbuf sb = STRBUF_INIT;
521 const char *cp, *ep;
522 struct branch *branch;
523
524 assert(s->branch && !s->is_initial);
525 if (prefixcmp(s->branch, "refs/heads/"))
526 return;
527 branch = branch_get(s->branch + 11);
528 if (!format_tracking_info(branch, &sb))
529 return;
530
531 for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
d249b098 532 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
b6975ab5 533 "# %.*s", (int)(ep - cp), cp);
d249b098 534 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
b6975ab5
JH
535}
536
c91f0d92
JK
537void wt_status_print(struct wt_status *s)
538{
98bf8a47 539 unsigned char sha1[20];
d249b098 540 const char *branch_color = color(WT_STATUS_HEADER, s);
98bf8a47 541
950ce2e2 542 s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
bda324cf
JH
543 if (s->branch) {
544 const char *on_what = "On branch ";
545 const char *branch_name = s->branch;
cc44c765 546 if (!prefixcmp(branch_name, "refs/heads/"))
bda324cf
JH
547 branch_name += 11;
548 else if (!strcmp(branch_name, "HEAD")) {
549 branch_name = "";
d249b098 550 branch_color = color(WT_STATUS_NOBRANCH, s);
bda324cf
JH
551 on_what = "Not currently on any branch.";
552 }
d249b098 553 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "# ");
950ce2e2 554 color_fprintf_ln(s->fp, branch_color, "%s%s", on_what, branch_name);
b6975ab5
JH
555 if (!s->is_initial)
556 wt_status_print_tracking(s);
bda324cf 557 }
c91f0d92 558
50b7e70f
JH
559 wt_status_collect_changes(s);
560
c91f0d92 561 if (s->is_initial) {
d249b098
JH
562 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
563 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "# Initial commit");
564 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "#");
c91f0d92
JK
565 }
566
4d4d5726 567 wt_status_print_unmerged(s);
c1e255b7 568 wt_status_print_updated(s);
c91f0d92 569 wt_status_print_changed(s);
d249b098 570 if (s->submodule_summary)
ac8d5afc 571 wt_status_print_submodule_summary(s);
d249b098 572 if (s->show_untracked_files)
6c2ce048
MSO
573 wt_status_print_untracked(s);
574 else if (s->commitable)
575 fprintf(s->fp, "# Untracked files not listed (use -u option to show untracked files)\n");
c91f0d92 576
1324fb6f 577 if (s->verbose)
c91f0d92 578 wt_status_print_verbose(s);
6e458bf6
JR
579 if (!s->commitable) {
580 if (s->amend)
f26a0012 581 fprintf(s->fp, "# No changes\n");
37d07f8f
JH
582 else if (s->nowarn)
583 ; /* nothing */
2a3a3c24 584 else if (s->workdir_dirty)
dcbc7bbe 585 printf("no changes added to commit (use \"git add\" and/or \"git commit -a\")\n");
2a3a3c24
JR
586 else if (s->workdir_untracked)
587 printf("nothing added to commit but untracked files present (use \"git add\" to track)\n");
588 else if (s->is_initial)
589 printf("nothing to commit (create/copy files and use \"git add\" to track)\n");
d249b098 590 else if (!s->show_untracked_files)
6c2ce048 591 printf("nothing to commit (use -u to show untracked files)\n");
2a3a3c24
JR
592 else
593 printf("nothing to commit (working directory clean)\n");
6e458bf6 594 }
c91f0d92
JK
595}
596
ef90d6d4 597int git_status_config(const char *k, const char *v, void *cb)
c91f0d92 598{
d249b098
JH
599 struct wt_status *s = cb;
600
ac8d5afc
PY
601 if (!strcmp(k, "status.submodulesummary")) {
602 int is_bool;
d249b098
JH
603 s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
604 if (is_bool && s->submodule_summary)
605 s->submodule_summary = -1;
ac8d5afc
PY
606 return 0;
607 }
a159ca0c 608 if (!strcmp(k, "status.color") || !strcmp(k, "color.status")) {
d249b098 609 s->use_color = git_config_colorbool(k, v, -1);
c91f0d92
JK
610 return 0;
611 }
1968d77d 612 if (!prefixcmp(k, "status.color.") || !prefixcmp(k, "color.status.")) {
c91f0d92 613 int slot = parse_status_slot(k, 13);
451d36bb
JH
614 if (!v)
615 return config_error_nonbool(k);
c91f0d92 616 color_parse(v, k, wt_status_colors[slot]);
46f721c8
JK
617 return 0;
618 }
619 if (!strcmp(k, "status.relativepaths")) {
d249b098 620 s->relative_paths = git_config_bool(k, v);
46f721c8 621 return 0;
c91f0d92 622 }
d6293d1f
MSO
623 if (!strcmp(k, "status.showuntrackedfiles")) {
624 if (!v)
c96a6d36 625 return config_error_nonbool(k);
d6293d1f 626 else if (!strcmp(v, "no"))
d249b098 627 s->show_untracked_files = SHOW_NO_UNTRACKED_FILES;
d6293d1f 628 else if (!strcmp(v, "normal"))
d249b098 629 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
d6293d1f 630 else if (!strcmp(v, "all"))
d249b098 631 s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
d6293d1f
MSO
632 else
633 return error("Invalid untracked files mode '%s'", v);
634 return 0;
635 }
d249b098 636 return git_diff_ui_config(k, v, NULL);
c91f0d92 637}