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];
115 memset(s
, 0, sizeof(*s
));
116 memcpy(s
->color_palette
, default_wt_status_colors
,
117 sizeof(default_wt_status_colors
));
118 s
->show_untracked_files
= SHOW_NORMAL_UNTRACKED_FILES
;
120 s
->relative_paths
= 1;
121 s
->branch
= resolve_refdup("HEAD", sha1
, 0, NULL
);
122 s
->reference
= "HEAD";
124 s
->index_file
= get_index_file();
125 s
->change
.strdup_strings
= 1;
126 s
->untracked
.strdup_strings
= 1;
127 s
->ignored
.strdup_strings
= 1;
130 static void wt_status_print_unmerged_header(struct wt_status
*s
)
132 const char *c
= color(WT_STATUS_HEADER
, s
);
134 status_printf_ln(s
, c
, _("Unmerged paths:"));
135 if (!advice_status_hints
)
137 if (s
->whence
!= FROM_COMMIT
)
139 else if (!s
->is_initial
)
140 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
142 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
143 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
144 status_printf_ln(s
, c
, "");
147 static void wt_status_print_cached_header(struct wt_status
*s
)
149 const char *c
= color(WT_STATUS_HEADER
, s
);
151 status_printf_ln(s
, c
, _("Changes to be committed:"));
152 if (!advice_status_hints
)
154 if (s
->whence
!= FROM_COMMIT
)
155 ; /* NEEDSWORK: use "git reset --unresolve"??? */
156 else if (!s
->is_initial
)
157 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
159 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
160 status_printf_ln(s
, c
, "");
163 static void wt_status_print_dirty_header(struct wt_status
*s
,
165 int has_dirty_submodules
)
167 const char *c
= color(WT_STATUS_HEADER
, s
);
169 status_printf_ln(s
, c
, _("Changes not staged for commit:"));
170 if (!advice_status_hints
)
173 status_printf_ln(s
, c
, _(" (use \"git add <file>...\" to update what will be committed)"));
175 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" to update what will be committed)"));
176 status_printf_ln(s
, c
, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)"));
177 if (has_dirty_submodules
)
178 status_printf_ln(s
, c
, _(" (commit or discard the untracked or modified content in submodules)"));
179 status_printf_ln(s
, c
, "");
182 static void wt_status_print_other_header(struct wt_status
*s
,
186 const char *c
= color(WT_STATUS_HEADER
, s
);
187 status_printf_ln(s
, c
, _("%s files:"), what
);
188 if (!advice_status_hints
)
190 status_printf_ln(s
, c
, _(" (use \"git %s <file>...\" to include in what will be committed)"), how
);
191 status_printf_ln(s
, c
, "");
194 static void wt_status_print_trailer(struct wt_status
*s
)
196 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
199 #define quote_path quote_path_relative
201 static void wt_status_print_unmerged_data(struct wt_status
*s
,
202 struct string_list_item
*it
)
204 const char *c
= color(WT_STATUS_UNMERGED
, s
);
205 struct wt_status_change_data
*d
= it
->util
;
206 struct strbuf onebuf
= STRBUF_INIT
;
207 const char *one
, *how
= _("bug");
209 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
210 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
211 switch (d
->stagemask
) {
212 case 1: how
= _("both deleted:"); break;
213 case 2: how
= _("added by us:"); break;
214 case 3: how
= _("deleted by them:"); break;
215 case 4: how
= _("added by them:"); break;
216 case 5: how
= _("deleted by us:"); break;
217 case 6: how
= _("both added:"); break;
218 case 7: how
= _("both modified:"); break;
220 status_printf_more(s
, c
, "%-20s%s\n", how
, one
);
221 strbuf_release(&onebuf
);
224 static void wt_status_print_change_data(struct wt_status
*s
,
226 struct string_list_item
*it
)
228 struct wt_status_change_data
*d
= it
->util
;
229 const char *c
= color(change_type
, s
);
233 const char *one
, *two
;
234 struct strbuf onebuf
= STRBUF_INIT
, twobuf
= STRBUF_INIT
;
235 struct strbuf extra
= STRBUF_INIT
;
237 one_name
= two_name
= it
->string
;
238 switch (change_type
) {
239 case WT_STATUS_UPDATED
:
240 status
= d
->index_status
;
242 one_name
= d
->head_path
;
244 case WT_STATUS_CHANGED
:
245 if (d
->new_submodule_commits
|| d
->dirty_submodule
) {
246 strbuf_addstr(&extra
, " (");
247 if (d
->new_submodule_commits
)
248 strbuf_addf(&extra
, _("new commits, "));
249 if (d
->dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
250 strbuf_addf(&extra
, _("modified content, "));
251 if (d
->dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
)
252 strbuf_addf(&extra
, _("untracked content, "));
253 strbuf_setlen(&extra
, extra
.len
- 2);
254 strbuf_addch(&extra
, ')');
256 status
= d
->worktree_status
;
260 one
= quote_path(one_name
, -1, &onebuf
, s
->prefix
);
261 two
= quote_path(two_name
, -1, &twobuf
, s
->prefix
);
263 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
265 case DIFF_STATUS_ADDED
:
266 status_printf_more(s
, c
, _("new file: %s"), one
);
268 case DIFF_STATUS_COPIED
:
269 status_printf_more(s
, c
, _("copied: %s -> %s"), one
, two
);
271 case DIFF_STATUS_DELETED
:
272 status_printf_more(s
, c
, _("deleted: %s"), one
);
274 case DIFF_STATUS_MODIFIED
:
275 status_printf_more(s
, c
, _("modified: %s"), one
);
277 case DIFF_STATUS_RENAMED
:
278 status_printf_more(s
, c
, _("renamed: %s -> %s"), one
, two
);
280 case DIFF_STATUS_TYPE_CHANGED
:
281 status_printf_more(s
, c
, _("typechange: %s"), one
);
283 case DIFF_STATUS_UNKNOWN
:
284 status_printf_more(s
, c
, _("unknown: %s"), one
);
286 case DIFF_STATUS_UNMERGED
:
287 status_printf_more(s
, c
, _("unmerged: %s"), one
);
290 die(_("bug: unhandled diff status %c"), status
);
293 status_printf_more(s
, color(WT_STATUS_HEADER
, s
), "%s", extra
.buf
);
294 strbuf_release(&extra
);
296 status_printf_more(s
, GIT_COLOR_NORMAL
, "\n");
297 strbuf_release(&onebuf
);
298 strbuf_release(&twobuf
);
301 static void wt_status_collect_changed_cb(struct diff_queue_struct
*q
,
302 struct diff_options
*options
,
305 struct wt_status
*s
= data
;
310 s
->workdir_dirty
= 1;
311 for (i
= 0; i
< q
->nr
; i
++) {
312 struct diff_filepair
*p
;
313 struct string_list_item
*it
;
314 struct wt_status_change_data
*d
;
317 it
= string_list_insert(&s
->change
, p
->one
->path
);
320 d
= xcalloc(1, sizeof(*d
));
323 if (!d
->worktree_status
)
324 d
->worktree_status
= p
->status
;
325 d
->dirty_submodule
= p
->two
->dirty_submodule
;
326 if (S_ISGITLINK(p
->two
->mode
))
327 d
->new_submodule_commits
= !!hashcmp(p
->one
->sha1
, p
->two
->sha1
);
331 static int unmerged_mask(const char *path
)
334 struct cache_entry
*ce
;
336 pos
= cache_name_pos(path
, strlen(path
));
342 while (pos
< active_nr
) {
343 ce
= active_cache
[pos
++];
344 if (strcmp(ce
->name
, path
) || !ce_stage(ce
))
346 mask
|= (1 << (ce_stage(ce
) - 1));
351 static void wt_status_collect_updated_cb(struct diff_queue_struct
*q
,
352 struct diff_options
*options
,
355 struct wt_status
*s
= data
;
358 for (i
= 0; i
< q
->nr
; i
++) {
359 struct diff_filepair
*p
;
360 struct string_list_item
*it
;
361 struct wt_status_change_data
*d
;
364 it
= string_list_insert(&s
->change
, p
->two
->path
);
367 d
= xcalloc(1, sizeof(*d
));
370 if (!d
->index_status
)
371 d
->index_status
= p
->status
;
373 case DIFF_STATUS_COPIED
:
374 case DIFF_STATUS_RENAMED
:
375 d
->head_path
= xstrdup(p
->one
->path
);
377 case DIFF_STATUS_UNMERGED
:
378 d
->stagemask
= unmerged_mask(p
->two
->path
);
384 static void wt_status_collect_changes_worktree(struct wt_status
*s
)
388 init_revisions(&rev
, NULL
);
389 setup_revisions(0, NULL
, &rev
, NULL
);
390 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
391 DIFF_OPT_SET(&rev
.diffopt
, DIRTY_SUBMODULES
);
392 if (!s
->show_untracked_files
)
393 DIFF_OPT_SET(&rev
.diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
394 if (s
->ignore_submodule_arg
) {
395 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
396 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
398 rev
.diffopt
.format_callback
= wt_status_collect_changed_cb
;
399 rev
.diffopt
.format_callback_data
= s
;
400 init_pathspec(&rev
.prune_data
, s
->pathspec
);
401 run_diff_files(&rev
, 0);
404 static void wt_status_collect_changes_index(struct wt_status
*s
)
407 struct setup_revision_opt opt
;
409 init_revisions(&rev
, NULL
);
410 memset(&opt
, 0, sizeof(opt
));
411 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
412 setup_revisions(0, NULL
, &rev
, &opt
);
414 if (s
->ignore_submodule_arg
) {
415 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
416 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
419 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
420 rev
.diffopt
.format_callback
= wt_status_collect_updated_cb
;
421 rev
.diffopt
.format_callback_data
= s
;
422 rev
.diffopt
.detect_rename
= 1;
423 rev
.diffopt
.rename_limit
= 200;
424 rev
.diffopt
.break_opt
= 0;
425 init_pathspec(&rev
.prune_data
, s
->pathspec
);
426 run_diff_index(&rev
, 1);
429 static void wt_status_collect_changes_initial(struct wt_status
*s
)
431 struct pathspec pathspec
;
434 init_pathspec(&pathspec
, s
->pathspec
);
435 for (i
= 0; i
< active_nr
; i
++) {
436 struct string_list_item
*it
;
437 struct wt_status_change_data
*d
;
438 struct cache_entry
*ce
= active_cache
[i
];
440 if (!ce_path_match(ce
, &pathspec
))
442 it
= string_list_insert(&s
->change
, ce
->name
);
445 d
= xcalloc(1, sizeof(*d
));
449 d
->index_status
= DIFF_STATUS_UNMERGED
;
450 d
->stagemask
|= (1 << (ce_stage(ce
) - 1));
453 d
->index_status
= DIFF_STATUS_ADDED
;
455 free_pathspec(&pathspec
);
458 static void wt_status_collect_untracked(struct wt_status
*s
)
461 struct dir_struct dir
;
463 if (!s
->show_untracked_files
)
465 memset(&dir
, 0, sizeof(dir
));
466 if (s
->show_untracked_files
!= SHOW_ALL_UNTRACKED_FILES
)
468 DIR_SHOW_OTHER_DIRECTORIES
| DIR_HIDE_EMPTY_DIRECTORIES
;
469 setup_standard_excludes(&dir
);
471 fill_directory(&dir
, s
->pathspec
);
472 for (i
= 0; i
< dir
.nr
; i
++) {
473 struct dir_entry
*ent
= dir
.entries
[i
];
474 if (cache_name_is_other(ent
->name
, ent
->len
) &&
475 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
476 string_list_insert(&s
->untracked
, ent
->name
);
480 if (s
->show_ignored_files
) {
482 dir
.flags
= DIR_SHOW_IGNORED
| DIR_SHOW_OTHER_DIRECTORIES
;
483 fill_directory(&dir
, s
->pathspec
);
484 for (i
= 0; i
< dir
.nr
; i
++) {
485 struct dir_entry
*ent
= dir
.entries
[i
];
486 if (cache_name_is_other(ent
->name
, ent
->len
) &&
487 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
488 string_list_insert(&s
->ignored
, ent
->name
);
496 void wt_status_collect(struct wt_status
*s
)
498 wt_status_collect_changes_worktree(s
);
501 wt_status_collect_changes_initial(s
);
503 wt_status_collect_changes_index(s
);
504 wt_status_collect_untracked(s
);
507 static void wt_status_print_unmerged(struct wt_status
*s
)
509 int shown_header
= 0;
512 for (i
= 0; i
< s
->change
.nr
; i
++) {
513 struct wt_status_change_data
*d
;
514 struct string_list_item
*it
;
515 it
= &(s
->change
.items
[i
]);
520 wt_status_print_unmerged_header(s
);
523 wt_status_print_unmerged_data(s
, it
);
526 wt_status_print_trailer(s
);
530 static void wt_status_print_updated(struct wt_status
*s
)
532 int shown_header
= 0;
535 for (i
= 0; i
< s
->change
.nr
; i
++) {
536 struct wt_status_change_data
*d
;
537 struct string_list_item
*it
;
538 it
= &(s
->change
.items
[i
]);
540 if (!d
->index_status
||
541 d
->index_status
== DIFF_STATUS_UNMERGED
)
544 wt_status_print_cached_header(s
);
548 wt_status_print_change_data(s
, WT_STATUS_UPDATED
, it
);
551 wt_status_print_trailer(s
);
557 * 1 : some change but no delete
559 static int wt_status_check_worktree_changes(struct wt_status
*s
,
560 int *dirty_submodules
)
565 *dirty_submodules
= 0;
567 for (i
= 0; i
< s
->change
.nr
; i
++) {
568 struct wt_status_change_data
*d
;
569 d
= s
->change
.items
[i
].util
;
570 if (!d
->worktree_status
||
571 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
575 if (d
->dirty_submodule
)
576 *dirty_submodules
= 1;
577 if (d
->worktree_status
== DIFF_STATUS_DELETED
)
583 static void wt_status_print_changed(struct wt_status
*s
)
585 int i
, dirty_submodules
;
586 int worktree_changes
= wt_status_check_worktree_changes(s
, &dirty_submodules
);
588 if (!worktree_changes
)
591 wt_status_print_dirty_header(s
, worktree_changes
< 0, dirty_submodules
);
593 for (i
= 0; i
< s
->change
.nr
; i
++) {
594 struct wt_status_change_data
*d
;
595 struct string_list_item
*it
;
596 it
= &(s
->change
.items
[i
]);
598 if (!d
->worktree_status
||
599 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
601 wt_status_print_change_data(s
, WT_STATUS_CHANGED
, it
);
603 wt_status_print_trailer(s
);
606 static void wt_status_print_submodule_summary(struct wt_status
*s
, int uncommitted
)
608 struct child_process sm_summary
;
609 char summary_limit
[64];
610 char index
[PATH_MAX
];
611 const char *env
[] = { NULL
, NULL
};
615 argv
[0] = "submodule";
617 argv
[2] = uncommitted
? "--files" : "--cached";
618 argv
[3] = "--for-status";
619 argv
[4] = "--summary-limit";
620 argv
[5] = summary_limit
;
621 argv
[6] = uncommitted
? NULL
: (s
->amend
? "HEAD^" : "HEAD");
624 sprintf(summary_limit
, "%d", s
->submodule_summary
);
625 snprintf(index
, sizeof(index
), "GIT_INDEX_FILE=%s", s
->index_file
);
627 memset(&sm_summary
, 0, sizeof(sm_summary
));
628 sm_summary
.argv
= argv
;
629 sm_summary
.env
= env
;
630 sm_summary
.git_cmd
= 1;
631 sm_summary
.no_stdin
= 1;
633 sm_summary
.out
= dup(fileno(s
->fp
)); /* run_command closes it */
634 run_command(&sm_summary
);
637 static void wt_status_print_other(struct wt_status
*s
,
638 struct string_list
*l
,
643 struct strbuf buf
= STRBUF_INIT
;
648 wt_status_print_other_header(s
, what
, how
);
650 for (i
= 0; i
< l
->nr
; i
++) {
651 struct string_list_item
*it
;
653 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
654 status_printf_more(s
, color(WT_STATUS_UNTRACKED
, s
),
655 "%s\n", quote_path(it
->string
, strlen(it
->string
),
658 strbuf_release(&buf
);
661 static void wt_status_print_verbose(struct wt_status
*s
)
664 struct setup_revision_opt opt
;
666 init_revisions(&rev
, NULL
);
667 DIFF_OPT_SET(&rev
.diffopt
, ALLOW_TEXTCONV
);
669 memset(&opt
, 0, sizeof(opt
));
670 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
671 setup_revisions(0, NULL
, &rev
, &opt
);
673 rev
.diffopt
.output_format
|= DIFF_FORMAT_PATCH
;
674 rev
.diffopt
.detect_rename
= 1;
675 rev
.diffopt
.file
= s
->fp
;
676 rev
.diffopt
.close_file
= 0;
678 * If we're not going to stdout, then we definitely don't
679 * want color, since we are going to the commit message
680 * file (and even the "auto" setting won't work, since it
681 * will have checked isatty on stdout).
684 rev
.diffopt
.use_color
= 0;
685 run_diff_index(&rev
, 1);
688 static void wt_status_print_tracking(struct wt_status
*s
)
690 struct strbuf sb
= STRBUF_INIT
;
692 struct branch
*branch
;
694 assert(s
->branch
&& !s
->is_initial
);
695 if (prefixcmp(s
->branch
, "refs/heads/"))
697 branch
= branch_get(s
->branch
+ 11);
698 if (!format_tracking_info(branch
, &sb
))
701 for (cp
= sb
.buf
; (ep
= strchr(cp
, '\n')) != NULL
; cp
= ep
+ 1)
702 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
),
703 "# %.*s", (int)(ep
- cp
), cp
);
704 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
707 void wt_status_print(struct wt_status
*s
)
709 const char *branch_color
= color(WT_STATUS_ONBRANCH
, s
);
710 const char *branch_status_color
= color(WT_STATUS_HEADER
, s
);
713 const char *on_what
= _("On branch ");
714 const char *branch_name
= s
->branch
;
715 if (!prefixcmp(branch_name
, "refs/heads/"))
717 else if (!strcmp(branch_name
, "HEAD")) {
719 branch_status_color
= color(WT_STATUS_NOBRANCH
, s
);
720 on_what
= _("Not currently on any branch.");
722 status_printf(s
, color(WT_STATUS_HEADER
, s
), "");
723 status_printf_more(s
, branch_status_color
, "%s", on_what
);
724 status_printf_more(s
, branch_color
, "%s\n", branch_name
);
726 wt_status_print_tracking(s
);
730 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
731 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), _("Initial commit"));
732 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
735 wt_status_print_updated(s
);
736 wt_status_print_unmerged(s
);
737 wt_status_print_changed(s
);
738 if (s
->submodule_summary
&&
739 (!s
->ignore_submodule_arg
||
740 strcmp(s
->ignore_submodule_arg
, "all"))) {
741 wt_status_print_submodule_summary(s
, 0); /* staged */
742 wt_status_print_submodule_summary(s
, 1); /* unstaged */
744 if (s
->show_untracked_files
) {
745 wt_status_print_other(s
, &s
->untracked
, _("Untracked"), "add");
746 if (s
->show_ignored_files
)
747 wt_status_print_other(s
, &s
->ignored
, _("Ignored"), "add -f");
748 } else if (s
->commitable
)
749 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("Untracked files not listed%s"),
751 ? _(" (use -u option to show untracked files)") : "");
754 wt_status_print_verbose(s
);
755 if (!s
->commitable
) {
757 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("No changes"));
760 else if (s
->workdir_dirty
)
761 printf(_("no changes added to commit%s\n"),
763 ? _(" (use \"git add\" and/or \"git commit -a\")") : "");
764 else if (s
->untracked
.nr
)
765 printf(_("nothing added to commit but untracked files present%s\n"),
767 ? _(" (use \"git add\" to track)") : "");
768 else if (s
->is_initial
)
769 printf(_("nothing to commit%s\n"), advice_status_hints
770 ? _(" (create/copy files and use \"git add\" to track)") : "");
771 else if (!s
->show_untracked_files
)
772 printf(_("nothing to commit%s\n"), advice_status_hints
773 ? _(" (use -u to show untracked files)") : "");
775 printf(_("nothing to commit%s\n"), advice_status_hints
776 ? _(" (working directory clean)") : "");
780 static void wt_shortstatus_unmerged(struct string_list_item
*it
,
783 struct wt_status_change_data
*d
= it
->util
;
784 const char *how
= "??";
786 switch (d
->stagemask
) {
787 case 1: how
= "DD"; break; /* both deleted */
788 case 2: how
= "AU"; break; /* added by us */
789 case 3: how
= "UD"; break; /* deleted by them */
790 case 4: how
= "UA"; break; /* added by them */
791 case 5: how
= "DU"; break; /* deleted by us */
792 case 6: how
= "AA"; break; /* both added */
793 case 7: how
= "UU"; break; /* both modified */
795 color_fprintf(s
->fp
, color(WT_STATUS_UNMERGED
, s
), "%s", how
);
796 if (s
->null_termination
) {
797 fprintf(stdout
, " %s%c", it
->string
, 0);
799 struct strbuf onebuf
= STRBUF_INIT
;
801 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
802 printf(" %s\n", one
);
803 strbuf_release(&onebuf
);
807 static void wt_shortstatus_status(struct string_list_item
*it
,
810 struct wt_status_change_data
*d
= it
->util
;
813 color_fprintf(s
->fp
, color(WT_STATUS_UPDATED
, s
), "%c", d
->index_status
);
816 if (d
->worktree_status
)
817 color_fprintf(s
->fp
, color(WT_STATUS_CHANGED
, s
), "%c", d
->worktree_status
);
821 if (s
->null_termination
) {
822 fprintf(stdout
, "%s%c", it
->string
, 0);
824 fprintf(stdout
, "%s%c", d
->head_path
, 0);
826 struct strbuf onebuf
= STRBUF_INIT
;
829 one
= quote_path(d
->head_path
, -1, &onebuf
, s
->prefix
);
830 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
832 strbuf_addch(&onebuf
, '"');
835 printf("%s -> ", one
);
836 strbuf_release(&onebuf
);
838 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
839 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
841 strbuf_addch(&onebuf
, '"');
845 strbuf_release(&onebuf
);
849 static void wt_shortstatus_other(struct string_list_item
*it
,
850 struct wt_status
*s
, const char *sign
)
852 if (s
->null_termination
) {
853 fprintf(stdout
, "%s %s%c", sign
, it
->string
, 0);
855 struct strbuf onebuf
= STRBUF_INIT
;
857 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
858 color_fprintf(s
->fp
, color(WT_STATUS_UNTRACKED
, s
), "%s", sign
);
859 printf(" %s\n", one
);
860 strbuf_release(&onebuf
);
864 static void wt_shortstatus_print_tracking(struct wt_status
*s
)
866 struct branch
*branch
;
867 const char *header_color
= color(WT_STATUS_HEADER
, s
);
868 const char *branch_color_local
= color(WT_STATUS_LOCAL_BRANCH
, s
);
869 const char *branch_color_remote
= color(WT_STATUS_REMOTE_BRANCH
, s
);
872 const char *branch_name
;
873 int num_ours
, num_theirs
;
875 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "## ");
879 branch_name
= s
->branch
;
881 if (!prefixcmp(branch_name
, "refs/heads/"))
883 else if (!strcmp(branch_name
, "HEAD")) {
884 branch_name
= _("HEAD (no branch)");
885 branch_color_local
= color(WT_STATUS_NOBRANCH
, s
);
888 branch
= branch_get(s
->branch
+ 11);
890 color_fprintf(s
->fp
, header_color
, _("Initial commit on "));
891 if (!stat_tracking_info(branch
, &num_ours
, &num_theirs
)) {
892 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
893 fputc(s
->null_termination
? '\0' : '\n', s
->fp
);
897 base
= branch
->merge
[0]->dst
;
898 base
= shorten_unambiguous_ref(base
, 0);
899 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
900 color_fprintf(s
->fp
, header_color
, "...");
901 color_fprintf(s
->fp
, branch_color_remote
, "%s", base
);
903 color_fprintf(s
->fp
, header_color
, " [");
905 color_fprintf(s
->fp
, header_color
, _("behind "));
906 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
907 } else if (!num_theirs
) {
908 color_fprintf(s
->fp
, header_color
, _("ahead "));
909 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
911 color_fprintf(s
->fp
, header_color
, _("ahead "));
912 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
913 color_fprintf(s
->fp
, header_color
, _(", behind "));
914 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
917 color_fprintf(s
->fp
, header_color
, "]");
918 fputc(s
->null_termination
? '\0' : '\n', s
->fp
);
921 void wt_shortstatus_print(struct wt_status
*s
)
926 wt_shortstatus_print_tracking(s
);
928 for (i
= 0; i
< s
->change
.nr
; i
++) {
929 struct wt_status_change_data
*d
;
930 struct string_list_item
*it
;
932 it
= &(s
->change
.items
[i
]);
935 wt_shortstatus_unmerged(it
, s
);
937 wt_shortstatus_status(it
, s
);
939 for (i
= 0; i
< s
->untracked
.nr
; i
++) {
940 struct string_list_item
*it
;
942 it
= &(s
->untracked
.items
[i
]);
943 wt_shortstatus_other(it
, s
, "??");
945 for (i
= 0; i
< s
->ignored
.nr
; i
++) {
946 struct string_list_item
*it
;
948 it
= &(s
->ignored
.items
[i
]);
949 wt_shortstatus_other(it
, s
, "!!");
953 void wt_porcelain_print(struct wt_status
*s
)
956 s
->relative_paths
= 0;
958 wt_shortstatus_print(s
);