From: Junio C Hamano Date: Wed, 5 Aug 2009 07:04:51 +0000 (-0700) Subject: status: show worktree status of conflicted paths separately X-Git-Tag: v1.6.5-rc0~26^2~7 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=4d4d5726aee31522e90df21ef62ee3377c5d8f8d;p=git.git status: show worktree status of conflicted paths separately When a path is unmerged in the index, we used to always say "unmerged" in the "Changed but not updated" section, even when the path was deleted in the work tree. Remove unmerged entries from the "Updated" section, and create a new section "Unmerged paths". Describe how the different stages conflict in more detail in this new section. Note that with the current 3-way merge policy (with or without recursive), certain combinations of index stages should never happen. For example, having only stage #2 means that a path that did not exist in the common ancestor was added by us while the other branch did not do anything to it, which would have autoresolved to take our addition. The code nevertheless prepares for the possibility that future merge policies may leave a path in such a state. Signed-off-by: Junio C Hamano --- diff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh index 5ad2cd1d0..1044aa654 100755 --- a/t/t7060-wtstatus.sh +++ b/t/t7060-wtstatus.sh @@ -28,4 +28,31 @@ test_expect_success 'Report new path with conflict' ' test_cmp expect actual ' +cat >expect <..." to unstage) +# (use "git add ..." to mark resolution) +# +# deleted by us: foo +# +no changes added to commit (use "git add" and/or "git commit -a") +EOF + +test_expect_success 'M/D conflict does not segfault' ' + mkdir mdconflict && + ( + cd mdconflict && + git init && + test_commit initial foo "" && + test_commit modify foo foo && + git checkout -b side HEAD^ && + git rm foo && + git commit -m delete && + test_must_fail git merge master && + test_must_fail git status > ../actual + ) && + test_cmp expect actual +' + test_done diff --git a/wt-status.c b/wt-status.c index 9aab56775..97fedfaa1 100644 --- a/wt-status.c +++ b/wt-status.c @@ -20,6 +20,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = { GIT_COLOR_RED, /* WT_STATUS_CHANGED */ GIT_COLOR_RED, /* WT_STATUS_UNTRACKED */ GIT_COLOR_RED, /* WT_STATUS_NOBRANCH */ + GIT_COLOR_RED, /* WT_STATUS_UNMERGED */ }; enum untracked_status_type show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; @@ -37,6 +38,8 @@ static int parse_status_slot(const char *var, int offset) return WT_STATUS_UNTRACKED; if (!strcasecmp(var+offset, "nobranch")) return WT_STATUS_NOBRANCH; + if (!strcasecmp(var+offset, "unmerged")) + return WT_STATUS_UNMERGED; die("bad config variable '%s'", var); } @@ -59,6 +62,18 @@ void wt_status_prepare(struct wt_status *s) s->change.strdup_strings = 1; } +static void wt_status_print_unmerged_header(struct wt_status *s) +{ + const char *c = color(WT_STATUS_HEADER); + color_fprintf_ln(s->fp, c, "# Unmerged paths:"); + if (!s->is_initial) + color_fprintf_ln(s->fp, c, "# (use \"git reset %s ...\" to unstage)", s->reference); + else + color_fprintf_ln(s->fp, c, "# (use \"git rm --cached ...\" to unstage)"); + color_fprintf_ln(s->fp, c, "# (use \"git add ...\" to mark resolution)"); + color_fprintf_ln(s->fp, c, "#"); +} + static void wt_status_print_cached_header(struct wt_status *s) { const char *c = color(WT_STATUS_HEADER); @@ -99,6 +114,29 @@ static void wt_status_print_trailer(struct wt_status *s) #define quote_path quote_path_relative +static void wt_status_print_unmerged_data(struct wt_status *s, + struct string_list_item *it) +{ + const char *c = color(WT_STATUS_UNMERGED); + struct wt_status_change_data *d = it->util; + struct strbuf onebuf = STRBUF_INIT; + const char *one, *how = "bug"; + + one = quote_path(it->string, -1, &onebuf, s->prefix); + color_fprintf(s->fp, color(WT_STATUS_HEADER), "#\t"); + switch (d->stagemask) { + case 1: how = "both deleted:"; break; + case 2: how = "added by us:"; break; + case 3: how = "deleted by them:"; break; + case 4: how = "added by them:"; break; + case 5: how = "deleted by us:"; break; + case 6: how = "both added:"; break; + case 7: how = "both modified:"; break; + } + color_fprintf(s->fp, c, "%-20s%s\n", how, one); + strbuf_release(&onebuf); +} + static void wt_status_print_change_data(struct wt_status *s, int change_type, struct string_list_item *it) @@ -187,6 +225,26 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q, } } +static int unmerged_mask(const char *path) +{ + int pos, mask; + struct cache_entry *ce; + + pos = cache_name_pos(path, strlen(path)); + if (0 <= pos) + return 0; + + mask = 0; + pos = -pos-1; + while (pos < active_nr) { + ce = active_cache[pos++]; + if (strcmp(ce->name, path) || !ce_stage(ce)) + break; + mask |= (1 << (ce_stage(ce) - 1)); + } + return mask; +} + static void wt_status_collect_updated_cb(struct diff_queue_struct *q, struct diff_options *options, void *data) @@ -213,6 +271,9 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q, case DIFF_STATUS_RENAMED: d->head_path = xstrdup(p->one->path); break; + case DIFF_STATUS_UNMERGED: + d->stagemask = unmerged_mask(p->two->path); + break; } } } @@ -260,8 +321,10 @@ static void wt_status_collect_changes_initial(struct wt_status *s) d = xcalloc(1, sizeof(*d)); it->util = d; } - if (ce_stage(ce)) + if (ce_stage(ce)) { d->index_status = DIFF_STATUS_UNMERGED; + d->stagemask |= (1 << (ce_stage(ce) - 1)); + } else d->index_status = DIFF_STATUS_ADDED; } @@ -277,6 +340,29 @@ void wt_status_collect_changes(struct wt_status *s) wt_status_collect_changes_index(s); } +static void wt_status_print_unmerged(struct wt_status *s) +{ + int shown_header = 0; + int i; + + for (i = 0; i < s->change.nr; i++) { + struct wt_status_change_data *d; + struct string_list_item *it; + it = &(s->change.items[i]); + d = it->util; + if (!d->stagemask) + continue; + if (!shown_header) { + wt_status_print_unmerged_header(s); + shown_header = 1; + } + wt_status_print_unmerged_data(s, it); + } + if (shown_header) + wt_status_print_trailer(s); + +} + static void wt_status_print_updated(struct wt_status *s) { int shown_header = 0; @@ -314,7 +400,8 @@ static int wt_status_check_worktree_changes(struct wt_status *s) for (i = 0; i < s->change.nr; i++) { struct wt_status_change_data *d; d = s->change.items[i].util; - if (!d->worktree_status) + if (!d->worktree_status || + d->worktree_status == DIFF_STATUS_UNMERGED) continue; changes = 1; if (d->worktree_status == DIFF_STATUS_DELETED) @@ -338,7 +425,8 @@ static void wt_status_print_changed(struct wt_status *s) struct string_list_item *it; it = &(s->change.items[i]); d = it->util; - if (!d->worktree_status) + if (!d->worktree_status || + d->worktree_status == DIFF_STATUS_UNMERGED) continue; wt_status_print_change_data(s, WT_STATUS_CHANGED, it); } @@ -479,6 +567,7 @@ void wt_status_print(struct wt_status *s) color_fprintf_ln(s->fp, color(WT_STATUS_HEADER), "#"); } + wt_status_print_unmerged(s); wt_status_print_updated(s); wt_status_print_changed(s); if (wt_status_submodule_summary) diff --git a/wt-status.h b/wt-status.h index 82a602b3b..f80142ffd 100644 --- a/wt-status.h +++ b/wt-status.h @@ -10,6 +10,7 @@ enum color_wt_status { WT_STATUS_CHANGED, WT_STATUS_UNTRACKED, WT_STATUS_NOBRANCH, + WT_STATUS_UNMERGED, }; enum untracked_status_type {