10 #include "run-command.h"
11 #include "argv-array.h"
14 #include "submodule.h"
20 #include "sequencer.h"
22 static const char cut_line[] =
23 "------------------------ >8 ------------------------\n";
25 static char default_wt_status_colors[][COLOR_MAXLEN] = {
26 GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
27 GIT_COLOR_GREEN, /* WT_STATUS_UPDATED */
28 GIT_COLOR_RED, /* WT_STATUS_CHANGED */
29 GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */
30 GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */
31 GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
32 GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
33 GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
34 GIT_COLOR_NIL, /* WT_STATUS_ONBRANCH */
37 static const char *color(int slot, struct wt_status *s)
40 if (want_color(s->use_color))
41 c = s->color_palette[slot];
42 if (slot == WT_STATUS_ONBRANCH && color_is_nil(c))
43 c = s->color_palette[WT_STATUS_HEADER];
47 static void status_vprintf(struct wt_status *s, int at_bol, const char *color,
48 const char *fmt, va_list ap, const char *trail)
50 struct strbuf sb = STRBUF_INIT;
51 struct strbuf linebuf = STRBUF_INIT;
52 const char *line, *eol;
54 strbuf_vaddf(&sb, fmt, ap);
56 if (s->display_comment_prefix) {
57 strbuf_addch(&sb, comment_line_char);
59 strbuf_addch(&sb, ' ');
61 color_print_strbuf(s->fp, color, &sb);
63 fprintf(s->fp, "%s", trail);
67 for (line = sb.buf; *line; line = eol + 1) {
68 eol = strchr(line, '\n');
70 strbuf_reset(&linebuf);
71 if (at_bol && s->display_comment_prefix) {
72 strbuf_addch(&linebuf, comment_line_char);
73 if (*line != '\n' && *line != '\t')
74 strbuf_addch(&linebuf, ' ');
77 strbuf_add(&linebuf, line, eol - line);
79 strbuf_addstr(&linebuf, line);
80 color_print_strbuf(s->fp, color, &linebuf);
88 fprintf(s->fp, "%s", trail);
89 strbuf_release(&linebuf);
93 void status_printf_ln(struct wt_status *s, const char *color,
99 status_vprintf(s, 1, color, fmt, ap, "\n");
103 void status_printf(struct wt_status *s, const char *color,
104 const char *fmt, ...)
109 status_vprintf(s, 1, color, fmt, ap, NULL);
113 static void status_printf_more(struct wt_status *s, const char *color,
114 const char *fmt, ...)
119 status_vprintf(s, 0, color, fmt, ap, NULL);
123 void wt_status_prepare(struct repository *r, struct wt_status *s)
125 memset(s, 0, sizeof(*s));
127 memcpy(s->color_palette, default_wt_status_colors,
128 sizeof(default_wt_status_colors));
129 s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
131 s->relative_paths = 1;
132 s->branch = resolve_refdup("HEAD", 0, NULL, NULL);
133 s->reference = "HEAD";
135 s->index_file = get_index_file();
136 s->change.strdup_strings = 1;
137 s->untracked.strdup_strings = 1;
138 s->ignored.strdup_strings = 1;
139 s->show_branch = -1; /* unspecified */
141 s->ahead_behind_flags = AHEAD_BEHIND_UNSPECIFIED;
142 s->display_comment_prefix = 0;
143 s->detect_rename = -1;
144 s->rename_score = -1;
145 s->rename_limit = -1;
148 static void wt_longstatus_print_unmerged_header(struct wt_status *s)
151 int del_mod_conflict = 0;
152 int both_deleted = 0;
154 const char *c = color(WT_STATUS_HEADER, s);
156 status_printf_ln(s, c, _("Unmerged paths:"));
158 for (i = 0; i < s->change.nr; i++) {
159 struct string_list_item *it = &(s->change.items[i]);
160 struct wt_status_change_data *d = it->util;
162 switch (d->stagemask) {
170 del_mod_conflict = 1;
180 if (s->whence != FROM_COMMIT)
182 else if (!s->is_initial)
183 status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference);
185 status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)"));
188 if (!del_mod_conflict)
189 status_printf_ln(s, c, _(" (use \"git add <file>...\" to mark resolution)"));
191 status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
192 } else if (!del_mod_conflict && !not_deleted) {
193 status_printf_ln(s, c, _(" (use \"git rm <file>...\" to mark resolution)"));
195 status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
197 status_printf_ln(s, c, "%s", "");
200 static void wt_longstatus_print_cached_header(struct wt_status *s)
202 const char *c = color(WT_STATUS_HEADER, s);
204 status_printf_ln(s, c, _("Changes to be committed:"));
207 if (s->whence != FROM_COMMIT)
208 ; /* NEEDSWORK: use "git reset --unresolve"??? */
209 else if (!s->is_initial)
210 status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference);
212 status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)"));
213 status_printf_ln(s, c, "%s", "");
216 static void wt_longstatus_print_dirty_header(struct wt_status *s,
218 int has_dirty_submodules)
220 const char *c = color(WT_STATUS_HEADER, s);
222 status_printf_ln(s, c, _("Changes not staged for commit:"));
226 status_printf_ln(s, c, _(" (use \"git add <file>...\" to update what will be committed)"));
228 status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" to update what will be committed)"));
229 status_printf_ln(s, c, _(" (use \"git checkout -- <file>...\" to discard changes in working directory)"));
230 if (has_dirty_submodules)
231 status_printf_ln(s, c, _(" (commit or discard the untracked or modified content in submodules)"));
232 status_printf_ln(s, c, "%s", "");
235 static void wt_longstatus_print_other_header(struct wt_status *s,
239 const char *c = color(WT_STATUS_HEADER, s);
240 status_printf_ln(s, c, "%s:", what);
243 status_printf_ln(s, c, _(" (use \"git %s <file>...\" to include in what will be committed)"), how);
244 status_printf_ln(s, c, "%s", "");
247 static void wt_longstatus_print_trailer(struct wt_status *s)
249 status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
252 #define quote_path quote_path_relative
254 static const char *wt_status_unmerged_status_string(int stagemask)
258 return _("both deleted:");
260 return _("added by us:");
262 return _("deleted by them:");
264 return _("added by them:");
266 return _("deleted by us:");
268 return _("both added:");
270 return _("both modified:");
272 BUG("unhandled unmerged status %x", stagemask);
276 static const char *wt_status_diff_status_string(int status)
279 case DIFF_STATUS_ADDED:
280 return _("new file:");
281 case DIFF_STATUS_COPIED:
283 case DIFF_STATUS_DELETED:
284 return _("deleted:");
285 case DIFF_STATUS_MODIFIED:
286 return _("modified:");
287 case DIFF_STATUS_RENAMED:
288 return _("renamed:");
289 case DIFF_STATUS_TYPE_CHANGED:
290 return _("typechange:");
291 case DIFF_STATUS_UNKNOWN:
292 return _("unknown:");
293 case DIFF_STATUS_UNMERGED:
294 return _("unmerged:");
300 static int maxwidth(const char *(*label)(int), int minval, int maxval)
304 for (i = minval; i <= maxval; i++) {
305 const char *s = label(i);
306 int len = s ? utf8_strwidth(s) : 0;
313 static void wt_longstatus_print_unmerged_data(struct wt_status *s,
314 struct string_list_item *it)
316 const char *c = color(WT_STATUS_UNMERGED, s);
317 struct wt_status_change_data *d = it->util;
318 struct strbuf onebuf = STRBUF_INIT;
319 static char *padding;
320 static int label_width;
321 const char *one, *how;
325 label_width = maxwidth(wt_status_unmerged_status_string, 1, 7);
326 label_width += strlen(" ");
327 padding = xmallocz(label_width);
328 memset(padding, ' ', label_width);
331 one = quote_path(it->string, s->prefix, &onebuf);
332 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
334 how = wt_status_unmerged_status_string(d->stagemask);
335 len = label_width - utf8_strwidth(how);
336 status_printf_more(s, c, "%s%.*s%s\n", how, len, padding, one);
337 strbuf_release(&onebuf);
340 static void wt_longstatus_print_change_data(struct wt_status *s,
342 struct string_list_item *it)
344 struct wt_status_change_data *d = it->util;
345 const char *c = color(change_type, s);
349 const char *one, *two;
350 struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
351 struct strbuf extra = STRBUF_INIT;
352 static char *padding;
353 static int label_width;
358 /* If DIFF_STATUS_* uses outside the range [A..Z], we're in trouble */
359 label_width = maxwidth(wt_status_diff_status_string, 'A', 'Z');
360 label_width += strlen(" ");
361 padding = xmallocz(label_width);
362 memset(padding, ' ', label_width);
365 one_name = two_name = it->string;
366 switch (change_type) {
367 case WT_STATUS_UPDATED:
368 status = d->index_status;
370 case WT_STATUS_CHANGED:
371 if (d->new_submodule_commits || d->dirty_submodule) {
372 strbuf_addstr(&extra, " (");
373 if (d->new_submodule_commits)
374 strbuf_addstr(&extra, _("new commits, "));
375 if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
376 strbuf_addstr(&extra, _("modified content, "));
377 if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
378 strbuf_addstr(&extra, _("untracked content, "));
379 strbuf_setlen(&extra, extra.len - 2);
380 strbuf_addch(&extra, ')');
382 status = d->worktree_status;
385 BUG("unhandled change_type %d in wt_longstatus_print_change_data",
390 * Only pick up the rename it's relevant. If the rename is for
391 * the changed section and we're printing the updated section,
394 if (d->rename_status == status)
395 one_name = d->rename_source;
397 one = quote_path(one_name, s->prefix, &onebuf);
398 two = quote_path(two_name, s->prefix, &twobuf);
400 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
401 what = wt_status_diff_status_string(status);
403 BUG("unhandled diff status %c", status);
404 len = label_width - utf8_strwidth(what);
406 if (one_name != two_name)
407 status_printf_more(s, c, "%s%.*s%s -> %s",
408 what, len, padding, one, two);
410 status_printf_more(s, c, "%s%.*s%s",
411 what, len, padding, one);
413 status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
414 strbuf_release(&extra);
416 status_printf_more(s, GIT_COLOR_NORMAL, "\n");
417 strbuf_release(&onebuf);
418 strbuf_release(&twobuf);
421 static char short_submodule_status(struct wt_status_change_data *d)
423 if (d->new_submodule_commits)
425 if (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED)
427 if (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED)
429 return d->worktree_status;
432 static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
433 struct diff_options *options,
436 struct wt_status *s = data;
441 s->workdir_dirty = 1;
442 for (i = 0; i < q->nr; i++) {
443 struct diff_filepair *p;
444 struct string_list_item *it;
445 struct wt_status_change_data *d;
448 it = string_list_insert(&s->change, p->two->path);
451 d = xcalloc(1, sizeof(*d));
454 if (!d->worktree_status)
455 d->worktree_status = p->status;
456 if (S_ISGITLINK(p->two->mode)) {
457 d->dirty_submodule = p->two->dirty_submodule;
458 d->new_submodule_commits = !oideq(&p->one->oid,
460 if (s->status_format == STATUS_FORMAT_SHORT)
461 d->worktree_status = short_submodule_status(d);
465 case DIFF_STATUS_ADDED:
466 d->mode_worktree = p->two->mode;
469 case DIFF_STATUS_DELETED:
470 d->mode_index = p->one->mode;
471 oidcpy(&d->oid_index, &p->one->oid);
472 /* mode_worktree is zero for a delete. */
475 case DIFF_STATUS_COPIED:
476 case DIFF_STATUS_RENAMED:
477 if (d->rename_status)
478 BUG("multiple renames on the same target? how?");
479 d->rename_source = xstrdup(p->one->path);
480 d->rename_score = p->score * 100 / MAX_SCORE;
481 d->rename_status = p->status;
483 case DIFF_STATUS_MODIFIED:
484 case DIFF_STATUS_TYPE_CHANGED:
485 case DIFF_STATUS_UNMERGED:
486 d->mode_index = p->one->mode;
487 d->mode_worktree = p->two->mode;
488 oidcpy(&d->oid_index, &p->one->oid);
492 BUG("unhandled diff-files status '%c'", p->status);
499 static int unmerged_mask(struct index_state *istate, const char *path)
502 const struct cache_entry *ce;
504 pos = index_name_pos(istate, path, strlen(path));
510 while (pos < istate->cache_nr) {
511 ce = istate->cache[pos++];
512 if (strcmp(ce->name, path) || !ce_stage(ce))
514 mask |= (1 << (ce_stage(ce) - 1));
519 static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
520 struct diff_options *options,
523 struct wt_status *s = data;
526 for (i = 0; i < q->nr; i++) {
527 struct diff_filepair *p;
528 struct string_list_item *it;
529 struct wt_status_change_data *d;
532 it = string_list_insert(&s->change, p->two->path);
535 d = xcalloc(1, sizeof(*d));
538 if (!d->index_status)
539 d->index_status = p->status;
541 case DIFF_STATUS_ADDED:
542 /* Leave {mode,oid}_head zero for an add. */
543 d->mode_index = p->two->mode;
544 oidcpy(&d->oid_index, &p->two->oid);
547 case DIFF_STATUS_DELETED:
548 d->mode_head = p->one->mode;
549 oidcpy(&d->oid_head, &p->one->oid);
551 /* Leave {mode,oid}_index zero for a delete. */
554 case DIFF_STATUS_COPIED:
555 case DIFF_STATUS_RENAMED:
556 if (d->rename_status)
557 BUG("multiple renames on the same target? how?");
558 d->rename_source = xstrdup(p->one->path);
559 d->rename_score = p->score * 100 / MAX_SCORE;
560 d->rename_status = p->status;
562 case DIFF_STATUS_MODIFIED:
563 case DIFF_STATUS_TYPE_CHANGED:
564 d->mode_head = p->one->mode;
565 d->mode_index = p->two->mode;
566 oidcpy(&d->oid_head, &p->one->oid);
567 oidcpy(&d->oid_index, &p->two->oid);
570 case DIFF_STATUS_UNMERGED:
571 d->stagemask = unmerged_mask(s->repo->index,
574 * Don't bother setting {mode,oid}_{head,index} since the print
575 * code will output the stage values directly and not use the
576 * values in these fields.
581 BUG("unhandled diff-index status '%c'", p->status);
587 static void wt_status_collect_changes_worktree(struct wt_status *s)
591 repo_init_revisions(s->repo, &rev, NULL);
592 setup_revisions(0, NULL, &rev, NULL);
593 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
594 rev.diffopt.flags.dirty_submodules = 1;
595 rev.diffopt.ita_invisible_in_index = 1;
596 if (!s->show_untracked_files)
597 rev.diffopt.flags.ignore_untracked_in_submodules = 1;
598 if (s->ignore_submodule_arg) {
599 rev.diffopt.flags.override_submodule_config = 1;
600 handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
602 rev.diffopt.format_callback = wt_status_collect_changed_cb;
603 rev.diffopt.format_callback_data = s;
604 rev.diffopt.detect_rename = s->detect_rename >= 0 ? s->detect_rename : rev.diffopt.detect_rename;
605 rev.diffopt.rename_limit = s->rename_limit >= 0 ? s->rename_limit : rev.diffopt.rename_limit;
606 rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
607 copy_pathspec(&rev.prune_data, &s->pathspec);
608 run_diff_files(&rev, 0);
611 static void wt_status_collect_changes_index(struct wt_status *s)
614 struct setup_revision_opt opt;
616 repo_init_revisions(s->repo, &rev, NULL);
617 memset(&opt, 0, sizeof(opt));
618 opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
619 setup_revisions(0, NULL, &rev, &opt);
621 rev.diffopt.flags.override_submodule_config = 1;
622 rev.diffopt.ita_invisible_in_index = 1;
623 if (s->ignore_submodule_arg) {
624 handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
627 * Unless the user did explicitly request a submodule ignore
628 * mode by passing a command line option we do not ignore any
629 * changed submodule SHA-1s when comparing index and HEAD, no
630 * matter what is configured. Otherwise the user won't be
631 * shown any submodules she manually added (and which are
632 * staged to be committed), which would be really confusing.
634 handle_ignore_submodules_arg(&rev.diffopt, "dirty");
637 rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
638 rev.diffopt.format_callback = wt_status_collect_updated_cb;
639 rev.diffopt.format_callback_data = s;
640 rev.diffopt.detect_rename = s->detect_rename >= 0 ? s->detect_rename : rev.diffopt.detect_rename;
641 rev.diffopt.rename_limit = s->rename_limit >= 0 ? s->rename_limit : rev.diffopt.rename_limit;
642 rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
643 copy_pathspec(&rev.prune_data, &s->pathspec);
644 run_diff_index(&rev, 1);
647 static void wt_status_collect_changes_initial(struct wt_status *s)
649 struct index_state *istate = s->repo->index;
652 for (i = 0; i < istate->cache_nr; i++) {
653 struct string_list_item *it;
654 struct wt_status_change_data *d;
655 const struct cache_entry *ce = istate->cache[i];
657 if (!ce_path_match(istate, ce, &s->pathspec, NULL))
659 if (ce_intent_to_add(ce))
661 it = string_list_insert(&s->change, ce->name);
664 d = xcalloc(1, sizeof(*d));
668 d->index_status = DIFF_STATUS_UNMERGED;
669 d->stagemask |= (1 << (ce_stage(ce) - 1));
671 * Don't bother setting {mode,oid}_{head,index} since the print
672 * code will output the stage values directly and not use the
673 * values in these fields.
677 d->index_status = DIFF_STATUS_ADDED;
678 /* Leave {mode,oid}_head zero for adds. */
679 d->mode_index = ce->ce_mode;
680 oidcpy(&d->oid_index, &ce->oid);
686 static void wt_status_collect_untracked(struct wt_status *s)
689 struct dir_struct dir;
690 uint64_t t_begin = getnanotime();
691 struct index_state *istate = s->repo->index;
693 if (!s->show_untracked_files)
696 memset(&dir, 0, sizeof(dir));
697 if (s->show_untracked_files != SHOW_ALL_UNTRACKED_FILES)
699 DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
700 if (s->show_ignored_mode) {
701 dir.flags |= DIR_SHOW_IGNORED_TOO;
703 if (s->show_ignored_mode == SHOW_MATCHING_IGNORED)
704 dir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING;
706 dir.untracked = istate->untracked;
709 setup_standard_excludes(&dir);
711 fill_directory(&dir, istate, &s->pathspec);
713 for (i = 0; i < dir.nr; i++) {
714 struct dir_entry *ent = dir.entries[i];
715 if (index_name_is_other(istate, ent->name, ent->len) &&
716 dir_path_match(istate, ent, &s->pathspec, 0, NULL))
717 string_list_insert(&s->untracked, ent->name);
721 for (i = 0; i < dir.ignored_nr; i++) {
722 struct dir_entry *ent = dir.ignored[i];
723 if (index_name_is_other(istate, ent->name, ent->len) &&
724 dir_path_match(istate, ent, &s->pathspec, 0, NULL))
725 string_list_insert(&s->ignored, ent->name);
731 clear_directory(&dir);
733 if (advice_status_u_option)
734 s->untracked_in_ms = (getnanotime() - t_begin) / 1000000;
737 static int has_unmerged(struct wt_status *s)
741 for (i = 0; i < s->change.nr; i++) {
742 struct wt_status_change_data *d;
743 d = s->change.items[i].util;
750 void wt_status_collect(struct wt_status *s)
752 wt_status_collect_changes_worktree(s);
754 wt_status_collect_changes_initial(s);
756 wt_status_collect_changes_index(s);
757 wt_status_collect_untracked(s);
759 wt_status_get_state(s->repo, &s->state, s->branch && !strcmp(s->branch, "HEAD"));
760 if (s->state.merge_in_progress && !has_unmerged(s))
764 void wt_status_collect_free_buffers(struct wt_status *s)
766 free(s->state.branch);
768 free(s->state.detached_from);
771 static void wt_longstatus_print_unmerged(struct wt_status *s)
773 int shown_header = 0;
776 for (i = 0; i < s->change.nr; i++) {
777 struct wt_status_change_data *d;
778 struct string_list_item *it;
779 it = &(s->change.items[i]);
784 wt_longstatus_print_unmerged_header(s);
787 wt_longstatus_print_unmerged_data(s, it);
790 wt_longstatus_print_trailer(s);
794 static void wt_longstatus_print_updated(struct wt_status *s)
796 int shown_header = 0;
799 for (i = 0; i < s->change.nr; i++) {
800 struct wt_status_change_data *d;
801 struct string_list_item *it;
802 it = &(s->change.items[i]);
804 if (!d->index_status ||
805 d->index_status == DIFF_STATUS_UNMERGED)
808 wt_longstatus_print_cached_header(s);
811 wt_longstatus_print_change_data(s, WT_STATUS_UPDATED, it);
814 wt_longstatus_print_trailer(s);
820 * 1 : some change but no delete
822 static int wt_status_check_worktree_changes(struct wt_status *s,
823 int *dirty_submodules)
828 *dirty_submodules = 0;
830 for (i = 0; i < s->change.nr; i++) {
831 struct wt_status_change_data *d;
832 d = s->change.items[i].util;
833 if (!d->worktree_status ||
834 d->worktree_status == DIFF_STATUS_UNMERGED)
838 if (d->dirty_submodule)
839 *dirty_submodules = 1;
840 if (d->worktree_status == DIFF_STATUS_DELETED)
846 static void wt_longstatus_print_changed(struct wt_status *s)
848 int i, dirty_submodules;
849 int worktree_changes = wt_status_check_worktree_changes(s, &dirty_submodules);
851 if (!worktree_changes)
854 wt_longstatus_print_dirty_header(s, worktree_changes < 0, dirty_submodules);
856 for (i = 0; i < s->change.nr; i++) {
857 struct wt_status_change_data *d;
858 struct string_list_item *it;
859 it = &(s->change.items[i]);
861 if (!d->worktree_status ||
862 d->worktree_status == DIFF_STATUS_UNMERGED)
864 wt_longstatus_print_change_data(s, WT_STATUS_CHANGED, it);
866 wt_longstatus_print_trailer(s);
869 static int stash_count_refs(struct object_id *ooid, struct object_id *noid,
870 const char *email, timestamp_t timestamp, int tz,
871 const char *message, void *cb_data)
878 static void wt_longstatus_print_stash_summary(struct wt_status *s)
882 for_each_reflog_ent("refs/stash", stash_count_refs, &stash_count);
884 status_printf_ln(s, GIT_COLOR_NORMAL,
885 Q_("Your stash currently has %d entry",
886 "Your stash currently has %d entries", stash_count),
890 static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncommitted)
892 struct child_process sm_summary = CHILD_PROCESS_INIT;
893 struct strbuf cmd_stdout = STRBUF_INIT;
894 struct strbuf summary = STRBUF_INIT;
895 char *summary_content;
897 argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s",
900 argv_array_push(&sm_summary.args, "submodule");
901 argv_array_push(&sm_summary.args, "summary");
902 argv_array_push(&sm_summary.args, uncommitted ? "--files" : "--cached");
903 argv_array_push(&sm_summary.args, "--for-status");
904 argv_array_push(&sm_summary.args, "--summary-limit");
905 argv_array_pushf(&sm_summary.args, "%d", s->submodule_summary);
907 argv_array_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD");
909 sm_summary.git_cmd = 1;
910 sm_summary.no_stdin = 1;
912 capture_command(&sm_summary, &cmd_stdout, 1024);
914 /* prepend header, only if there's an actual output */
915 if (cmd_stdout.len) {
917 strbuf_addstr(&summary, _("Submodules changed but not updated:"));
919 strbuf_addstr(&summary, _("Submodule changes to be committed:"));
920 strbuf_addstr(&summary, "\n\n");
922 strbuf_addbuf(&summary, &cmd_stdout);
923 strbuf_release(&cmd_stdout);
925 if (s->display_comment_prefix) {
927 summary_content = strbuf_detach(&summary, &len);
928 strbuf_add_commented_lines(&summary, summary_content, len);
929 free(summary_content);
932 fputs(summary.buf, s->fp);
933 strbuf_release(&summary);
936 static void wt_longstatus_print_other(struct wt_status *s,
937 struct string_list *l,
942 struct strbuf buf = STRBUF_INIT;
943 static struct string_list output = STRING_LIST_INIT_DUP;
944 struct column_options copts;
949 wt_longstatus_print_other_header(s, what, how);
951 for (i = 0; i < l->nr; i++) {
952 struct string_list_item *it;
955 path = quote_path(it->string, s->prefix, &buf);
956 if (column_active(s->colopts)) {
957 string_list_append(&output, path);
960 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
961 status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
965 strbuf_release(&buf);
966 if (!column_active(s->colopts))
969 strbuf_addf(&buf, "%s%s\t%s",
970 color(WT_STATUS_HEADER, s),
971 s->display_comment_prefix ? "#" : "",
972 color(WT_STATUS_UNTRACKED, s));
973 memset(&copts, 0, sizeof(copts));
975 copts.indent = buf.buf;
976 if (want_color(s->use_color))
977 copts.nl = GIT_COLOR_RESET "\n";
978 print_columns(&output, s->colopts, &copts);
979 string_list_clear(&output, 0);
980 strbuf_release(&buf);
982 status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
985 size_t wt_status_locate_end(const char *s, size_t len)
988 struct strbuf pattern = STRBUF_INIT;
990 strbuf_addf(&pattern, "\n%c %s", comment_line_char, cut_line);
991 if (starts_with(s, pattern.buf + 1))
993 else if ((p = strstr(s, pattern.buf)))
995 strbuf_release(&pattern);
999 void wt_status_add_cut_line(FILE *fp)
1001 const char *explanation = _("Do not modify or remove the line above.\nEverything below it will be ignored.");
1002 struct strbuf buf = STRBUF_INIT;
1004 fprintf(fp, "%c %s", comment_line_char, cut_line);
1005 strbuf_add_commented_lines(&buf, explanation, strlen(explanation));
1007 strbuf_release(&buf);
1010 static void wt_longstatus_print_verbose(struct wt_status *s)
1012 struct rev_info rev;
1013 struct setup_revision_opt opt;
1014 int dirty_submodules;
1015 const char *c = color(WT_STATUS_HEADER, s);
1017 repo_init_revisions(s->repo, &rev, NULL);
1018 rev.diffopt.flags.allow_textconv = 1;
1019 rev.diffopt.ita_invisible_in_index = 1;
1021 memset(&opt, 0, sizeof(opt));
1022 opt.def = s->is_initial ? empty_tree_oid_hex() : s->reference;
1023 setup_revisions(0, NULL, &rev, &opt);
1025 rev.diffopt.output_format |= DIFF_FORMAT_PATCH;
1026 rev.diffopt.detect_rename = s->detect_rename >= 0 ? s->detect_rename : rev.diffopt.detect_rename;
1027 rev.diffopt.rename_limit = s->rename_limit >= 0 ? s->rename_limit : rev.diffopt.rename_limit;
1028 rev.diffopt.rename_score = s->rename_score >= 0 ? s->rename_score : rev.diffopt.rename_score;
1029 rev.diffopt.file = s->fp;
1030 rev.diffopt.close_file = 0;
1032 * If we're not going to stdout, then we definitely don't
1033 * want color, since we are going to the commit message
1034 * file (and even the "auto" setting won't work, since it
1035 * will have checked isatty on stdout). But we then do want
1036 * to insert the scissor line here to reliably remove the
1037 * diff before committing.
1039 if (s->fp != stdout) {
1040 rev.diffopt.use_color = 0;
1041 wt_status_add_cut_line(s->fp);
1043 if (s->verbose > 1 && s->committable) {
1044 /* print_updated() printed a header, so do we */
1045 if (s->fp != stdout)
1046 wt_longstatus_print_trailer(s);
1047 status_printf_ln(s, c, _("Changes to be committed:"));
1048 rev.diffopt.a_prefix = "c/";
1049 rev.diffopt.b_prefix = "i/";
1050 } /* else use prefix as per user config */
1051 run_diff_index(&rev, 1);
1052 if (s->verbose > 1 &&
1053 wt_status_check_worktree_changes(s, &dirty_submodules)) {
1054 status_printf_ln(s, c,
1055 "--------------------------------------------------");
1056 status_printf_ln(s, c, _("Changes not staged for commit:"));
1058 rev.diffopt.a_prefix = "i/";
1059 rev.diffopt.b_prefix = "w/";
1060 run_diff_files(&rev, 0);
1064 static void wt_longstatus_print_tracking(struct wt_status *s)
1066 struct strbuf sb = STRBUF_INIT;
1067 const char *cp, *ep, *branch_name;
1068 struct branch *branch;
1069 char comment_line_string[3];
1072 assert(s->branch && !s->is_initial);
1073 if (!skip_prefix(s->branch, "refs/heads/", &branch_name))
1075 branch = branch_get(branch_name);
1076 if (!format_tracking_info(branch, &sb, s->ahead_behind_flags))
1080 if (s->display_comment_prefix) {
1081 comment_line_string[i++] = comment_line_char;
1082 comment_line_string[i++] = ' ';
1084 comment_line_string[i] = '\0';
1086 for (cp = sb.buf; (ep = strchr(cp, '\n')) != NULL; cp = ep + 1)
1087 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s),
1088 "%s%.*s", comment_line_string,
1089 (int)(ep - cp), cp);
1090 if (s->display_comment_prefix)
1091 color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
1095 strbuf_release(&sb);
1098 static void show_merge_in_progress(struct wt_status *s,
1101 if (has_unmerged(s)) {
1102 status_printf_ln(s, color, _("You have unmerged paths."));
1104 status_printf_ln(s, color,
1105 _(" (fix conflicts and run \"git commit\")"));
1106 status_printf_ln(s, color,
1107 _(" (use \"git merge --abort\" to abort the merge)"));
1110 status_printf_ln(s, color,
1111 _("All conflicts fixed but you are still merging."));
1113 status_printf_ln(s, color,
1114 _(" (use \"git commit\" to conclude merge)"));
1116 wt_longstatus_print_trailer(s);
1119 static void show_am_in_progress(struct wt_status *s,
1122 status_printf_ln(s, color,
1123 _("You are in the middle of an am session."));
1124 if (s->state.am_empty_patch)
1125 status_printf_ln(s, color,
1126 _("The current patch is empty."));
1128 if (!s->state.am_empty_patch)
1129 status_printf_ln(s, color,
1130 _(" (fix conflicts and then run \"git am --continue\")"));
1131 status_printf_ln(s, color,
1132 _(" (use \"git am --skip\" to skip this patch)"));
1133 status_printf_ln(s, color,
1134 _(" (use \"git am --abort\" to restore the original branch)"));
1136 wt_longstatus_print_trailer(s);
1139 static char *read_line_from_git_path(const char *filename)
1141 struct strbuf buf = STRBUF_INIT;
1142 FILE *fp = fopen_or_warn(git_path("%s", filename), "r");
1145 strbuf_release(&buf);
1148 strbuf_getline_lf(&buf, fp);
1150 return strbuf_detach(&buf, NULL);
1152 strbuf_release(&buf);
1157 static int split_commit_in_progress(struct wt_status *s)
1159 int split_in_progress = 0;
1160 char *head, *orig_head, *rebase_amend, *rebase_orig_head;
1162 if ((!s->amend && !s->nowarn && !s->workdir_dirty) ||
1163 !s->branch || strcmp(s->branch, "HEAD"))
1166 head = read_line_from_git_path("HEAD");
1167 orig_head = read_line_from_git_path("ORIG_HEAD");
1168 rebase_amend = read_line_from_git_path("rebase-merge/amend");
1169 rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
1171 if (!head || !orig_head || !rebase_amend || !rebase_orig_head)
1172 ; /* fall through, no split in progress */
1173 else if (!strcmp(rebase_amend, rebase_orig_head))
1174 split_in_progress = !!strcmp(head, rebase_amend);
1175 else if (strcmp(orig_head, rebase_orig_head))
1176 split_in_progress = 1;
1181 free(rebase_orig_head);
1183 return split_in_progress;
1188 * "pick d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some message"
1190 * "pick d6a2f03 some message"
1192 * The function assumes that the line does not contain useless spaces
1193 * before or after the command.
1195 static void abbrev_sha1_in_line(struct strbuf *line)
1197 struct strbuf **split;
1200 if (starts_with(line->buf, "exec ") ||
1201 starts_with(line->buf, "x "))
1204 split = strbuf_split_max(line, ' ', 3);
1205 if (split[0] && split[1]) {
1206 struct object_id oid;
1209 * strbuf_split_max left a space. Trim it and re-add
1210 * it after abbreviation.
1212 strbuf_trim(split[1]);
1213 if (!get_oid(split[1]->buf, &oid)) {
1214 strbuf_reset(split[1]);
1215 strbuf_add_unique_abbrev(split[1], &oid,
1217 strbuf_addch(split[1], ' ');
1219 for (i = 0; split[i]; i++)
1220 strbuf_addbuf(line, split[i]);
1223 strbuf_list_free(split);
1226 static int read_rebase_todolist(const char *fname, struct string_list *lines)
1228 struct strbuf line = STRBUF_INIT;
1229 FILE *f = fopen(git_path("%s", fname), "r");
1232 if (errno == ENOENT)
1234 die_errno("Could not open file %s for reading",
1235 git_path("%s", fname));
1237 while (!strbuf_getline_lf(&line, f)) {
1238 if (line.len && line.buf[0] == comment_line_char)
1243 abbrev_sha1_in_line(&line);
1244 string_list_append(lines, line.buf);
1247 strbuf_release(&line);
1251 static void show_rebase_information(struct wt_status *s,
1254 if (s->state.rebase_interactive_in_progress) {
1256 int nr_lines_to_show = 2;
1258 struct string_list have_done = STRING_LIST_INIT_DUP;
1259 struct string_list yet_to_do = STRING_LIST_INIT_DUP;
1261 read_rebase_todolist("rebase-merge/done", &have_done);
1262 if (read_rebase_todolist("rebase-merge/git-rebase-todo",
1264 status_printf_ln(s, color,
1265 _("git-rebase-todo is missing."));
1266 if (have_done.nr == 0)
1267 status_printf_ln(s, color, _("No commands done."));
1269 status_printf_ln(s, color,
1270 Q_("Last command done (%d command done):",
1271 "Last commands done (%d commands done):",
1274 for (i = (have_done.nr > nr_lines_to_show)
1275 ? have_done.nr - nr_lines_to_show : 0;
1278 status_printf_ln(s, color, " %s", have_done.items[i].string);
1279 if (have_done.nr > nr_lines_to_show && s->hints)
1280 status_printf_ln(s, color,
1281 _(" (see more in file %s)"), git_path("rebase-merge/done"));
1284 if (yet_to_do.nr == 0)
1285 status_printf_ln(s, color,
1286 _("No commands remaining."));
1288 status_printf_ln(s, color,
1289 Q_("Next command to do (%d remaining command):",
1290 "Next commands to do (%d remaining commands):",
1293 for (i = 0; i < nr_lines_to_show && i < yet_to_do.nr; i++)
1294 status_printf_ln(s, color, " %s", yet_to_do.items[i].string);
1296 status_printf_ln(s, color,
1297 _(" (use \"git rebase --edit-todo\" to view and edit)"));
1299 string_list_clear(&yet_to_do, 0);
1300 string_list_clear(&have_done, 0);
1304 static void print_rebase_state(struct wt_status *s,
1307 if (s->state.branch)
1308 status_printf_ln(s, color,
1309 _("You are currently rebasing branch '%s' on '%s'."),
1313 status_printf_ln(s, color,
1314 _("You are currently rebasing."));
1317 static void show_rebase_in_progress(struct wt_status *s,
1322 show_rebase_information(s, color);
1323 if (has_unmerged(s)) {
1324 print_rebase_state(s, color);
1326 status_printf_ln(s, color,
1327 _(" (fix conflicts and then run \"git rebase --continue\")"));
1328 status_printf_ln(s, color,
1329 _(" (use \"git rebase --skip\" to skip this patch)"));
1330 status_printf_ln(s, color,
1331 _(" (use \"git rebase --abort\" to check out the original branch)"));
1333 } else if (s->state.rebase_in_progress ||
1334 !stat(git_path_merge_msg(s->repo), &st)) {
1335 print_rebase_state(s, color);
1337 status_printf_ln(s, color,
1338 _(" (all conflicts fixed: run \"git rebase --continue\")"));
1339 } else if (split_commit_in_progress(s)) {
1340 if (s->state.branch)
1341 status_printf_ln(s, color,
1342 _("You are currently splitting a commit while rebasing branch '%s' on '%s'."),
1346 status_printf_ln(s, color,
1347 _("You are currently splitting a commit during a rebase."));
1349 status_printf_ln(s, color,
1350 _(" (Once your working directory is clean, run \"git rebase --continue\")"));
1352 if (s->state.branch)
1353 status_printf_ln(s, color,
1354 _("You are currently editing a commit while rebasing branch '%s' on '%s'."),
1358 status_printf_ln(s, color,
1359 _("You are currently editing a commit during a rebase."));
1360 if (s->hints && !s->amend) {
1361 status_printf_ln(s, color,
1362 _(" (use \"git commit --amend\" to amend the current commit)"));
1363 status_printf_ln(s, color,
1364 _(" (use \"git rebase --continue\" once you are satisfied with your changes)"));
1367 wt_longstatus_print_trailer(s);
1370 static void show_cherry_pick_in_progress(struct wt_status *s,
1373 if (is_null_oid(&s->state.cherry_pick_head_oid))
1374 status_printf_ln(s, color,
1375 _("Cherry-pick currently in progress."));
1377 status_printf_ln(s, color,
1378 _("You are currently cherry-picking commit %s."),
1379 find_unique_abbrev(&s->state.cherry_pick_head_oid,
1383 if (has_unmerged(s))
1384 status_printf_ln(s, color,
1385 _(" (fix conflicts and run \"git cherry-pick --continue\")"));
1386 else if (is_null_oid(&s->state.cherry_pick_head_oid))
1387 status_printf_ln(s, color,
1388 _(" (run \"git cherry-pick --continue\" to continue)"));
1390 status_printf_ln(s, color,
1391 _(" (all conflicts fixed: run \"git cherry-pick --continue\")"));
1392 status_printf_ln(s, color,
1393 _(" (use \"git cherry-pick --abort\" to cancel the cherry-pick operation)"));
1395 wt_longstatus_print_trailer(s);
1398 static void show_revert_in_progress(struct wt_status *s,
1401 if (is_null_oid(&s->state.revert_head_oid))
1402 status_printf_ln(s, color,
1403 _("Revert currently in progress."));
1405 status_printf_ln(s, color,
1406 _("You are currently reverting commit %s."),
1407 find_unique_abbrev(&s->state.revert_head_oid,
1410 if (has_unmerged(s))
1411 status_printf_ln(s, color,
1412 _(" (fix conflicts and run \"git revert --continue\")"));
1413 else if (is_null_oid(&s->state.revert_head_oid))
1414 status_printf_ln(s, color,
1415 _(" (run \"git revert --continue\" to continue)"));
1417 status_printf_ln(s, color,
1418 _(" (all conflicts fixed: run \"git revert --continue\")"));
1419 status_printf_ln(s, color,
1420 _(" (use \"git revert --abort\" to cancel the revert operation)"));
1422 wt_longstatus_print_trailer(s);
1425 static void show_bisect_in_progress(struct wt_status *s,
1428 if (s->state.branch)
1429 status_printf_ln(s, color,
1430 _("You are currently bisecting, started from branch '%s'."),
1433 status_printf_ln(s, color,
1434 _("You are currently bisecting."));
1436 status_printf_ln(s, color,
1437 _(" (use \"git bisect reset\" to get back to the original branch)"));
1438 wt_longstatus_print_trailer(s);
1442 * Extract branch information from rebase/bisect
1444 static char *get_branch(const struct worktree *wt, const char *path)
1446 struct strbuf sb = STRBUF_INIT;
1447 struct object_id oid;
1448 const char *branch_name;
1450 if (strbuf_read_file(&sb, worktree_git_path(wt, "%s", path), 0) <= 0)
1453 while (sb.len && sb.buf[sb.len - 1] == '\n')
1454 strbuf_setlen(&sb, sb.len - 1);
1457 if (skip_prefix(sb.buf, "refs/heads/", &branch_name))
1458 strbuf_remove(&sb, 0, branch_name - sb.buf);
1459 else if (starts_with(sb.buf, "refs/"))
1461 else if (!get_oid_hex(sb.buf, &oid)) {
1463 strbuf_add_unique_abbrev(&sb, &oid, DEFAULT_ABBREV);
1464 } else if (!strcmp(sb.buf, "detached HEAD")) /* rebase */
1468 return strbuf_detach(&sb, NULL);
1471 strbuf_release(&sb);
1475 struct grab_1st_switch_cbdata {
1477 struct object_id noid;
1480 static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,
1481 const char *email, timestamp_t timestamp, int tz,
1482 const char *message, void *cb_data)
1484 struct grab_1st_switch_cbdata *cb = cb_data;
1485 const char *target = NULL, *end;
1487 if (!skip_prefix(message, "checkout: moving from ", &message))
1489 target = strstr(message, " to ");
1492 target += strlen(" to ");
1493 strbuf_reset(&cb->buf);
1494 oidcpy(&cb->noid, noid);
1495 end = strchrnul(target, '\n');
1496 strbuf_add(&cb->buf, target, end - target);
1497 if (!strcmp(cb->buf.buf, "HEAD")) {
1498 /* HEAD is relative. Resolve it to the right reflog entry. */
1499 strbuf_reset(&cb->buf);
1500 strbuf_add_unique_abbrev(&cb->buf, noid, DEFAULT_ABBREV);
1505 static void wt_status_get_detached_from(struct repository *r,
1506 struct wt_status_state *state)
1508 struct grab_1st_switch_cbdata cb;
1509 struct commit *commit;
1510 struct object_id oid;
1513 strbuf_init(&cb.buf, 0);
1514 if (for_each_reflog_ent_reverse("HEAD", grab_1st_switch, &cb) <= 0) {
1515 strbuf_release(&cb.buf);
1519 if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
1520 /* sha1 is a commit? match without further lookup */
1521 (oideq(&cb.noid, &oid) ||
1522 /* perhaps sha1 is a tag, try to dereference to a commit */
1523 ((commit = lookup_commit_reference_gently(r, &oid, 1)) != NULL &&
1524 oideq(&cb.noid, &commit->object.oid)))) {
1525 const char *from = ref;
1526 if (!skip_prefix(from, "refs/tags/", &from))
1527 skip_prefix(from, "refs/remotes/", &from);
1528 state->detached_from = xstrdup(from);
1530 state->detached_from =
1531 xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
1532 oidcpy(&state->detached_oid, &cb.noid);
1533 state->detached_at = !get_oid("HEAD", &oid) &&
1534 oideq(&oid, &state->detached_oid);
1537 strbuf_release(&cb.buf);
1540 int wt_status_check_rebase(const struct worktree *wt,
1541 struct wt_status_state *state)
1545 if (!stat(worktree_git_path(wt, "rebase-apply"), &st)) {
1546 if (!stat(worktree_git_path(wt, "rebase-apply/applying"), &st)) {
1547 state->am_in_progress = 1;
1548 if (!stat(worktree_git_path(wt, "rebase-apply/patch"), &st) && !st.st_size)
1549 state->am_empty_patch = 1;
1551 state->rebase_in_progress = 1;
1552 state->branch = get_branch(wt, "rebase-apply/head-name");
1553 state->onto = get_branch(wt, "rebase-apply/onto");
1555 } else if (!stat(worktree_git_path(wt, "rebase-merge"), &st)) {
1556 if (!stat(worktree_git_path(wt, "rebase-merge/interactive"), &st))
1557 state->rebase_interactive_in_progress = 1;
1559 state->rebase_in_progress = 1;
1560 state->branch = get_branch(wt, "rebase-merge/head-name");
1561 state->onto = get_branch(wt, "rebase-merge/onto");
1567 int wt_status_check_bisect(const struct worktree *wt,
1568 struct wt_status_state *state)
1572 if (!stat(worktree_git_path(wt, "BISECT_LOG"), &st)) {
1573 state->bisect_in_progress = 1;
1574 state->branch = get_branch(wt, "BISECT_START");
1580 void wt_status_get_state(struct repository *r,
1581 struct wt_status_state *state,
1582 int get_detached_from)
1585 struct object_id oid;
1586 enum replay_action action;
1588 if (!stat(git_path_merge_head(r), &st)) {
1589 wt_status_check_rebase(NULL, state);
1590 state->merge_in_progress = 1;
1591 } else if (wt_status_check_rebase(NULL, state)) {
1593 } else if (!stat(git_path_cherry_pick_head(r), &st) &&
1594 !get_oid("CHERRY_PICK_HEAD", &oid)) {
1595 state->cherry_pick_in_progress = 1;
1596 oidcpy(&state->cherry_pick_head_oid, &oid);
1598 wt_status_check_bisect(NULL, state);
1599 if (!stat(git_path_revert_head(r), &st) &&
1600 !get_oid("REVERT_HEAD", &oid)) {
1601 state->revert_in_progress = 1;
1602 oidcpy(&state->revert_head_oid, &oid);
1604 if (!sequencer_get_last_command(r, &action)) {
1605 if (action == REPLAY_PICK) {
1606 state->cherry_pick_in_progress = 1;
1607 oidcpy(&state->cherry_pick_head_oid, &null_oid);
1609 state->revert_in_progress = 1;
1610 oidcpy(&state->revert_head_oid, &null_oid);
1613 if (get_detached_from)
1614 wt_status_get_detached_from(r, state);
1617 static void wt_longstatus_print_state(struct wt_status *s)
1619 const char *state_color = color(WT_STATUS_HEADER, s);
1620 struct wt_status_state *state = &s->state;
1622 if (state->merge_in_progress) {
1623 if (state->rebase_interactive_in_progress) {
1624 show_rebase_information(s, state_color);
1627 show_merge_in_progress(s, state_color);
1628 } else if (state->am_in_progress)
1629 show_am_in_progress(s, state_color);
1630 else if (state->rebase_in_progress || state->rebase_interactive_in_progress)
1631 show_rebase_in_progress(s, state_color);
1632 else if (state->cherry_pick_in_progress)
1633 show_cherry_pick_in_progress(s, state_color);
1634 else if (state->revert_in_progress)
1635 show_revert_in_progress(s, state_color);
1636 if (state->bisect_in_progress)
1637 show_bisect_in_progress(s, state_color);
1640 static void wt_longstatus_print(struct wt_status *s)
1642 const char *branch_color = color(WT_STATUS_ONBRANCH, s);
1643 const char *branch_status_color = color(WT_STATUS_HEADER, s);
1646 const char *on_what = _("On branch ");
1647 const char *branch_name = s->branch;
1648 if (!strcmp(branch_name, "HEAD")) {
1649 branch_status_color = color(WT_STATUS_NOBRANCH, s);
1650 if (s->state.rebase_in_progress ||
1651 s->state.rebase_interactive_in_progress) {
1652 if (s->state.rebase_interactive_in_progress)
1653 on_what = _("interactive rebase in progress; onto ");
1655 on_what = _("rebase in progress; onto ");
1656 branch_name = s->state.onto;
1657 } else if (s->state.detached_from) {
1658 branch_name = s->state.detached_from;
1659 if (s->state.detached_at)
1660 on_what = _("HEAD detached at ");
1662 on_what = _("HEAD detached from ");
1665 on_what = _("Not currently on any branch.");
1668 skip_prefix(branch_name, "refs/heads/", &branch_name);
1669 status_printf(s, color(WT_STATUS_HEADER, s), "%s", "");
1670 status_printf_more(s, branch_status_color, "%s", on_what);
1671 status_printf_more(s, branch_color, "%s\n", branch_name);
1673 wt_longstatus_print_tracking(s);
1676 wt_longstatus_print_state(s);
1678 if (s->is_initial) {
1679 status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
1680 status_printf_ln(s, color(WT_STATUS_HEADER, s),
1682 ? _("Initial commit")
1683 : _("No commits yet"));
1684 status_printf_ln(s, color(WT_STATUS_HEADER, s), "%s", "");
1687 wt_longstatus_print_updated(s);
1688 wt_longstatus_print_unmerged(s);
1689 wt_longstatus_print_changed(s);
1690 if (s->submodule_summary &&
1691 (!s->ignore_submodule_arg ||
1692 strcmp(s->ignore_submodule_arg, "all"))) {
1693 wt_longstatus_print_submodule_summary(s, 0); /* staged */
1694 wt_longstatus_print_submodule_summary(s, 1); /* unstaged */
1696 if (s->show_untracked_files) {
1697 wt_longstatus_print_other(s, &s->untracked, _("Untracked files"), "add");
1698 if (s->show_ignored_mode)
1699 wt_longstatus_print_other(s, &s->ignored, _("Ignored files"), "add -f");
1700 if (advice_status_u_option && 2000 < s->untracked_in_ms) {
1701 status_printf_ln(s, GIT_COLOR_NORMAL, "%s", "");
1702 status_printf_ln(s, GIT_COLOR_NORMAL,
1703 _("It took %.2f seconds to enumerate untracked files. 'status -uno'\n"
1704 "may speed it up, but you have to be careful not to forget to add\n"
1705 "new files yourself (see 'git help status')."),
1706 s->untracked_in_ms / 1000.0);
1708 } else if (s->committable)
1709 status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
1711 ? _(" (use -u option to show untracked files)") : "");
1714 wt_longstatus_print_verbose(s);
1715 if (!s->committable) {
1717 status_printf_ln(s, GIT_COLOR_NORMAL, _("No changes"));
1720 else if (s->workdir_dirty) {
1722 printf(_("no changes added to commit "
1723 "(use \"git add\" and/or \"git commit -a\")\n"));
1725 printf(_("no changes added to commit\n"));
1726 } else if (s->untracked.nr) {
1728 printf(_("nothing added to commit but untracked files "
1729 "present (use \"git add\" to track)\n"));
1731 printf(_("nothing added to commit but untracked files present\n"));
1732 } else if (s->is_initial) {
1734 printf(_("nothing to commit (create/copy files "
1735 "and use \"git add\" to track)\n"));
1737 printf(_("nothing to commit\n"));
1738 } else if (!s->show_untracked_files) {
1740 printf(_("nothing to commit (use -u to show untracked files)\n"));
1742 printf(_("nothing to commit\n"));
1744 printf(_("nothing to commit, working tree clean\n"));
1747 wt_longstatus_print_stash_summary(s);
1750 static void wt_shortstatus_unmerged(struct string_list_item *it,
1751 struct wt_status *s)
1753 struct wt_status_change_data *d = it->util;
1754 const char *how = "??";
1756 switch (d->stagemask) {
1757 case 1: how = "DD"; break; /* both deleted */
1758 case 2: how = "AU"; break; /* added by us */
1759 case 3: how = "UD"; break; /* deleted by them */
1760 case 4: how = "UA"; break; /* added by them */
1761 case 5: how = "DU"; break; /* deleted by us */
1762 case 6: how = "AA"; break; /* both added */
1763 case 7: how = "UU"; break; /* both modified */
1765 color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
1766 if (s->null_termination) {
1767 fprintf(stdout, " %s%c", it->string, 0);
1769 struct strbuf onebuf = STRBUF_INIT;
1771 one = quote_path(it->string, s->prefix, &onebuf);
1772 printf(" %s\n", one);
1773 strbuf_release(&onebuf);
1777 static void wt_shortstatus_status(struct string_list_item *it,
1778 struct wt_status *s)
1780 struct wt_status_change_data *d = it->util;
1782 if (d->index_status)
1783 color_fprintf(s->fp, color(WT_STATUS_UPDATED, s), "%c", d->index_status);
1786 if (d->worktree_status)
1787 color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
1791 if (s->null_termination) {
1792 fprintf(stdout, "%s%c", it->string, 0);
1793 if (d->rename_source)
1794 fprintf(stdout, "%s%c", d->rename_source, 0);
1796 struct strbuf onebuf = STRBUF_INIT;
1799 if (d->rename_source) {
1800 one = quote_path(d->rename_source, s->prefix, &onebuf);
1801 if (*one != '"' && strchr(one, ' ') != NULL) {
1803 strbuf_addch(&onebuf, '"');
1806 printf("%s -> ", one);
1807 strbuf_release(&onebuf);
1809 one = quote_path(it->string, s->prefix, &onebuf);
1810 if (*one != '"' && strchr(one, ' ') != NULL) {
1812 strbuf_addch(&onebuf, '"');
1815 printf("%s\n", one);
1816 strbuf_release(&onebuf);
1820 static void wt_shortstatus_other(struct string_list_item *it,
1821 struct wt_status *s, const char *sign)
1823 if (s->null_termination) {
1824 fprintf(stdout, "%s %s%c", sign, it->string, 0);
1826 struct strbuf onebuf = STRBUF_INIT;
1828 one = quote_path(it->string, s->prefix, &onebuf);
1829 color_fprintf(s->fp, color(WT_STATUS_UNTRACKED, s), "%s", sign);
1830 printf(" %s\n", one);
1831 strbuf_release(&onebuf);
1835 static void wt_shortstatus_print_tracking(struct wt_status *s)
1837 struct branch *branch;
1838 const char *header_color = color(WT_STATUS_HEADER, s);
1839 const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s);
1840 const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
1844 const char *branch_name;
1845 int num_ours, num_theirs, sti;
1846 int upstream_is_gone = 0;
1848 color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
1852 branch_name = s->branch;
1854 #define LABEL(string) (s->no_gettext ? (string) : _(string))
1857 color_fprintf(s->fp, header_color, LABEL(N_("No commits yet on ")));
1859 if (!strcmp(s->branch, "HEAD")) {
1860 color_fprintf(s->fp, color(WT_STATUS_NOBRANCH, s), "%s",
1861 LABEL(N_("HEAD (no branch)")));
1865 skip_prefix(branch_name, "refs/heads/", &branch_name);
1867 branch = branch_get(branch_name);
1869 color_fprintf(s->fp, branch_color_local, "%s", branch_name);
1871 sti = stat_tracking_info(branch, &num_ours, &num_theirs, &base,
1872 s->ahead_behind_flags);
1877 upstream_is_gone = 1;
1880 short_base = shorten_unambiguous_ref(base, 0);
1881 color_fprintf(s->fp, header_color, "...");
1882 color_fprintf(s->fp, branch_color_remote, "%s", short_base);
1885 if (!upstream_is_gone && !sti)
1888 color_fprintf(s->fp, header_color, " [");
1889 if (upstream_is_gone) {
1890 color_fprintf(s->fp, header_color, LABEL(N_("gone")));
1891 } else if (s->ahead_behind_flags == AHEAD_BEHIND_QUICK) {
1892 color_fprintf(s->fp, header_color, LABEL(N_("different")));
1893 } else if (!num_ours) {
1894 color_fprintf(s->fp, header_color, LABEL(N_("behind ")));
1895 color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
1896 } else if (!num_theirs) {
1897 color_fprintf(s->fp, header_color, LABEL(N_("ahead ")));
1898 color_fprintf(s->fp, branch_color_local, "%d", num_ours);
1900 color_fprintf(s->fp, header_color, LABEL(N_("ahead ")));
1901 color_fprintf(s->fp, branch_color_local, "%d", num_ours);
1902 color_fprintf(s->fp, header_color, ", %s", LABEL(N_("behind ")));
1903 color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
1906 color_fprintf(s->fp, header_color, "]");
1908 fputc(s->null_termination ? '\0' : '\n', s->fp);
1911 static void wt_shortstatus_print(struct wt_status *s)
1913 struct string_list_item *it;
1916 wt_shortstatus_print_tracking(s);
1918 for_each_string_list_item(it, &s->change) {
1919 struct wt_status_change_data *d = it->util;
1922 wt_shortstatus_unmerged(it, s);
1924 wt_shortstatus_status(it, s);
1926 for_each_string_list_item(it, &s->untracked)
1927 wt_shortstatus_other(it, s, "??");
1929 for_each_string_list_item(it, &s->ignored)
1930 wt_shortstatus_other(it, s, "!!");
1933 static void wt_porcelain_print(struct wt_status *s)
1936 s->relative_paths = 0;
1939 wt_shortstatus_print(s);
1943 * Print branch information for porcelain v2 output. These lines
1944 * are printed when the '--branch' parameter is given.
1946 * # branch.oid <commit><eol>
1947 * # branch.head <head><eol>
1948 * [# branch.upstream <upstream><eol>
1949 * [# branch.ab +<ahead> -<behind><eol>]]
1951 * <commit> ::= the current commit hash or the the literal
1952 * "(initial)" to indicate an initialized repo
1955 * <head> ::= <branch_name> the current branch name or
1956 * "(detached)" literal when detached head or
1957 * "(unknown)" when something is wrong.
1959 * <upstream> ::= the upstream branch name, when set.
1961 * <ahead> ::= integer ahead value or '?'.
1963 * <behind> ::= integer behind value or '?'.
1965 * The end-of-line is defined by the -z flag.
1967 * <eol> ::= NUL when -z,
1970 * When an upstream is set and present, the 'branch.ab' line will
1971 * be printed with the ahead/behind counts for the branch and the
1972 * upstream. When AHEAD_BEHIND_QUICK is requested and the branches
1973 * are different, '?' will be substituted for the actual count.
1975 static void wt_porcelain_v2_print_tracking(struct wt_status *s)
1977 struct branch *branch;
1979 const char *branch_name;
1980 int ab_info, nr_ahead, nr_behind;
1981 char eol = s->null_termination ? '\0' : '\n';
1983 fprintf(s->fp, "# branch.oid %s%c",
1984 (s->is_initial ? "(initial)" : sha1_to_hex(s->sha1_commit)),
1988 fprintf(s->fp, "# branch.head %s%c", "(unknown)", eol);
1990 if (!strcmp(s->branch, "HEAD")) {
1991 fprintf(s->fp, "# branch.head %s%c", "(detached)", eol);
1993 if (s->state.rebase_in_progress ||
1994 s->state.rebase_interactive_in_progress)
1995 branch_name = s->state.onto;
1996 else if (s->state.detached_from)
1997 branch_name = s->state.detached_from;
2002 skip_prefix(s->branch, "refs/heads/", &branch_name);
2004 fprintf(s->fp, "# branch.head %s%c", branch_name, eol);
2007 /* Lookup stats on the upstream tracking branch, if set. */
2008 branch = branch_get(branch_name);
2010 ab_info = stat_tracking_info(branch, &nr_ahead, &nr_behind,
2011 &base, s->ahead_behind_flags);
2013 base = shorten_unambiguous_ref(base, 0);
2014 fprintf(s->fp, "# branch.upstream %s%c", base, eol);
2019 if (nr_ahead || nr_behind)
2020 fprintf(s->fp, "# branch.ab +%d -%d%c",
2021 nr_ahead, nr_behind, eol);
2023 fprintf(s->fp, "# branch.ab +? -?%c",
2025 } else if (!ab_info) {
2027 fprintf(s->fp, "# branch.ab +0 -0%c", eol);
2034 * Convert various submodule status values into a
2035 * fixed-length string of characters in the buffer provided.
2037 static void wt_porcelain_v2_submodule_state(
2038 struct wt_status_change_data *d,
2041 if (S_ISGITLINK(d->mode_head) ||
2042 S_ISGITLINK(d->mode_index) ||
2043 S_ISGITLINK(d->mode_worktree)) {
2045 sub[1] = d->new_submodule_commits ? 'C' : '.';
2046 sub[2] = (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) ? 'M' : '.';
2047 sub[3] = (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ? 'U' : '.';
2058 * Fix-up changed entries before we print them.
2060 static void wt_porcelain_v2_fix_up_changed(
2061 struct string_list_item *it,
2062 struct wt_status *s)
2064 struct wt_status_change_data *d = it->util;
2066 if (!d->index_status) {
2068 * This entry is unchanged in the index (relative to the head).
2069 * Therefore, the collect_updated_cb was never called for this
2070 * entry (during the head-vs-index scan) and so the head column
2071 * fields were never set.
2073 * We must have data for the index column (from the
2074 * index-vs-worktree scan (otherwise, this entry should not be
2075 * in the list of changes)).
2077 * Copy index column fields to the head column, so that our
2078 * output looks complete.
2080 assert(d->mode_head == 0);
2081 d->mode_head = d->mode_index;
2082 oidcpy(&d->oid_head, &d->oid_index);
2085 if (!d->worktree_status) {
2087 * This entry is unchanged in the worktree (relative to the index).
2088 * Therefore, the collect_changed_cb was never called for this entry
2089 * (during the index-vs-worktree scan) and so the worktree column
2090 * fields were never set.
2092 * We must have data for the index column (from the head-vs-index
2095 * Copy the index column fields to the worktree column so that
2096 * our output looks complete.
2098 * Note that we only have a mode field in the worktree column
2099 * because the scan code tries really hard to not have to compute it.
2101 assert(d->mode_worktree == 0);
2102 d->mode_worktree = d->mode_index;
2107 * Print porcelain v2 info for tracked entries with changes.
2109 static void wt_porcelain_v2_print_changed_entry(
2110 struct string_list_item *it,
2111 struct wt_status *s)
2113 struct wt_status_change_data *d = it->util;
2114 struct strbuf buf = STRBUF_INIT;
2115 struct strbuf buf_from = STRBUF_INIT;
2116 const char *path = NULL;
2117 const char *path_from = NULL;
2119 char submodule_token[5];
2120 char sep_char, eol_char;
2122 wt_porcelain_v2_fix_up_changed(it, s);
2123 wt_porcelain_v2_submodule_state(d, submodule_token);
2125 key[0] = d->index_status ? d->index_status : '.';
2126 key[1] = d->worktree_status ? d->worktree_status : '.';
2129 if (s->null_termination) {
2131 * In -z mode, we DO NOT C-quote pathnames. Current path is ALWAYS first.
2132 * A single NUL character separates them.
2137 path_from = d->rename_source;
2140 * Path(s) are C-quoted if necessary. Current path is ALWAYS first.
2141 * The source path is only present when necessary.
2142 * A single TAB separates them (because paths can contain spaces
2143 * which are not escaped and C-quoting does escape TAB characters).
2147 path = quote_path(it->string, s->prefix, &buf);
2148 if (d->rename_source)
2149 path_from = quote_path(d->rename_source, s->prefix, &buf_from);
2153 fprintf(s->fp, "2 %s %s %06o %06o %06o %s %s %c%d %s%c%s%c",
2154 key, submodule_token,
2155 d->mode_head, d->mode_index, d->mode_worktree,
2156 oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index),
2157 d->rename_status, d->rename_score,
2158 path, sep_char, path_from, eol_char);
2160 fprintf(s->fp, "1 %s %s %06o %06o %06o %s %s %s%c",
2161 key, submodule_token,
2162 d->mode_head, d->mode_index, d->mode_worktree,
2163 oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index),
2166 strbuf_release(&buf);
2167 strbuf_release(&buf_from);
2171 * Print porcelain v2 status info for unmerged entries.
2173 static void wt_porcelain_v2_print_unmerged_entry(
2174 struct string_list_item *it,
2175 struct wt_status *s)
2177 struct wt_status_change_data *d = it->util;
2178 struct index_state *istate = s->repo->index;
2179 const struct cache_entry *ce;
2180 struct strbuf buf_index = STRBUF_INIT;
2181 const char *path_index = NULL;
2182 int pos, stage, sum;
2185 struct object_id oid;
2188 char submodule_token[5];
2189 char unmerged_prefix = 'u';
2190 char eol_char = s->null_termination ? '\0' : '\n';
2192 wt_porcelain_v2_submodule_state(d, submodule_token);
2194 switch (d->stagemask) {
2195 case 1: key = "DD"; break; /* both deleted */
2196 case 2: key = "AU"; break; /* added by us */
2197 case 3: key = "UD"; break; /* deleted by them */
2198 case 4: key = "UA"; break; /* added by them */
2199 case 5: key = "DU"; break; /* deleted by us */
2200 case 6: key = "AA"; break; /* both added */
2201 case 7: key = "UU"; break; /* both modified */
2203 BUG("unhandled unmerged status %x", d->stagemask);
2207 * Disregard d.aux.porcelain_v2 data that we accumulated
2208 * for the head and index columns during the scans and
2209 * replace with the actual stage data.
2211 * Note that this is a last-one-wins for each the individual
2212 * stage [123] columns in the event of multiple cache entries
2215 memset(stages, 0, sizeof(stages));
2217 pos = index_name_pos(istate, it->string, strlen(it->string));
2220 while (pos < istate->cache_nr) {
2221 ce = istate->cache[pos++];
2222 stage = ce_stage(ce);
2223 if (strcmp(ce->name, it->string) || !stage)
2225 stages[stage - 1].mode = ce->ce_mode;
2226 oidcpy(&stages[stage - 1].oid, &ce->oid);
2227 sum |= (1 << (stage - 1));
2229 if (sum != d->stagemask)
2230 BUG("observed stagemask 0x%x != expected stagemask 0x%x", sum, d->stagemask);
2232 if (s->null_termination)
2233 path_index = it->string;
2235 path_index = quote_path(it->string, s->prefix, &buf_index);
2237 fprintf(s->fp, "%c %s %s %06o %06o %06o %06o %s %s %s %s%c",
2238 unmerged_prefix, key, submodule_token,
2239 stages[0].mode, /* stage 1 */
2240 stages[1].mode, /* stage 2 */
2241 stages[2].mode, /* stage 3 */
2243 oid_to_hex(&stages[0].oid), /* stage 1 */
2244 oid_to_hex(&stages[1].oid), /* stage 2 */
2245 oid_to_hex(&stages[2].oid), /* stage 3 */
2249 strbuf_release(&buf_index);
2253 * Print porcelain V2 status info for untracked and ignored entries.
2255 static void wt_porcelain_v2_print_other(
2256 struct string_list_item *it,
2257 struct wt_status *s,
2260 struct strbuf buf = STRBUF_INIT;
2264 if (s->null_termination) {
2268 path = quote_path(it->string, s->prefix, &buf);
2272 fprintf(s->fp, "%c %s%c", prefix, path, eol_char);
2274 strbuf_release(&buf);
2278 * Print porcelain V2 status.
2281 * [<v2_changed_items>]*
2282 * [<v2_unmerged_items>]*
2283 * [<v2_untracked_items>]*
2284 * [<v2_ignored_items>]*
2287 static void wt_porcelain_v2_print(struct wt_status *s)
2289 struct wt_status_change_data *d;
2290 struct string_list_item *it;
2294 wt_porcelain_v2_print_tracking(s);
2296 for (i = 0; i < s->change.nr; i++) {
2297 it = &(s->change.items[i]);
2300 wt_porcelain_v2_print_changed_entry(it, s);
2303 for (i = 0; i < s->change.nr; i++) {
2304 it = &(s->change.items[i]);
2307 wt_porcelain_v2_print_unmerged_entry(it, s);
2310 for (i = 0; i < s->untracked.nr; i++) {
2311 it = &(s->untracked.items[i]);
2312 wt_porcelain_v2_print_other(it, s, '?');
2315 for (i = 0; i < s->ignored.nr; i++) {
2316 it = &(s->ignored.items[i]);
2317 wt_porcelain_v2_print_other(it, s, '!');
2321 void wt_status_print(struct wt_status *s)
2323 switch (s->status_format) {
2324 case STATUS_FORMAT_SHORT:
2325 wt_shortstatus_print(s);
2327 case STATUS_FORMAT_PORCELAIN:
2328 wt_porcelain_print(s);
2330 case STATUS_FORMAT_PORCELAIN_V2:
2331 wt_porcelain_v2_print(s);
2333 case STATUS_FORMAT_UNSPECIFIED:
2334 BUG("finalize_deferred_config() should have been called");
2336 case STATUS_FORMAT_NONE:
2337 case STATUS_FORMAT_LONG:
2338 wt_longstatus_print(s);
2344 * Returns 1 if there are unstaged changes, 0 otherwise.
2346 int has_unstaged_changes(struct repository *r, int ignore_submodules)
2348 struct rev_info rev_info;
2351 repo_init_revisions(r, &rev_info, NULL);
2352 if (ignore_submodules) {
2353 rev_info.diffopt.flags.ignore_submodules = 1;
2354 rev_info.diffopt.flags.override_submodule_config = 1;
2356 rev_info.diffopt.flags.quick = 1;
2357 diff_setup_done(&rev_info.diffopt);
2358 result = run_diff_files(&rev_info, 0);
2359 return diff_result_code(&rev_info.diffopt, result);
2363 * Returns 1 if there are uncommitted changes, 0 otherwise.
2365 int has_uncommitted_changes(struct repository *r,
2366 int ignore_submodules)
2368 struct rev_info rev_info;
2371 if (is_index_unborn(r->index))
2374 repo_init_revisions(r, &rev_info, NULL);
2375 if (ignore_submodules)
2376 rev_info.diffopt.flags.ignore_submodules = 1;
2377 rev_info.diffopt.flags.quick = 1;
2379 add_head_to_pending(&rev_info);
2380 if (!rev_info.pending.nr) {
2382 * We have no head (or it's corrupt); use the empty tree,
2383 * which will complain if the index is non-empty.
2385 struct tree *tree = lookup_tree(r, the_hash_algo->empty_tree);
2386 add_pending_object(&rev_info, &tree->object, "");
2389 diff_setup_done(&rev_info.diffopt);
2390 result = run_diff_index(&rev_info, 1);
2391 return diff_result_code(&rev_info.diffopt, result);
2395 * If the work tree has unstaged or uncommitted changes, dies with the
2396 * appropriate message.
2398 int require_clean_work_tree(struct repository *r,
2401 int ignore_submodules,
2404 struct lock_file lock_file = LOCK_INIT;
2407 fd = repo_hold_locked_index(r, &lock_file, 0);
2408 refresh_index(r->index, REFRESH_QUIET, NULL, NULL, NULL);
2410 repo_update_index_if_able(r, &lock_file);
2411 rollback_lock_file(&lock_file);
2413 if (has_unstaged_changes(r, ignore_submodules)) {
2414 /* TRANSLATORS: the action is e.g. "pull with rebase" */
2415 error(_("cannot %s: You have unstaged changes."), _(action));
2419 if (has_uncommitted_changes(r, ignore_submodules)) {
2421 error(_("additionally, your index contains uncommitted changes."));
2423 error(_("cannot %s: Your index contains uncommitted changes."),