fetch-pack: eliminate spurious error messages
[gitweb.git] / wt-status.c
index e404f2d9ec01c6c44f3c1723d5cc272425dec94d..c110cbc1250b08fe491d60244e1c8f27c0201532 100644 (file)
@@ -12,6 +12,7 @@
 #include "refs.h"
 #include "submodule.h"
 #include "column.h"
+#include "strbuf.h"
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -23,7 +24,6 @@ static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_GREEN,  /* WT_STATUS_LOCAL_BRANCH */
        GIT_COLOR_RED,    /* WT_STATUS_REMOTE_BRANCH */
        GIT_COLOR_NIL,    /* WT_STATUS_ONBRANCH */
-       GIT_COLOR_NORMAL, /* WT_STATUS_IN_PROGRESS */
 };
 
 static const char *color(int slot, struct wt_status *s)
@@ -131,9 +131,34 @@ void wt_status_prepare(struct wt_status *s)
 
 static void wt_status_print_unmerged_header(struct wt_status *s)
 {
+       int i;
+       int del_mod_conflict = 0;
+       int both_deleted = 0;
+       int not_deleted = 0;
        const char *c = color(WT_STATUS_HEADER, s);
 
        status_printf_ln(s, c, _("Unmerged paths:"));
+
+       for (i = 0; i < s->change.nr; i++) {
+               struct string_list_item *it = &(s->change.items[i]);
+               struct wt_status_change_data *d = it->util;
+
+               switch (d->stagemask) {
+               case 0:
+                       break;
+               case 1:
+                       both_deleted = 1;
+                       break;
+               case 3:
+               case 5:
+                       del_mod_conflict = 1;
+                       break;
+               default:
+                       not_deleted = 1;
+                       break;
+               }
+       }
+
        if (!advice_status_hints)
                return;
        if (s->whence != FROM_COMMIT)
@@ -142,7 +167,17 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
                status_printf_ln(s, c, _("  (use \"git reset %s <file>...\" to unstage)"), s->reference);
        else
                status_printf_ln(s, c, _("  (use \"git rm --cached <file>...\" to unstage)"));
-       status_printf_ln(s, c, _("  (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
+
+       if (!both_deleted) {
+               if (!del_mod_conflict)
+                       status_printf_ln(s, c, _("  (use \"git add <file>...\" to mark resolution)"));
+               else
+                       status_printf_ln(s, c, _("  (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
+       } else if (!del_mod_conflict && !not_deleted) {
+               status_printf_ln(s, c, _("  (use \"git rm <file>...\" to mark resolution)"));
+       } else {
+               status_printf_ln(s, c, _("  (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
+       }
        status_printf_ln(s, c, "");
 }
 
@@ -782,6 +817,52 @@ static void show_am_in_progress(struct wt_status *s,
        wt_status_print_trailer(s);
 }
 
+static char *read_line_from_git_path(const char *filename)
+{
+       struct strbuf buf = STRBUF_INIT;
+       FILE *fp = fopen(git_path("%s", filename), "r");
+       if (!fp) {
+               strbuf_release(&buf);
+               return NULL;
+       }
+       strbuf_getline(&buf, fp, '\n');
+       if (!fclose(fp)) {
+               return strbuf_detach(&buf, NULL);
+       } else {
+               strbuf_release(&buf);
+               return NULL;
+       }
+}
+
+static int split_commit_in_progress(struct wt_status *s)
+{
+       int split_in_progress = 0;
+       char *head = read_line_from_git_path("HEAD");
+       char *orig_head = read_line_from_git_path("ORIG_HEAD");
+       char *rebase_amend = read_line_from_git_path("rebase-merge/amend");
+       char *rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
+
+       if (!head || !orig_head || !rebase_amend || !rebase_orig_head ||
+           !s->branch || strcmp(s->branch, "HEAD"))
+               return split_in_progress;
+
+       if (!strcmp(rebase_amend, rebase_orig_head)) {
+               if (strcmp(head, rebase_amend))
+                       split_in_progress = 1;
+       } else if (strcmp(orig_head, rebase_orig_head)) {
+               split_in_progress = 1;
+       }
+
+       if (!s->amend && !s->nowarn && !s->workdir_dirty)
+               split_in_progress = 0;
+
+       free(head);
+       free(orig_head);
+       free(rebase_amend);
+       free(rebase_orig_head);
+       return split_in_progress;
+}
+
 static void show_rebase_in_progress(struct wt_status *s,
                                struct wt_status_state *state,
                                const char *color)
@@ -803,6 +884,11 @@ static void show_rebase_in_progress(struct wt_status *s,
                if (advice_status_hints)
                        status_printf_ln(s, color,
                                _("  (all conflicts fixed: run \"git rebase --continue\")"));
+       } else if (split_commit_in_progress(s)) {
+               status_printf_ln(s, color, _("You are currently splitting a commit during a rebase."));
+               if (advice_status_hints)
+                       status_printf_ln(s, color,
+                               _("  (Once your working directory is clean, run \"git rebase --continue\")"));
        } else {
                status_printf_ln(s, color, _("You are currently editing a commit during a rebase."));
                if (advice_status_hints && !s->amend) {
@@ -844,7 +930,7 @@ static void show_bisect_in_progress(struct wt_status *s,
 
 static void wt_status_print_state(struct wt_status *s)
 {
-       const char *state_color = color(WT_STATUS_IN_PROGRESS, s);
+       const char *state_color = color(WT_STATUS_HEADER, s);
        struct wt_status_state state;
        struct stat st;