10 #include "run-command.h"
13 #include "submodule.h"
15 static char default_wt_status_colors
[][COLOR_MAXLEN
] = {
16 GIT_COLOR_NORMAL
, /* WT_STATUS_HEADER */
17 GIT_COLOR_GREEN
, /* WT_STATUS_UPDATED */
18 GIT_COLOR_RED
, /* WT_STATUS_CHANGED */
19 GIT_COLOR_RED
, /* WT_STATUS_UNTRACKED */
20 GIT_COLOR_RED
, /* WT_STATUS_NOBRANCH */
21 GIT_COLOR_RED
, /* WT_STATUS_UNMERGED */
22 GIT_COLOR_GREEN
, /* WT_STATUS_LOCAL_BRANCH */
23 GIT_COLOR_RED
, /* WT_STATUS_REMOTE_BRANCH */
24 GIT_COLOR_NIL
, /* WT_STATUS_ONBRANCH */
27 static const char *color(int slot
, struct wt_status
*s
)
30 if (want_color(s
->use_color
))
31 c
= s
->color_palette
[slot
];
32 if (slot
== WT_STATUS_ONBRANCH
&& color_is_nil(c
))
33 c
= s
->color_palette
[WT_STATUS_HEADER
];
37 static void status_vprintf(struct wt_status
*s
, int at_bol
, const char *color
,
38 const char *fmt
, va_list ap
, const char *trail
)
40 struct strbuf sb
= STRBUF_INIT
;
41 struct strbuf linebuf
= STRBUF_INIT
;
42 const char *line
, *eol
;
44 strbuf_vaddf(&sb
, fmt
, ap
);
46 strbuf_addch(&sb
, '#');
48 strbuf_addch(&sb
, ' ');
49 color_print_strbuf(s
->fp
, color
, &sb
);
51 fprintf(s
->fp
, "%s", trail
);
55 for (line
= sb
.buf
; *line
; line
= eol
+ 1) {
56 eol
= strchr(line
, '\n');
58 strbuf_reset(&linebuf
);
60 strbuf_addch(&linebuf
, '#');
61 if (*line
!= '\n' && *line
!= '\t')
62 strbuf_addch(&linebuf
, ' ');
65 strbuf_add(&linebuf
, line
, eol
- line
);
67 strbuf_addstr(&linebuf
, line
);
68 color_print_strbuf(s
->fp
, color
, &linebuf
);
76 fprintf(s
->fp
, "%s", trail
);
77 strbuf_release(&linebuf
);
81 void status_printf_ln(struct wt_status
*s
, const char *color
,
87 status_vprintf(s
, 1, color
, fmt
, ap
, "\n");
91 void status_printf(struct wt_status
*s
, const char *color
,
97 status_vprintf(s
, 1, color
, fmt
, ap
, NULL
);
101 void status_printf_more(struct wt_status
*s
, const char *color
,
102 const char *fmt
, ...)
107 status_vprintf(s
, 0, color
, fmt
, ap
, NULL
);
111 void wt_status_prepare(struct wt_status
*s
)
113 unsigned char sha1
[20];
116 memset(s
, 0, sizeof(*s
));
117 memcpy(s
->color_palette
, default_wt_status_colors
,
118 sizeof(default_wt_status_colors
));
119 s
->show_untracked_files
= SHOW_NORMAL_UNTRACKED_FILES
;
121 s
->relative_paths
= 1;
122 head
= resolve_ref("HEAD", sha1
, 0, NULL
);
123 s
->branch
= head
? xstrdup(head
) : NULL
;
124 s
->reference
= "HEAD";
126 s
->index_file
= get_index_file();
127 s
->change
.strdup_strings
= 1;
128 s
->untracked
.strdup_strings
= 1;
129 s
->ignored
.strdup_strings
= 1;
132 static void wt_status_print_unmerged_header(struct wt_status
*s
)
134 const char *c
= color(WT_STATUS_HEADER
, s
);
136 status_printf_ln(s
, c
, _("Unmerged paths:"));
137 if (!advice_status_hints
)
139 if (s
->whence
!= FROM_COMMIT
)
141 else if (!s
->is_initial
)
142 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
144 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
145 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
146 status_printf_ln(s
, c
, "");
149 static void wt_status_print_cached_header(struct wt_status
*s
)
151 const char *c
= color(WT_STATUS_HEADER
, s
);
153 status_printf_ln(s
, c
, _("Changes to be committed:"));
154 if (!advice_status_hints
)
156 if (s
->whence
!= FROM_COMMIT
)
157 ; /* NEEDSWORK: use "git reset --unresolve"??? */
158 else if (!s
->is_initial
)
159 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
161 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
162 status_printf_ln(s
, c
, "");
165 static void wt_status_print_dirty_header(struct wt_status
*s
,
167 int has_dirty_submodules
)
169 const char *c
= color(WT_STATUS_HEADER
, s
);
171 status_printf_ln(s
, c
, _("Changes not staged for commit:"));
172 if (!advice_status_hints
)
175 status_printf_ln(s
, c
, _(" (use \"git add <file>...\" to update what will be committed)"));
177 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" to update what will be committed)"));
178 status_printf_ln(s
, c
, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)"));
179 if (has_dirty_submodules
)
180 status_printf_ln(s
, c
, _(" (commit or discard the untracked or modified content in submodules)"));
181 status_printf_ln(s
, c
, "");
184 static void wt_status_print_other_header(struct wt_status
*s
,
188 const char *c
= color(WT_STATUS_HEADER
, s
);
189 status_printf_ln(s
, c
, _("%s files:"), what
);
190 if (!advice_status_hints
)
192 status_printf_ln(s
, c
, _(" (use \"git %s <file>...\" to include in what will be committed)"), how
);
193 status_printf_ln(s
, c
, "");
196 static void wt_status_print_trailer(struct wt_status
*s
)
198 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
201 #define quote_path quote_path_relative
203 static void wt_status_print_unmerged_data(struct wt_status
*s
,
204 struct string_list_item
*it
)
206 const char *c
= color(WT_STATUS_UNMERGED
, s
);
207 struct wt_status_change_data
*d
= it
->util
;
208 struct strbuf onebuf
= STRBUF_INIT
;
209 const char *one
, *how
= _("bug");
211 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
212 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
213 switch (d
->stagemask
) {
214 case 1: how
= _("both deleted:"); break;
215 case 2: how
= _("added by us:"); break;
216 case 3: how
= _("deleted by them:"); break;
217 case 4: how
= _("added by them:"); break;
218 case 5: how
= _("deleted by us:"); break;
219 case 6: how
= _("both added:"); break;
220 case 7: how
= _("both modified:"); break;
222 status_printf_more(s
, c
, "%-20s%s\n", how
, one
);
223 strbuf_release(&onebuf
);
226 static void wt_status_print_change_data(struct wt_status
*s
,
228 struct string_list_item
*it
)
230 struct wt_status_change_data
*d
= it
->util
;
231 const char *c
= color(change_type
, s
);
235 const char *one
, *two
;
236 struct strbuf onebuf
= STRBUF_INIT
, twobuf
= STRBUF_INIT
;
237 struct strbuf extra
= STRBUF_INIT
;
239 one_name
= two_name
= it
->string
;
240 switch (change_type
) {
241 case WT_STATUS_UPDATED
:
242 status
= d
->index_status
;
244 one_name
= d
->head_path
;
246 case WT_STATUS_CHANGED
:
247 if (d
->new_submodule_commits
|| d
->dirty_submodule
) {
248 strbuf_addstr(&extra
, " (");
249 if (d
->new_submodule_commits
)
250 strbuf_addf(&extra
, _("new commits, "));
251 if (d
->dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
252 strbuf_addf(&extra
, _("modified content, "));
253 if (d
->dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
)
254 strbuf_addf(&extra
, _("untracked content, "));
255 strbuf_setlen(&extra
, extra
.len
- 2);
256 strbuf_addch(&extra
, ')');
258 status
= d
->worktree_status
;
262 one
= quote_path(one_name
, -1, &onebuf
, s
->prefix
);
263 two
= quote_path(two_name
, -1, &twobuf
, s
->prefix
);
265 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
267 case DIFF_STATUS_ADDED
:
268 status_printf_more(s
, c
, _("new file: %s"), one
);
270 case DIFF_STATUS_COPIED
:
271 status_printf_more(s
, c
, _("copied: %s -> %s"), one
, two
);
273 case DIFF_STATUS_DELETED
:
274 status_printf_more(s
, c
, _("deleted: %s"), one
);
276 case DIFF_STATUS_MODIFIED
:
277 status_printf_more(s
, c
, _("modified: %s"), one
);
279 case DIFF_STATUS_RENAMED
:
280 status_printf_more(s
, c
, _("renamed: %s -> %s"), one
, two
);
282 case DIFF_STATUS_TYPE_CHANGED
:
283 status_printf_more(s
, c
, _("typechange: %s"), one
);
285 case DIFF_STATUS_UNKNOWN
:
286 status_printf_more(s
, c
, _("unknown: %s"), one
);
288 case DIFF_STATUS_UNMERGED
:
289 status_printf_more(s
, c
, _("unmerged: %s"), one
);
292 die(_("bug: unhandled diff status %c"), status
);
295 status_printf_more(s
, color(WT_STATUS_HEADER
, s
), "%s", extra
.buf
);
296 strbuf_release(&extra
);
298 status_printf_more(s
, GIT_COLOR_NORMAL
, "\n");
299 strbuf_release(&onebuf
);
300 strbuf_release(&twobuf
);
303 static void wt_status_collect_changed_cb(struct diff_queue_struct
*q
,
304 struct diff_options
*options
,
307 struct wt_status
*s
= data
;
312 s
->workdir_dirty
= 1;
313 for (i
= 0; i
< q
->nr
; i
++) {
314 struct diff_filepair
*p
;
315 struct string_list_item
*it
;
316 struct wt_status_change_data
*d
;
319 it
= string_list_insert(&s
->change
, p
->one
->path
);
322 d
= xcalloc(1, sizeof(*d
));
325 if (!d
->worktree_status
)
326 d
->worktree_status
= p
->status
;
327 d
->dirty_submodule
= p
->two
->dirty_submodule
;
328 if (S_ISGITLINK(p
->two
->mode
))
329 d
->new_submodule_commits
= !!hashcmp(p
->one
->sha1
, p
->two
->sha1
);
333 static int unmerged_mask(const char *path
)
336 struct cache_entry
*ce
;
338 pos
= cache_name_pos(path
, strlen(path
));
344 while (pos
< active_nr
) {
345 ce
= active_cache
[pos
++];
346 if (strcmp(ce
->name
, path
) || !ce_stage(ce
))
348 mask
|= (1 << (ce_stage(ce
) - 1));
353 static void wt_status_collect_updated_cb(struct diff_queue_struct
*q
,
354 struct diff_options
*options
,
357 struct wt_status
*s
= data
;
360 for (i
= 0; i
< q
->nr
; i
++) {
361 struct diff_filepair
*p
;
362 struct string_list_item
*it
;
363 struct wt_status_change_data
*d
;
366 it
= string_list_insert(&s
->change
, p
->two
->path
);
369 d
= xcalloc(1, sizeof(*d
));
372 if (!d
->index_status
)
373 d
->index_status
= p
->status
;
375 case DIFF_STATUS_COPIED
:
376 case DIFF_STATUS_RENAMED
:
377 d
->head_path
= xstrdup(p
->one
->path
);
379 case DIFF_STATUS_UNMERGED
:
380 d
->stagemask
= unmerged_mask(p
->two
->path
);
386 static void wt_status_collect_changes_worktree(struct wt_status
*s
)
390 init_revisions(&rev
, NULL
);
391 setup_revisions(0, NULL
, &rev
, NULL
);
392 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
393 DIFF_OPT_SET(&rev
.diffopt
, DIRTY_SUBMODULES
);
394 if (!s
->show_untracked_files
)
395 DIFF_OPT_SET(&rev
.diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
396 if (s
->ignore_submodule_arg
) {
397 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
398 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
400 rev
.diffopt
.format_callback
= wt_status_collect_changed_cb
;
401 rev
.diffopt
.format_callback_data
= s
;
402 init_pathspec(&rev
.prune_data
, s
->pathspec
);
403 run_diff_files(&rev
, 0);
406 static void wt_status_collect_changes_index(struct wt_status
*s
)
409 struct setup_revision_opt opt
;
411 init_revisions(&rev
, NULL
);
412 memset(&opt
, 0, sizeof(opt
));
413 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
414 setup_revisions(0, NULL
, &rev
, &opt
);
416 if (s
->ignore_submodule_arg
) {
417 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
418 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
421 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
422 rev
.diffopt
.format_callback
= wt_status_collect_updated_cb
;
423 rev
.diffopt
.format_callback_data
= s
;
424 rev
.diffopt
.detect_rename
= 1;
425 rev
.diffopt
.rename_limit
= 200;
426 rev
.diffopt
.break_opt
= 0;
427 init_pathspec(&rev
.prune_data
, s
->pathspec
);
428 run_diff_index(&rev
, 1);
431 static void wt_status_collect_changes_initial(struct wt_status
*s
)
433 struct pathspec pathspec
;
436 init_pathspec(&pathspec
, s
->pathspec
);
437 for (i
= 0; i
< active_nr
; i
++) {
438 struct string_list_item
*it
;
439 struct wt_status_change_data
*d
;
440 struct cache_entry
*ce
= active_cache
[i
];
442 if (!ce_path_match(ce
, &pathspec
))
444 it
= string_list_insert(&s
->change
, ce
->name
);
447 d
= xcalloc(1, sizeof(*d
));
451 d
->index_status
= DIFF_STATUS_UNMERGED
;
452 d
->stagemask
|= (1 << (ce_stage(ce
) - 1));
455 d
->index_status
= DIFF_STATUS_ADDED
;
457 free_pathspec(&pathspec
);
460 static void wt_status_collect_untracked(struct wt_status
*s
)
463 struct dir_struct dir
;
465 if (!s
->show_untracked_files
)
467 memset(&dir
, 0, sizeof(dir
));
468 if (s
->show_untracked_files
!= SHOW_ALL_UNTRACKED_FILES
)
470 DIR_SHOW_OTHER_DIRECTORIES
| DIR_HIDE_EMPTY_DIRECTORIES
;
471 setup_standard_excludes(&dir
);
473 fill_directory(&dir
, s
->pathspec
);
474 for (i
= 0; i
< dir
.nr
; i
++) {
475 struct dir_entry
*ent
= dir
.entries
[i
];
476 if (cache_name_is_other(ent
->name
, ent
->len
) &&
477 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
478 string_list_insert(&s
->untracked
, ent
->name
);
482 if (s
->show_ignored_files
) {
484 dir
.flags
= DIR_SHOW_IGNORED
| DIR_SHOW_OTHER_DIRECTORIES
;
485 fill_directory(&dir
, s
->pathspec
);
486 for (i
= 0; i
< dir
.nr
; i
++) {
487 struct dir_entry
*ent
= dir
.entries
[i
];
488 if (cache_name_is_other(ent
->name
, ent
->len
) &&
489 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
490 string_list_insert(&s
->ignored
, ent
->name
);
498 void wt_status_collect(struct wt_status
*s
)
500 wt_status_collect_changes_worktree(s
);
503 wt_status_collect_changes_initial(s
);
505 wt_status_collect_changes_index(s
);
506 wt_status_collect_untracked(s
);
509 static void wt_status_print_unmerged(struct wt_status
*s
)
511 int shown_header
= 0;
514 for (i
= 0; i
< s
->change
.nr
; i
++) {
515 struct wt_status_change_data
*d
;
516 struct string_list_item
*it
;
517 it
= &(s
->change
.items
[i
]);
522 wt_status_print_unmerged_header(s
);
525 wt_status_print_unmerged_data(s
, it
);
528 wt_status_print_trailer(s
);
532 static void wt_status_print_updated(struct wt_status
*s
)
534 int shown_header
= 0;
537 for (i
= 0; i
< s
->change
.nr
; i
++) {
538 struct wt_status_change_data
*d
;
539 struct string_list_item
*it
;
540 it
= &(s
->change
.items
[i
]);
542 if (!d
->index_status
||
543 d
->index_status
== DIFF_STATUS_UNMERGED
)
546 wt_status_print_cached_header(s
);
550 wt_status_print_change_data(s
, WT_STATUS_UPDATED
, it
);
553 wt_status_print_trailer(s
);
559 * 1 : some change but no delete
561 static int wt_status_check_worktree_changes(struct wt_status
*s
,
562 int *dirty_submodules
)
567 *dirty_submodules
= 0;
569 for (i
= 0; i
< s
->change
.nr
; i
++) {
570 struct wt_status_change_data
*d
;
571 d
= s
->change
.items
[i
].util
;
572 if (!d
->worktree_status
||
573 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
577 if (d
->dirty_submodule
)
578 *dirty_submodules
= 1;
579 if (d
->worktree_status
== DIFF_STATUS_DELETED
)
585 static void wt_status_print_changed(struct wt_status
*s
)
587 int i
, dirty_submodules
;
588 int worktree_changes
= wt_status_check_worktree_changes(s
, &dirty_submodules
);
590 if (!worktree_changes
)
593 wt_status_print_dirty_header(s
, worktree_changes
< 0, dirty_submodules
);
595 for (i
= 0; i
< s
->change
.nr
; i
++) {
596 struct wt_status_change_data
*d
;
597 struct string_list_item
*it
;
598 it
= &(s
->change
.items
[i
]);
600 if (!d
->worktree_status
||
601 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
603 wt_status_print_change_data(s
, WT_STATUS_CHANGED
, it
);
605 wt_status_print_trailer(s
);
608 static void wt_status_print_submodule_summary(struct wt_status
*s
, int uncommitted
)
610 struct child_process sm_summary
;
611 char summary_limit
[64];
612 char index
[PATH_MAX
];
613 const char *env
[] = { NULL
, NULL
};
617 argv
[0] = "submodule";
619 argv
[2] = uncommitted
? "--files" : "--cached";
620 argv
[3] = "--for-status";
621 argv
[4] = "--summary-limit";
622 argv
[5] = summary_limit
;
623 argv
[6] = uncommitted
? NULL
: (s
->amend
? "HEAD^" : "HEAD");
626 sprintf(summary_limit
, "%d", s
->submodule_summary
);
627 snprintf(index
, sizeof(index
), "GIT_INDEX_FILE=%s", s
->index_file
);
629 memset(&sm_summary
, 0, sizeof(sm_summary
));
630 sm_summary
.argv
= argv
;
631 sm_summary
.env
= env
;
632 sm_summary
.git_cmd
= 1;
633 sm_summary
.no_stdin
= 1;
635 sm_summary
.out
= dup(fileno(s
->fp
)); /* run_command closes it */
636 run_command(&sm_summary
);
639 static void wt_status_print_other(struct wt_status
*s
,
640 struct string_list
*l
,
645 struct strbuf buf
= STRBUF_INIT
;
650 wt_status_print_other_header(s
, what
, how
);
652 for (i
= 0; i
< l
->nr
; i
++) {
653 struct string_list_item
*it
;
655 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
656 status_printf_more(s
, color(WT_STATUS_UNTRACKED
, s
),
657 "%s\n", quote_path(it
->string
, strlen(it
->string
),
660 strbuf_release(&buf
);
663 static void wt_status_print_verbose(struct wt_status
*s
)
666 struct setup_revision_opt opt
;
668 init_revisions(&rev
, NULL
);
669 DIFF_OPT_SET(&rev
.diffopt
, ALLOW_TEXTCONV
);
671 memset(&opt
, 0, sizeof(opt
));
672 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
673 setup_revisions(0, NULL
, &rev
, &opt
);
675 rev
.diffopt
.output_format
|= DIFF_FORMAT_PATCH
;
676 rev
.diffopt
.detect_rename
= 1;
677 rev
.diffopt
.file
= s
->fp
;
678 rev
.diffopt
.close_file
= 0;
680 * If we're not going to stdout, then we definitely don't
681 * want color, since we are going to the commit message
682 * file (and even the "auto" setting won't work, since it
683 * will have checked isatty on stdout).
686 rev
.diffopt
.use_color
= 0;
687 run_diff_index(&rev
, 1);
690 static void wt_status_print_tracking(struct wt_status
*s
)
692 struct strbuf sb
= STRBUF_INIT
;
694 struct branch
*branch
;
696 assert(s
->branch
&& !s
->is_initial
);
697 if (prefixcmp(s
->branch
, "refs/heads/"))
699 branch
= branch_get(s
->branch
+ 11);
700 if (!format_tracking_info(branch
, &sb
))
703 for (cp
= sb
.buf
; (ep
= strchr(cp
, '\n')) != NULL
; cp
= ep
+ 1)
704 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
),
705 "# %.*s", (int)(ep
- cp
), cp
);
706 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
709 void wt_status_print(struct wt_status
*s
)
711 const char *branch_color
= color(WT_STATUS_ONBRANCH
, s
);
712 const char *branch_status_color
= color(WT_STATUS_HEADER
, s
);
715 const char *on_what
= _("On branch ");
716 const char *branch_name
= s
->branch
;
717 if (!prefixcmp(branch_name
, "refs/heads/"))
719 else if (!strcmp(branch_name
, "HEAD")) {
721 branch_status_color
= color(WT_STATUS_NOBRANCH
, s
);
722 on_what
= _("Not currently on any branch.");
724 status_printf(s
, color(WT_STATUS_HEADER
, s
), "");
725 status_printf_more(s
, branch_status_color
, "%s", on_what
);
726 status_printf_more(s
, branch_color
, "%s\n", branch_name
);
728 wt_status_print_tracking(s
);
732 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
733 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), _("Initial commit"));
734 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
737 wt_status_print_updated(s
);
738 wt_status_print_unmerged(s
);
739 wt_status_print_changed(s
);
740 if (s
->submodule_summary
&&
741 (!s
->ignore_submodule_arg
||
742 strcmp(s
->ignore_submodule_arg
, "all"))) {
743 wt_status_print_submodule_summary(s
, 0); /* staged */
744 wt_status_print_submodule_summary(s
, 1); /* unstaged */
746 if (s
->show_untracked_files
) {
747 wt_status_print_other(s
, &s
->untracked
, _("Untracked"), "add");
748 if (s
->show_ignored_files
)
749 wt_status_print_other(s
, &s
->ignored
, _("Ignored"), "add -f");
750 } else if (s
->commitable
)
751 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("Untracked files not listed%s"),
753 ? _(" (use -u option to show untracked files)") : "");
756 wt_status_print_verbose(s
);
757 if (!s
->commitable
) {
759 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("No changes"));
762 else if (s
->workdir_dirty
)
763 printf(_("no changes added to commit%s\n"),
765 ? _(" (use \"git add\" and/or \"git commit -a\")") : "");
766 else if (s
->untracked
.nr
)
767 printf(_("nothing added to commit but untracked files present%s\n"),
769 ? _(" (use \"git add\" to track)") : "");
770 else if (s
->is_initial
)
771 printf(_("nothing to commit%s\n"), advice_status_hints
772 ? _(" (create/copy files and use \"git add\" to track)") : "");
773 else if (!s
->show_untracked_files
)
774 printf(_("nothing to commit%s\n"), advice_status_hints
775 ? _(" (use -u to show untracked files)") : "");
777 printf(_("nothing to commit%s\n"), advice_status_hints
778 ? _(" (working directory clean)") : "");
782 static void wt_shortstatus_unmerged(int null_termination
, struct string_list_item
*it
,
785 struct wt_status_change_data
*d
= it
->util
;
786 const char *how
= "??";
788 switch (d
->stagemask
) {
789 case 1: how
= "DD"; break; /* both deleted */
790 case 2: how
= "AU"; break; /* added by us */
791 case 3: how
= "UD"; break; /* deleted by them */
792 case 4: how
= "UA"; break; /* added by them */
793 case 5: how
= "DU"; break; /* deleted by us */
794 case 6: how
= "AA"; break; /* both added */
795 case 7: how
= "UU"; break; /* both modified */
797 color_fprintf(s
->fp
, color(WT_STATUS_UNMERGED
, s
), "%s", how
);
798 if (null_termination
) {
799 fprintf(stdout
, " %s%c", it
->string
, 0);
801 struct strbuf onebuf
= STRBUF_INIT
;
803 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
804 printf(" %s\n", one
);
805 strbuf_release(&onebuf
);
809 static void wt_shortstatus_status(int null_termination
, struct string_list_item
*it
,
812 struct wt_status_change_data
*d
= it
->util
;
815 color_fprintf(s
->fp
, color(WT_STATUS_UPDATED
, s
), "%c", d
->index_status
);
818 if (d
->worktree_status
)
819 color_fprintf(s
->fp
, color(WT_STATUS_CHANGED
, s
), "%c", d
->worktree_status
);
823 if (null_termination
) {
824 fprintf(stdout
, "%s%c", it
->string
, 0);
826 fprintf(stdout
, "%s%c", d
->head_path
, 0);
828 struct strbuf onebuf
= STRBUF_INIT
;
831 one
= quote_path(d
->head_path
, -1, &onebuf
, s
->prefix
);
832 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
834 strbuf_addch(&onebuf
, '"');
837 printf("%s -> ", one
);
838 strbuf_release(&onebuf
);
840 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
841 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
843 strbuf_addch(&onebuf
, '"');
847 strbuf_release(&onebuf
);
851 static void wt_shortstatus_other(int null_termination
, struct string_list_item
*it
,
852 struct wt_status
*s
, const char *sign
)
854 if (null_termination
) {
855 fprintf(stdout
, "%s %s%c", sign
, it
->string
, 0);
857 struct strbuf onebuf
= STRBUF_INIT
;
859 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
860 color_fprintf(s
->fp
, color(WT_STATUS_UNTRACKED
, s
), "%s", sign
);
861 printf(" %s\n", one
);
862 strbuf_release(&onebuf
);
866 static void wt_shortstatus_print_tracking(struct wt_status
*s
)
868 struct branch
*branch
;
869 const char *header_color
= color(WT_STATUS_HEADER
, s
);
870 const char *branch_color_local
= color(WT_STATUS_LOCAL_BRANCH
, s
);
871 const char *branch_color_remote
= color(WT_STATUS_REMOTE_BRANCH
, s
);
874 const char *branch_name
;
875 int num_ours
, num_theirs
;
877 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "## ");
881 branch_name
= s
->branch
;
883 if (!prefixcmp(branch_name
, "refs/heads/"))
885 else if (!strcmp(branch_name
, "HEAD")) {
886 branch_name
= _("HEAD (no branch)");
887 branch_color_local
= color(WT_STATUS_NOBRANCH
, s
);
890 branch
= branch_get(s
->branch
+ 11);
892 color_fprintf(s
->fp
, header_color
, _("Initial commit on "));
893 if (!stat_tracking_info(branch
, &num_ours
, &num_theirs
)) {
894 color_fprintf_ln(s
->fp
, branch_color_local
,
899 base
= branch
->merge
[0]->dst
;
900 base
= shorten_unambiguous_ref(base
, 0);
901 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
902 color_fprintf(s
->fp
, header_color
, "...");
903 color_fprintf(s
->fp
, branch_color_remote
, "%s", base
);
905 color_fprintf(s
->fp
, header_color
, " [");
907 color_fprintf(s
->fp
, header_color
, _("behind "));
908 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
909 } else if (!num_theirs
) {
910 color_fprintf(s
->fp
, header_color
, _("ahead "));
911 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
913 color_fprintf(s
->fp
, header_color
, _("ahead "));
914 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
915 color_fprintf(s
->fp
, header_color
, _(", behind "));
916 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
919 color_fprintf_ln(s
->fp
, header_color
, "]");
922 void wt_shortstatus_print(struct wt_status
*s
, int null_termination
, int show_branch
)
927 wt_shortstatus_print_tracking(s
);
929 for (i
= 0; i
< s
->change
.nr
; i
++) {
930 struct wt_status_change_data
*d
;
931 struct string_list_item
*it
;
933 it
= &(s
->change
.items
[i
]);
936 wt_shortstatus_unmerged(null_termination
, it
, s
);
938 wt_shortstatus_status(null_termination
, it
, s
);
940 for (i
= 0; i
< s
->untracked
.nr
; i
++) {
941 struct string_list_item
*it
;
943 it
= &(s
->untracked
.items
[i
]);
944 wt_shortstatus_other(null_termination
, it
, s
, "??");
946 for (i
= 0; i
< s
->ignored
.nr
; i
++) {
947 struct string_list_item
*it
;
949 it
= &(s
->ignored
.items
[i
]);
950 wt_shortstatus_other(null_termination
, it
, s
, "!!");
954 void wt_porcelain_print(struct wt_status
*s
, int null_termination
)
957 s
->relative_paths
= 0;
959 wt_shortstatus_print(s
, null_termination
, 0);