#include "quote.h"
#include "run-command.h"
#include "remote.h"
+#include "refs.h"
+#include "submodule.h"
static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */
GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */
GIT_COLOR_RED, /* WT_STATUS_UNMERGED */
+ GIT_COLOR_GREEN, /* WT_STATUS_LOCAL_BRANCH */
+ GIT_COLOR_RED, /* WT_STATUS_REMOTE_BRANCH */
};
static const char *color(int slot, struct wt_status *s)
DIFF_OPT_SET(&rev.diffopt, DIRTY_SUBMODULES);
if (!s->show_untracked_files)
DIFF_OPT_SET(&rev.diffopt, IGNORE_UNTRACKED_IN_SUBMODULES);
+ if (s->ignore_submodule_arg)
+ handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
rev.diffopt.format_callback = wt_status_collect_changed_cb;
rev.diffopt.format_callback_data = s;
rev.prune_data = s->pathspec;
opt.def = s->is_initial ? EMPTY_TREE_SHA1_HEX : s->reference;
setup_revisions(0, NULL, &rev, &opt);
+ if (s->ignore_submodule_arg)
+ handle_ignore_submodules_arg(&rev.diffopt, s->ignore_submodule_arg);
+
rev.diffopt.output_format |= DIFF_FORMAT_CALLBACK;
rev.diffopt.format_callback = wt_status_collect_updated_cb;
rev.diffopt.format_callback_data = s;
struct child_process sm_summary;
char summary_limit[64];
char index[PATH_MAX];
- const char *env[] = { index, NULL };
- const char *argv[] = {
- "submodule",
- "summary",
- uncommitted ? "--files" : "--cached",
- "--for-status",
- "--summary-limit",
- summary_limit,
- uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD"),
- NULL
- };
+ const char *env[] = { NULL, NULL };
+ const char *argv[8];
+
+ env[0] = index;
+ argv[0] = "submodule";
+ argv[1] = "summary";
+ argv[2] = uncommitted ? "--files" : "--cached";
+ argv[3] = "--for-status";
+ argv[4] = "--summary-limit";
+ argv[5] = summary_limit;
+ argv[6] = uncommitted ? NULL : (s->amend ? "HEAD^" : "HEAD");
+ argv[7] = NULL;
sprintf(summary_limit, "%d", s->submodule_summary);
snprintf(index, sizeof(index), "GIT_INDEX_FILE=%s", s->index_file);
wt_status_print_updated(s);
wt_status_print_unmerged(s);
wt_status_print_changed(s);
- if (s->submodule_summary) {
+ if (s->submodule_summary &&
+ (!s->ignore_submodule_arg ||
+ strcmp(s->ignore_submodule_arg, "all"))) {
wt_status_print_submodule_summary(s, 0); /* staged */
wt_status_print_submodule_summary(s, 1); /* unstaged */
}
}
}
-void wt_shortstatus_print(struct wt_status *s, int null_termination)
+static void wt_shortstatus_print_tracking(struct wt_status *s)
+{
+ struct branch *branch;
+ const char *header_color = color(WT_STATUS_HEADER, s);
+ const char *branch_color_local = color(WT_STATUS_LOCAL_BRANCH, s);
+ const char *branch_color_remote = color(WT_STATUS_REMOTE_BRANCH, s);
+
+ const char *base;
+ const char *branch_name;
+ int num_ours, num_theirs;
+
+ color_fprintf(s->fp, color(WT_STATUS_HEADER, s), "## ");
+
+ if (!s->branch)
+ return;
+ branch_name = s->branch;
+
+ if (!prefixcmp(branch_name, "refs/heads/"))
+ branch_name += 11;
+ else if (!strcmp(branch_name, "HEAD")) {
+ branch_name = "HEAD (no branch)";
+ branch_color_local = color(WT_STATUS_NOBRANCH, s);
+ }
+
+ branch = branch_get(s->branch + 11);
+ if (s->is_initial)
+ color_fprintf(s->fp, header_color, "Initial commit on ");
+ if (!stat_tracking_info(branch, &num_ours, &num_theirs)) {
+ color_fprintf_ln(s->fp, branch_color_local,
+ "%s", branch_name);
+ return;
+ }
+
+ base = branch->merge[0]->dst;
+ base = shorten_unambiguous_ref(base, 0);
+ color_fprintf(s->fp, branch_color_local, "%s", branch_name);
+ color_fprintf(s->fp, header_color, "...");
+ color_fprintf(s->fp, branch_color_remote, "%s", base);
+
+ color_fprintf(s->fp, header_color, " [");
+ if (!num_ours) {
+ color_fprintf(s->fp, header_color, "behind ");
+ color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
+ } else if (!num_theirs) {
+ color_fprintf(s->fp, header_color, "ahead ");
+ color_fprintf(s->fp, branch_color_local, "%d", num_ours);
+ } else {
+ color_fprintf(s->fp, header_color, "ahead ");
+ color_fprintf(s->fp, branch_color_local, "%d", num_ours);
+ color_fprintf(s->fp, header_color, ", behind ");
+ color_fprintf(s->fp, branch_color_remote, "%d", num_theirs);
+ }
+
+ color_fprintf_ln(s->fp, header_color, "]");
+}
+
+void wt_shortstatus_print(struct wt_status *s, int null_termination, int show_branch)
{
int i;
+
+ if (show_branch)
+ wt_shortstatus_print_tracking(s);
+
for (i = 0; i < s->change.nr; i++) {
struct wt_status_change_data *d;
struct string_list_item *it;
s->use_color = 0;
s->relative_paths = 0;
s->prefix = NULL;
- wt_shortstatus_print(s, null_termination);
+ wt_shortstatus_print(s, null_termination, 0);
}