10 #include "run-command.h"
13 #include "submodule.h"
16 static char default_wt_status_colors
[][COLOR_MAXLEN
] = {
17 GIT_COLOR_NORMAL
, /* WT_STATUS_HEADER */
18 GIT_COLOR_GREEN
, /* WT_STATUS_UPDATED */
19 GIT_COLOR_RED
, /* WT_STATUS_CHANGED */
20 GIT_COLOR_RED
, /* WT_STATUS_UNTRACKED */
21 GIT_COLOR_RED
, /* WT_STATUS_NOBRANCH */
22 GIT_COLOR_RED
, /* WT_STATUS_UNMERGED */
23 GIT_COLOR_GREEN
, /* WT_STATUS_LOCAL_BRANCH */
24 GIT_COLOR_RED
, /* WT_STATUS_REMOTE_BRANCH */
25 GIT_COLOR_NIL
, /* WT_STATUS_ONBRANCH */
28 static const char *color(int slot
, struct wt_status
*s
)
31 if (want_color(s
->use_color
))
32 c
= s
->color_palette
[slot
];
33 if (slot
== WT_STATUS_ONBRANCH
&& color_is_nil(c
))
34 c
= s
->color_palette
[WT_STATUS_HEADER
];
38 static void status_vprintf(struct wt_status
*s
, int at_bol
, const char *color
,
39 const char *fmt
, va_list ap
, const char *trail
)
41 struct strbuf sb
= STRBUF_INIT
;
42 struct strbuf linebuf
= STRBUF_INIT
;
43 const char *line
, *eol
;
45 strbuf_vaddf(&sb
, fmt
, ap
);
47 strbuf_addch(&sb
, '#');
49 strbuf_addch(&sb
, ' ');
50 color_print_strbuf(s
->fp
, color
, &sb
);
52 fprintf(s
->fp
, "%s", trail
);
56 for (line
= sb
.buf
; *line
; line
= eol
+ 1) {
57 eol
= strchr(line
, '\n');
59 strbuf_reset(&linebuf
);
61 strbuf_addch(&linebuf
, '#');
62 if (*line
!= '\n' && *line
!= '\t')
63 strbuf_addch(&linebuf
, ' ');
66 strbuf_add(&linebuf
, line
, eol
- line
);
68 strbuf_addstr(&linebuf
, line
);
69 color_print_strbuf(s
->fp
, color
, &linebuf
);
77 fprintf(s
->fp
, "%s", trail
);
78 strbuf_release(&linebuf
);
82 void status_printf_ln(struct wt_status
*s
, const char *color
,
88 status_vprintf(s
, 1, color
, fmt
, ap
, "\n");
92 void status_printf(struct wt_status
*s
, const char *color
,
98 status_vprintf(s
, 1, color
, fmt
, ap
, NULL
);
102 void status_printf_more(struct wt_status
*s
, const char *color
,
103 const char *fmt
, ...)
108 status_vprintf(s
, 0, color
, fmt
, ap
, NULL
);
112 void wt_status_prepare(struct wt_status
*s
)
114 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 s
->branch
= resolve_refdup("HEAD", sha1
, 0, NULL
);
123 s
->reference
= "HEAD";
125 s
->index_file
= get_index_file();
126 s
->change
.strdup_strings
= 1;
127 s
->untracked
.strdup_strings
= 1;
128 s
->ignored
.strdup_strings
= 1;
131 static void wt_status_print_unmerged_header(struct wt_status
*s
)
133 const char *c
= color(WT_STATUS_HEADER
, s
);
135 status_printf_ln(s
, c
, _("Unmerged paths:"));
136 if (!advice_status_hints
)
138 if (s
->whence
!= FROM_COMMIT
)
140 else if (!s
->is_initial
)
141 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
143 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
144 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
145 status_printf_ln(s
, c
, "");
148 static void wt_status_print_cached_header(struct wt_status
*s
)
150 const char *c
= color(WT_STATUS_HEADER
, s
);
152 status_printf_ln(s
, c
, _("Changes to be committed:"));
153 if (!advice_status_hints
)
155 if (s
->whence
!= FROM_COMMIT
)
156 ; /* NEEDSWORK: use "git reset --unresolve"??? */
157 else if (!s
->is_initial
)
158 status_printf_ln(s
, c
, _(" (use \"git reset %s <file>...\" to unstage)"), s
->reference
);
160 status_printf_ln(s
, c
, _(" (use \"git rm --cached <file>...\" to unstage)"));
161 status_printf_ln(s
, c
, "");
164 static void wt_status_print_dirty_header(struct wt_status
*s
,
166 int has_dirty_submodules
)
168 const char *c
= color(WT_STATUS_HEADER
, s
);
170 status_printf_ln(s
, c
, _("Changes not staged for commit:"));
171 if (!advice_status_hints
)
174 status_printf_ln(s
, c
, _(" (use \"git add <file>...\" to update what will be committed)"));
176 status_printf_ln(s
, c
, _(" (use \"git add/rm <file>...\" to update what will be committed)"));
177 status_printf_ln(s
, c
, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)"));
178 if (has_dirty_submodules
)
179 status_printf_ln(s
, c
, _(" (commit or discard the untracked or modified content in submodules)"));
180 status_printf_ln(s
, c
, "");
183 static void wt_status_print_other_header(struct wt_status
*s
,
187 const char *c
= color(WT_STATUS_HEADER
, s
);
188 status_printf_ln(s
, c
, _("%s files:"), what
);
189 if (!advice_status_hints
)
191 status_printf_ln(s
, c
, _(" (use \"git %s <file>...\" to include in what will be committed)"), how
);
192 status_printf_ln(s
, c
, "");
195 static void wt_status_print_trailer(struct wt_status
*s
)
197 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
200 #define quote_path quote_path_relative
202 static void wt_status_print_unmerged_data(struct wt_status
*s
,
203 struct string_list_item
*it
)
205 const char *c
= color(WT_STATUS_UNMERGED
, s
);
206 struct wt_status_change_data
*d
= it
->util
;
207 struct strbuf onebuf
= STRBUF_INIT
;
208 const char *one
, *how
= _("bug");
210 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
211 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
212 switch (d
->stagemask
) {
213 case 1: how
= _("both deleted:"); break;
214 case 2: how
= _("added by us:"); break;
215 case 3: how
= _("deleted by them:"); break;
216 case 4: how
= _("added by them:"); break;
217 case 5: how
= _("deleted by us:"); break;
218 case 6: how
= _("both added:"); break;
219 case 7: how
= _("both modified:"); break;
221 status_printf_more(s
, c
, "%-20s%s\n", how
, one
);
222 strbuf_release(&onebuf
);
225 static void wt_status_print_change_data(struct wt_status
*s
,
227 struct string_list_item
*it
)
229 struct wt_status_change_data
*d
= it
->util
;
230 const char *c
= color(change_type
, s
);
234 const char *one
, *two
;
235 struct strbuf onebuf
= STRBUF_INIT
, twobuf
= STRBUF_INIT
;
236 struct strbuf extra
= STRBUF_INIT
;
238 one_name
= two_name
= it
->string
;
239 switch (change_type
) {
240 case WT_STATUS_UPDATED
:
241 status
= d
->index_status
;
243 one_name
= d
->head_path
;
245 case WT_STATUS_CHANGED
:
246 if (d
->new_submodule_commits
|| d
->dirty_submodule
) {
247 strbuf_addstr(&extra
, " (");
248 if (d
->new_submodule_commits
)
249 strbuf_addf(&extra
, _("new commits, "));
250 if (d
->dirty_submodule
& DIRTY_SUBMODULE_MODIFIED
)
251 strbuf_addf(&extra
, _("modified content, "));
252 if (d
->dirty_submodule
& DIRTY_SUBMODULE_UNTRACKED
)
253 strbuf_addf(&extra
, _("untracked content, "));
254 strbuf_setlen(&extra
, extra
.len
- 2);
255 strbuf_addch(&extra
, ')');
257 status
= d
->worktree_status
;
261 one
= quote_path(one_name
, -1, &onebuf
, s
->prefix
);
262 two
= quote_path(two_name
, -1, &twobuf
, s
->prefix
);
264 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
266 case DIFF_STATUS_ADDED
:
267 status_printf_more(s
, c
, _("new file: %s"), one
);
269 case DIFF_STATUS_COPIED
:
270 status_printf_more(s
, c
, _("copied: %s -> %s"), one
, two
);
272 case DIFF_STATUS_DELETED
:
273 status_printf_more(s
, c
, _("deleted: %s"), one
);
275 case DIFF_STATUS_MODIFIED
:
276 status_printf_more(s
, c
, _("modified: %s"), one
);
278 case DIFF_STATUS_RENAMED
:
279 status_printf_more(s
, c
, _("renamed: %s -> %s"), one
, two
);
281 case DIFF_STATUS_TYPE_CHANGED
:
282 status_printf_more(s
, c
, _("typechange: %s"), one
);
284 case DIFF_STATUS_UNKNOWN
:
285 status_printf_more(s
, c
, _("unknown: %s"), one
);
287 case DIFF_STATUS_UNMERGED
:
288 status_printf_more(s
, c
, _("unmerged: %s"), one
);
291 die(_("bug: unhandled diff status %c"), status
);
294 status_printf_more(s
, color(WT_STATUS_HEADER
, s
), "%s", extra
.buf
);
295 strbuf_release(&extra
);
297 status_printf_more(s
, GIT_COLOR_NORMAL
, "\n");
298 strbuf_release(&onebuf
);
299 strbuf_release(&twobuf
);
302 static void wt_status_collect_changed_cb(struct diff_queue_struct
*q
,
303 struct diff_options
*options
,
306 struct wt_status
*s
= data
;
311 s
->workdir_dirty
= 1;
312 for (i
= 0; i
< q
->nr
; i
++) {
313 struct diff_filepair
*p
;
314 struct string_list_item
*it
;
315 struct wt_status_change_data
*d
;
318 it
= string_list_insert(&s
->change
, p
->one
->path
);
321 d
= xcalloc(1, sizeof(*d
));
324 if (!d
->worktree_status
)
325 d
->worktree_status
= p
->status
;
326 d
->dirty_submodule
= p
->two
->dirty_submodule
;
327 if (S_ISGITLINK(p
->two
->mode
))
328 d
->new_submodule_commits
= !!hashcmp(p
->one
->sha1
, p
->two
->sha1
);
332 static int unmerged_mask(const char *path
)
335 struct cache_entry
*ce
;
337 pos
= cache_name_pos(path
, strlen(path
));
343 while (pos
< active_nr
) {
344 ce
= active_cache
[pos
++];
345 if (strcmp(ce
->name
, path
) || !ce_stage(ce
))
347 mask
|= (1 << (ce_stage(ce
) - 1));
352 static void wt_status_collect_updated_cb(struct diff_queue_struct
*q
,
353 struct diff_options
*options
,
356 struct wt_status
*s
= data
;
359 for (i
= 0; i
< q
->nr
; i
++) {
360 struct diff_filepair
*p
;
361 struct string_list_item
*it
;
362 struct wt_status_change_data
*d
;
365 it
= string_list_insert(&s
->change
, p
->two
->path
);
368 d
= xcalloc(1, sizeof(*d
));
371 if (!d
->index_status
)
372 d
->index_status
= p
->status
;
374 case DIFF_STATUS_COPIED
:
375 case DIFF_STATUS_RENAMED
:
376 d
->head_path
= xstrdup(p
->one
->path
);
378 case DIFF_STATUS_UNMERGED
:
379 d
->stagemask
= unmerged_mask(p
->two
->path
);
385 static void wt_status_collect_changes_worktree(struct wt_status
*s
)
389 init_revisions(&rev
, NULL
);
390 setup_revisions(0, NULL
, &rev
, NULL
);
391 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
392 DIFF_OPT_SET(&rev
.diffopt
, DIRTY_SUBMODULES
);
393 if (!s
->show_untracked_files
)
394 DIFF_OPT_SET(&rev
.diffopt
, IGNORE_UNTRACKED_IN_SUBMODULES
);
395 if (s
->ignore_submodule_arg
) {
396 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
397 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
399 rev
.diffopt
.format_callback
= wt_status_collect_changed_cb
;
400 rev
.diffopt
.format_callback_data
= s
;
401 init_pathspec(&rev
.prune_data
, s
->pathspec
);
402 run_diff_files(&rev
, 0);
405 static void wt_status_collect_changes_index(struct wt_status
*s
)
408 struct setup_revision_opt opt
;
410 init_revisions(&rev
, NULL
);
411 memset(&opt
, 0, sizeof(opt
));
412 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
413 setup_revisions(0, NULL
, &rev
, &opt
);
415 if (s
->ignore_submodule_arg
) {
416 DIFF_OPT_SET(&rev
.diffopt
, OVERRIDE_SUBMODULE_CONFIG
);
417 handle_ignore_submodules_arg(&rev
.diffopt
, s
->ignore_submodule_arg
);
420 rev
.diffopt
.output_format
|= DIFF_FORMAT_CALLBACK
;
421 rev
.diffopt
.format_callback
= wt_status_collect_updated_cb
;
422 rev
.diffopt
.format_callback_data
= s
;
423 rev
.diffopt
.detect_rename
= 1;
424 rev
.diffopt
.rename_limit
= 200;
425 rev
.diffopt
.break_opt
= 0;
426 init_pathspec(&rev
.prune_data
, s
->pathspec
);
427 run_diff_index(&rev
, 1);
430 static void wt_status_collect_changes_initial(struct wt_status
*s
)
432 struct pathspec pathspec
;
435 init_pathspec(&pathspec
, s
->pathspec
);
436 for (i
= 0; i
< active_nr
; i
++) {
437 struct string_list_item
*it
;
438 struct wt_status_change_data
*d
;
439 struct cache_entry
*ce
= active_cache
[i
];
441 if (!ce_path_match(ce
, &pathspec
))
443 it
= string_list_insert(&s
->change
, ce
->name
);
446 d
= xcalloc(1, sizeof(*d
));
450 d
->index_status
= DIFF_STATUS_UNMERGED
;
451 d
->stagemask
|= (1 << (ce_stage(ce
) - 1));
454 d
->index_status
= DIFF_STATUS_ADDED
;
456 free_pathspec(&pathspec
);
459 static void wt_status_collect_untracked(struct wt_status
*s
)
462 struct dir_struct dir
;
464 if (!s
->show_untracked_files
)
466 memset(&dir
, 0, sizeof(dir
));
467 if (s
->show_untracked_files
!= SHOW_ALL_UNTRACKED_FILES
)
469 DIR_SHOW_OTHER_DIRECTORIES
| DIR_HIDE_EMPTY_DIRECTORIES
;
470 setup_standard_excludes(&dir
);
472 fill_directory(&dir
, s
->pathspec
);
473 for (i
= 0; i
< dir
.nr
; i
++) {
474 struct dir_entry
*ent
= dir
.entries
[i
];
475 if (cache_name_is_other(ent
->name
, ent
->len
) &&
476 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
477 string_list_insert(&s
->untracked
, ent
->name
);
481 if (s
->show_ignored_files
) {
483 dir
.flags
= DIR_SHOW_IGNORED
| DIR_SHOW_OTHER_DIRECTORIES
;
484 fill_directory(&dir
, s
->pathspec
);
485 for (i
= 0; i
< dir
.nr
; i
++) {
486 struct dir_entry
*ent
= dir
.entries
[i
];
487 if (cache_name_is_other(ent
->name
, ent
->len
) &&
488 match_pathspec(s
->pathspec
, ent
->name
, ent
->len
, 0, NULL
))
489 string_list_insert(&s
->ignored
, ent
->name
);
497 void wt_status_collect(struct wt_status
*s
)
499 wt_status_collect_changes_worktree(s
);
502 wt_status_collect_changes_initial(s
);
504 wt_status_collect_changes_index(s
);
505 wt_status_collect_untracked(s
);
508 static void wt_status_print_unmerged(struct wt_status
*s
)
510 int shown_header
= 0;
513 for (i
= 0; i
< s
->change
.nr
; i
++) {
514 struct wt_status_change_data
*d
;
515 struct string_list_item
*it
;
516 it
= &(s
->change
.items
[i
]);
521 wt_status_print_unmerged_header(s
);
524 wt_status_print_unmerged_data(s
, it
);
527 wt_status_print_trailer(s
);
531 static void wt_status_print_updated(struct wt_status
*s
)
533 int shown_header
= 0;
536 for (i
= 0; i
< s
->change
.nr
; i
++) {
537 struct wt_status_change_data
*d
;
538 struct string_list_item
*it
;
539 it
= &(s
->change
.items
[i
]);
541 if (!d
->index_status
||
542 d
->index_status
== DIFF_STATUS_UNMERGED
)
545 wt_status_print_cached_header(s
);
549 wt_status_print_change_data(s
, WT_STATUS_UPDATED
, it
);
552 wt_status_print_trailer(s
);
558 * 1 : some change but no delete
560 static int wt_status_check_worktree_changes(struct wt_status
*s
,
561 int *dirty_submodules
)
566 *dirty_submodules
= 0;
568 for (i
= 0; i
< s
->change
.nr
; i
++) {
569 struct wt_status_change_data
*d
;
570 d
= s
->change
.items
[i
].util
;
571 if (!d
->worktree_status
||
572 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
576 if (d
->dirty_submodule
)
577 *dirty_submodules
= 1;
578 if (d
->worktree_status
== DIFF_STATUS_DELETED
)
584 static void wt_status_print_changed(struct wt_status
*s
)
586 int i
, dirty_submodules
;
587 int worktree_changes
= wt_status_check_worktree_changes(s
, &dirty_submodules
);
589 if (!worktree_changes
)
592 wt_status_print_dirty_header(s
, worktree_changes
< 0, dirty_submodules
);
594 for (i
= 0; i
< s
->change
.nr
; i
++) {
595 struct wt_status_change_data
*d
;
596 struct string_list_item
*it
;
597 it
= &(s
->change
.items
[i
]);
599 if (!d
->worktree_status
||
600 d
->worktree_status
== DIFF_STATUS_UNMERGED
)
602 wt_status_print_change_data(s
, WT_STATUS_CHANGED
, it
);
604 wt_status_print_trailer(s
);
607 static void wt_status_print_submodule_summary(struct wt_status
*s
, int uncommitted
)
609 struct child_process sm_summary
;
610 char summary_limit
[64];
611 char index
[PATH_MAX
];
612 const char *env
[] = { NULL
, NULL
};
616 argv
[0] = "submodule";
618 argv
[2] = uncommitted
? "--files" : "--cached";
619 argv
[3] = "--for-status";
620 argv
[4] = "--summary-limit";
621 argv
[5] = summary_limit
;
622 argv
[6] = uncommitted
? NULL
: (s
->amend
? "HEAD^" : "HEAD");
625 sprintf(summary_limit
, "%d", s
->submodule_summary
);
626 snprintf(index
, sizeof(index
), "GIT_INDEX_FILE=%s", s
->index_file
);
628 memset(&sm_summary
, 0, sizeof(sm_summary
));
629 sm_summary
.argv
= argv
;
630 sm_summary
.env
= env
;
631 sm_summary
.git_cmd
= 1;
632 sm_summary
.no_stdin
= 1;
634 sm_summary
.out
= dup(fileno(s
->fp
)); /* run_command closes it */
635 run_command(&sm_summary
);
638 static void wt_status_print_other(struct wt_status
*s
,
639 struct string_list
*l
,
644 struct strbuf buf
= STRBUF_INIT
;
645 static struct string_list output
= STRING_LIST_INIT_DUP
;
646 struct column_options copts
;
651 wt_status_print_other_header(s
, what
, how
);
653 for (i
= 0; i
< l
->nr
; i
++) {
654 struct string_list_item
*it
;
657 path
= quote_path(it
->string
, strlen(it
->string
),
659 if (column_active(s
->colopts
)) {
660 string_list_append(&output
, path
);
663 status_printf(s
, color(WT_STATUS_HEADER
, s
), "\t");
664 status_printf_more(s
, color(WT_STATUS_UNTRACKED
, s
),
668 strbuf_release(&buf
);
669 if (!column_active(s
->colopts
))
672 strbuf_addf(&buf
, "%s#\t%s",
673 color(WT_STATUS_HEADER
, s
),
674 color(WT_STATUS_UNTRACKED
, s
));
675 memset(&copts
, 0, sizeof(copts
));
677 copts
.indent
= buf
.buf
;
678 if (want_color(s
->use_color
))
679 copts
.nl
= GIT_COLOR_RESET
"\n";
680 print_columns(&output
, s
->colopts
, &copts
);
681 string_list_clear(&output
, 0);
682 strbuf_release(&buf
);
685 static void wt_status_print_verbose(struct wt_status
*s
)
688 struct setup_revision_opt opt
;
690 init_revisions(&rev
, NULL
);
691 DIFF_OPT_SET(&rev
.diffopt
, ALLOW_TEXTCONV
);
693 memset(&opt
, 0, sizeof(opt
));
694 opt
.def
= s
->is_initial
? EMPTY_TREE_SHA1_HEX
: s
->reference
;
695 setup_revisions(0, NULL
, &rev
, &opt
);
697 rev
.diffopt
.output_format
|= DIFF_FORMAT_PATCH
;
698 rev
.diffopt
.detect_rename
= 1;
699 rev
.diffopt
.file
= s
->fp
;
700 rev
.diffopt
.close_file
= 0;
702 * If we're not going to stdout, then we definitely don't
703 * want color, since we are going to the commit message
704 * file (and even the "auto" setting won't work, since it
705 * will have checked isatty on stdout).
708 rev
.diffopt
.use_color
= 0;
709 run_diff_index(&rev
, 1);
712 static void wt_status_print_tracking(struct wt_status
*s
)
714 struct strbuf sb
= STRBUF_INIT
;
716 struct branch
*branch
;
718 assert(s
->branch
&& !s
->is_initial
);
719 if (prefixcmp(s
->branch
, "refs/heads/"))
721 branch
= branch_get(s
->branch
+ 11);
722 if (!format_tracking_info(branch
, &sb
))
725 for (cp
= sb
.buf
; (ep
= strchr(cp
, '\n')) != NULL
; cp
= ep
+ 1)
726 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
),
727 "# %.*s", (int)(ep
- cp
), cp
);
728 color_fprintf_ln(s
->fp
, color(WT_STATUS_HEADER
, s
), "#");
731 void wt_status_print(struct wt_status
*s
)
733 const char *branch_color
= color(WT_STATUS_ONBRANCH
, s
);
734 const char *branch_status_color
= color(WT_STATUS_HEADER
, s
);
737 const char *on_what
= _("On branch ");
738 const char *branch_name
= s
->branch
;
739 if (!prefixcmp(branch_name
, "refs/heads/"))
741 else if (!strcmp(branch_name
, "HEAD")) {
743 branch_status_color
= color(WT_STATUS_NOBRANCH
, s
);
744 on_what
= _("Not currently on any branch.");
746 status_printf(s
, color(WT_STATUS_HEADER
, s
), "");
747 status_printf_more(s
, branch_status_color
, "%s", on_what
);
748 status_printf_more(s
, branch_color
, "%s\n", branch_name
);
750 wt_status_print_tracking(s
);
754 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
755 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), _("Initial commit"));
756 status_printf_ln(s
, color(WT_STATUS_HEADER
, s
), "");
759 wt_status_print_updated(s
);
760 wt_status_print_unmerged(s
);
761 wt_status_print_changed(s
);
762 if (s
->submodule_summary
&&
763 (!s
->ignore_submodule_arg
||
764 strcmp(s
->ignore_submodule_arg
, "all"))) {
765 wt_status_print_submodule_summary(s
, 0); /* staged */
766 wt_status_print_submodule_summary(s
, 1); /* unstaged */
768 if (s
->show_untracked_files
) {
769 wt_status_print_other(s
, &s
->untracked
, _("Untracked"), "add");
770 if (s
->show_ignored_files
)
771 wt_status_print_other(s
, &s
->ignored
, _("Ignored"), "add -f");
772 } else if (s
->commitable
)
773 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("Untracked files not listed%s"),
775 ? _(" (use -u option to show untracked files)") : "");
778 wt_status_print_verbose(s
);
779 if (!s
->commitable
) {
781 status_printf_ln(s
, GIT_COLOR_NORMAL
, _("No changes"));
784 else if (s
->workdir_dirty
)
785 printf(_("no changes added to commit%s\n"),
787 ? _(" (use \"git add\" and/or \"git commit -a\")") : "");
788 else if (s
->untracked
.nr
)
789 printf(_("nothing added to commit but untracked files present%s\n"),
791 ? _(" (use \"git add\" to track)") : "");
792 else if (s
->is_initial
)
793 printf(_("nothing to commit%s\n"), advice_status_hints
794 ? _(" (create/copy files and use \"git add\" to track)") : "");
795 else if (!s
->show_untracked_files
)
796 printf(_("nothing to commit%s\n"), advice_status_hints
797 ? _(" (use -u to show untracked files)") : "");
799 printf(_("nothing to commit%s\n"), advice_status_hints
800 ? _(" (working directory clean)") : "");
804 static void wt_shortstatus_unmerged(struct string_list_item
*it
,
807 struct wt_status_change_data
*d
= it
->util
;
808 const char *how
= "??";
810 switch (d
->stagemask
) {
811 case 1: how
= "DD"; break; /* both deleted */
812 case 2: how
= "AU"; break; /* added by us */
813 case 3: how
= "UD"; break; /* deleted by them */
814 case 4: how
= "UA"; break; /* added by them */
815 case 5: how
= "DU"; break; /* deleted by us */
816 case 6: how
= "AA"; break; /* both added */
817 case 7: how
= "UU"; break; /* both modified */
819 color_fprintf(s
->fp
, color(WT_STATUS_UNMERGED
, s
), "%s", how
);
820 if (s
->null_termination
) {
821 fprintf(stdout
, " %s%c", it
->string
, 0);
823 struct strbuf onebuf
= STRBUF_INIT
;
825 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
826 printf(" %s\n", one
);
827 strbuf_release(&onebuf
);
831 static void wt_shortstatus_status(struct string_list_item
*it
,
834 struct wt_status_change_data
*d
= it
->util
;
837 color_fprintf(s
->fp
, color(WT_STATUS_UPDATED
, s
), "%c", d
->index_status
);
840 if (d
->worktree_status
)
841 color_fprintf(s
->fp
, color(WT_STATUS_CHANGED
, s
), "%c", d
->worktree_status
);
845 if (s
->null_termination
) {
846 fprintf(stdout
, "%s%c", it
->string
, 0);
848 fprintf(stdout
, "%s%c", d
->head_path
, 0);
850 struct strbuf onebuf
= STRBUF_INIT
;
853 one
= quote_path(d
->head_path
, -1, &onebuf
, s
->prefix
);
854 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
856 strbuf_addch(&onebuf
, '"');
859 printf("%s -> ", one
);
860 strbuf_release(&onebuf
);
862 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
863 if (*one
!= '"' && strchr(one
, ' ') != NULL
) {
865 strbuf_addch(&onebuf
, '"');
869 strbuf_release(&onebuf
);
873 static void wt_shortstatus_other(struct string_list_item
*it
,
874 struct wt_status
*s
, const char *sign
)
876 if (s
->null_termination
) {
877 fprintf(stdout
, "%s %s%c", sign
, it
->string
, 0);
879 struct strbuf onebuf
= STRBUF_INIT
;
881 one
= quote_path(it
->string
, -1, &onebuf
, s
->prefix
);
882 color_fprintf(s
->fp
, color(WT_STATUS_UNTRACKED
, s
), "%s", sign
);
883 printf(" %s\n", one
);
884 strbuf_release(&onebuf
);
888 static void wt_shortstatus_print_tracking(struct wt_status
*s
)
890 struct branch
*branch
;
891 const char *header_color
= color(WT_STATUS_HEADER
, s
);
892 const char *branch_color_local
= color(WT_STATUS_LOCAL_BRANCH
, s
);
893 const char *branch_color_remote
= color(WT_STATUS_REMOTE_BRANCH
, s
);
896 const char *branch_name
;
897 int num_ours
, num_theirs
;
899 color_fprintf(s
->fp
, color(WT_STATUS_HEADER
, s
), "## ");
903 branch_name
= s
->branch
;
905 if (!prefixcmp(branch_name
, "refs/heads/"))
907 else if (!strcmp(branch_name
, "HEAD")) {
908 branch_name
= _("HEAD (no branch)");
909 branch_color_local
= color(WT_STATUS_NOBRANCH
, s
);
912 branch
= branch_get(s
->branch
+ 11);
914 color_fprintf(s
->fp
, header_color
, _("Initial commit on "));
915 if (!stat_tracking_info(branch
, &num_ours
, &num_theirs
)) {
916 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
917 fputc(s
->null_termination
? '\0' : '\n', s
->fp
);
921 base
= branch
->merge
[0]->dst
;
922 base
= shorten_unambiguous_ref(base
, 0);
923 color_fprintf(s
->fp
, branch_color_local
, "%s", branch_name
);
924 color_fprintf(s
->fp
, header_color
, "...");
925 color_fprintf(s
->fp
, branch_color_remote
, "%s", base
);
927 color_fprintf(s
->fp
, header_color
, " [");
929 color_fprintf(s
->fp
, header_color
, _("behind "));
930 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
931 } else if (!num_theirs
) {
932 color_fprintf(s
->fp
, header_color
, _("ahead "));
933 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
935 color_fprintf(s
->fp
, header_color
, _("ahead "));
936 color_fprintf(s
->fp
, branch_color_local
, "%d", num_ours
);
937 color_fprintf(s
->fp
, header_color
, _(", behind "));
938 color_fprintf(s
->fp
, branch_color_remote
, "%d", num_theirs
);
941 color_fprintf(s
->fp
, header_color
, "]");
942 fputc(s
->null_termination
? '\0' : '\n', s
->fp
);
945 void wt_shortstatus_print(struct wt_status
*s
)
950 wt_shortstatus_print_tracking(s
);
952 for (i
= 0; i
< s
->change
.nr
; i
++) {
953 struct wt_status_change_data
*d
;
954 struct string_list_item
*it
;
956 it
= &(s
->change
.items
[i
]);
959 wt_shortstatus_unmerged(it
, s
);
961 wt_shortstatus_status(it
, s
);
963 for (i
= 0; i
< s
->untracked
.nr
; i
++) {
964 struct string_list_item
*it
;
966 it
= &(s
->untracked
.items
[i
]);
967 wt_shortstatus_other(it
, s
, "??");
969 for (i
= 0; i
< s
->ignored
.nr
; i
++) {
970 struct string_list_item
*it
;
972 it
= &(s
->ignored
.items
[i
]);
973 wt_shortstatus_other(it
, s
, "!!");
977 void wt_porcelain_print(struct wt_status
*s
)
980 s
->relative_paths
= 0;
982 wt_shortstatus_print(s
);