remote-hg: test 'shared_path' in a moved clone
[gitweb.git] / wt-status.c
index 706a6f77a2fd95893cd64c703b7bf407a874547e..4625cdb900f179e94314348340719b677fed1ca1 100644 (file)
@@ -15,6 +15,7 @@
 #include "submodule.h"
 #include "column.h"
 #include "strbuf.h"
+#include "utf8.h"
 
 static char default_wt_status_colors[][COLOR_MAXLEN] = {
        GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -165,7 +166,7 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
                }
        }
 
-       if (!advice_status_hints)
+       if (!s->hints)
                return;
        if (s->whence != FROM_COMMIT)
                ;
@@ -192,7 +193,7 @@ static void wt_status_print_cached_header(struct wt_status *s)
        const char *c = color(WT_STATUS_HEADER, s);
 
        status_printf_ln(s, c, _("Changes to be committed:"));
-       if (!advice_status_hints)
+       if (!s->hints)
                return;
        if (s->whence != FROM_COMMIT)
                ; /* NEEDSWORK: use "git reset --unresolve"??? */
@@ -210,7 +211,7 @@ static void wt_status_print_dirty_header(struct wt_status *s,
        const char *c = color(WT_STATUS_HEADER, s);
 
        status_printf_ln(s, c, _("Changes not staged for commit:"));
-       if (!advice_status_hints)
+       if (!s->hints)
                return;
        if (!has_deleted)
                status_printf_ln(s, c, _("  (use \"git add <file>...\" to update what will be committed)"));
@@ -228,7 +229,7 @@ static void wt_status_print_other_header(struct wt_status *s,
 {
        const char *c = color(WT_STATUS_HEADER, s);
        status_printf_ln(s, c, "%s:", what);
-       if (!advice_status_hints)
+       if (!s->hints)
                return;
        status_printf_ln(s, c, _("  (use \"git %s <file>...\" to include in what will be committed)"), how);
        status_printf_ln(s, c, "");
@@ -264,6 +265,30 @@ static void wt_status_print_unmerged_data(struct wt_status *s,
        strbuf_release(&onebuf);
 }
 
+static const char *wt_status_diff_status_string(int status)
+{
+       switch (status) {
+       case DIFF_STATUS_ADDED:
+               return _("new file");
+       case DIFF_STATUS_COPIED:
+               return _("copied");
+       case DIFF_STATUS_DELETED:
+               return _("deleted");
+       case DIFF_STATUS_MODIFIED:
+               return _("modified");
+       case DIFF_STATUS_RENAMED:
+               return _("renamed");
+       case DIFF_STATUS_TYPE_CHANGED:
+               return _("typechange");
+       case DIFF_STATUS_UNKNOWN:
+               return _("unknown");
+       case DIFF_STATUS_UNMERGED:
+               return _("unmerged");
+       default:
+               return NULL;
+       }
+}
+
 static void wt_status_print_change_data(struct wt_status *s,
                                        int change_type,
                                        struct string_list_item *it)
@@ -276,6 +301,23 @@ static void wt_status_print_change_data(struct wt_status *s,
        const char *one, *two;
        struct strbuf onebuf = STRBUF_INIT, twobuf = STRBUF_INIT;
        struct strbuf extra = STRBUF_INIT;
+       static char *padding;
+       const char *what;
+       int len;
+
+       if (!padding) {
+               int width = 0;
+               /* If DIFF_STATUS_* uses outside this range, we're in trouble */
+               for (status = 'A'; status <= 'Z'; status++) {
+                       what = wt_status_diff_status_string(status);
+                       len = what ? strlen(what) : 0;
+                       if (len > width)
+                               width = len;
+               }
+               width += 2;     /* colon and a space */
+               padding = xmallocz(width);
+               memset(padding, ' ', width);
+       }
 
        one_name = two_name = it->string;
        switch (change_type) {
@@ -307,34 +349,18 @@ static void wt_status_print_change_data(struct wt_status *s,
        two = quote_path(two_name, s->prefix, &twobuf);
 
        status_printf(s, color(WT_STATUS_HEADER, s), "\t");
-       switch (status) {
-       case DIFF_STATUS_ADDED:
-               status_printf_more(s, c, _("new file:   %s"), one);
-               break;
-       case DIFF_STATUS_COPIED:
-               status_printf_more(s, c, _("copied:     %s -> %s"), one, two);
-               break;
-       case DIFF_STATUS_DELETED:
-               status_printf_more(s, c, _("deleted:    %s"), one);
-               break;
-       case DIFF_STATUS_MODIFIED:
-               status_printf_more(s, c, _("modified:   %s"), one);
-               break;
-       case DIFF_STATUS_RENAMED:
-               status_printf_more(s, c, _("renamed:    %s -> %s"), one, two);
-               break;
-       case DIFF_STATUS_TYPE_CHANGED:
-               status_printf_more(s, c, _("typechange: %s"), one);
-               break;
-       case DIFF_STATUS_UNKNOWN:
-               status_printf_more(s, c, _("unknown:    %s"), one);
-               break;
-       case DIFF_STATUS_UNMERGED:
-               status_printf_more(s, c, _("unmerged:   %s"), one);
-               break;
-       default:
+       what = wt_status_diff_status_string(status);
+       if (!what)
                die(_("bug: unhandled diff status %c"), status);
-       }
+       /* 1 for colon, which is not part of "what" */
+       len = strlen(padding) - (utf8_strwidth(what) + 1);
+       assert(len >= 0);
+       if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
+               status_printf_more(s, c, "%s:%.*s%s -> %s",
+                                  what, len, padding, one, two);
+       else
+               status_printf_more(s, c, "%s:%.*s%s",
+                                  what, len, padding, one);
        if (extra.len) {
                status_printf_more(s, color(WT_STATUS_HEADER, s), "%s", extra.buf);
                strbuf_release(&extra);
@@ -846,13 +872,13 @@ static void show_merge_in_progress(struct wt_status *s,
 {
        if (has_unmerged(s)) {
                status_printf_ln(s, color, _("You have unmerged paths."));
-               if (advice_status_hints)
+               if (s->hints)
                        status_printf_ln(s, color,
                                _("  (fix conflicts and run \"git commit\")"));
        } else {
                status_printf_ln(s, color,
                        _("All conflicts fixed but you are still merging."));
-               if (advice_status_hints)
+               if (s->hints)
                        status_printf_ln(s, color,
                                _("  (use \"git commit\" to conclude merge)"));
        }
@@ -868,7 +894,7 @@ static void show_am_in_progress(struct wt_status *s,
        if (state->am_empty_patch)
                status_printf_ln(s, color,
                        _("The current patch is empty."));
-       if (advice_status_hints) {
+       if (s->hints) {
                if (!state->am_empty_patch)
                        status_printf_ln(s, color,
                                _("  (fix conflicts and then run \"git am --continue\")"));
@@ -941,7 +967,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                else
                        status_printf_ln(s, color,
                                         _("You are currently rebasing."));
-               if (advice_status_hints) {
+               if (s->hints) {
                        status_printf_ln(s, color,
                                _("  (fix conflicts and then run \"git rebase --continue\")"));
                        status_printf_ln(s, color,
@@ -958,7 +984,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                else
                        status_printf_ln(s, color,
                                         _("You are currently rebasing."));
-               if (advice_status_hints)
+               if (s->hints)
                        status_printf_ln(s, color,
                                _("  (all conflicts fixed: run \"git rebase --continue\")"));
        } else if (split_commit_in_progress(s)) {
@@ -970,7 +996,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                else
                        status_printf_ln(s, color,
                                         _("You are currently splitting a commit during a rebase."));
-               if (advice_status_hints)
+               if (s->hints)
                        status_printf_ln(s, color,
                                _("  (Once your working directory is clean, run \"git rebase --continue\")"));
        } else {
@@ -982,7 +1008,7 @@ static void show_rebase_in_progress(struct wt_status *s,
                else
                        status_printf_ln(s, color,
                                         _("You are currently editing a commit during a rebase."));
-               if (advice_status_hints && !s->amend) {
+               if (s->hints && !s->amend) {
                        status_printf_ln(s, color,
                                _("  (use \"git commit --amend\" to amend the current commit)"));
                        status_printf_ln(s, color,
@@ -996,8 +1022,9 @@ static void show_cherry_pick_in_progress(struct wt_status *s,
                                        struct wt_status_state *state,
                                        const char *color)
 {
-       status_printf_ln(s, color, _("You are currently cherry-picking."));
-       if (advice_status_hints) {
+       status_printf_ln(s, color, _("You are currently cherry-picking commit %s."),
+                       find_unique_abbrev(state->cherry_pick_head_sha1, DEFAULT_ABBREV));
+       if (s->hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
                                _("  (fix conflicts and run \"git cherry-pick --continue\")"));
@@ -1016,7 +1043,7 @@ static void show_revert_in_progress(struct wt_status *s,
 {
        status_printf_ln(s, color, _("You are currently reverting commit %s."),
                         find_unique_abbrev(state->revert_head_sha1, DEFAULT_ABBREV));
-       if (advice_status_hints) {
+       if (s->hints) {
                if (has_unmerged(s))
                        status_printf_ln(s, color,
                                _("  (fix conflicts and run \"git revert --continue\")"));
@@ -1040,7 +1067,7 @@ static void show_bisect_in_progress(struct wt_status *s,
        else
                status_printf_ln(s, color,
                                 _("You are currently bisecting."));
-       if (advice_status_hints)
+       if (s->hints)
                status_printf_ln(s, color,
                        _("  (use \"git bisect reset\" to get back to the original branch)"));
        wt_status_print_trailer(s);
@@ -1169,8 +1196,10 @@ void wt_status_get_state(struct wt_status_state *state,
                        state->rebase_in_progress = 1;
                state->branch = read_and_strip_branch("rebase-merge/head-name");
                state->onto = read_and_strip_branch("rebase-merge/onto");
-       } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st)) {
+       } else if (!stat(git_path("CHERRY_PICK_HEAD"), &st) &&
+                       !get_sha1("CHERRY_PICK_HEAD", sha1)) {
                state->cherry_pick_in_progress = 1;
+               hashcpy(state->cherry_pick_head_sha1, sha1);
        }
        if (!stat(git_path("BISECT_LOG"), &st)) {
                state->bisect_in_progress = 1;
@@ -1278,7 +1307,7 @@ void wt_status_print(struct wt_status *s)
                }
        } else if (s->commitable)
                status_printf_ln(s, GIT_COLOR_NORMAL, _("Untracked files not listed%s"),
-                       advice_status_hints
+                       s->hints
                        ? _(" (use -u option to show untracked files)") : "");
 
        if (s->verbose)
@@ -1289,25 +1318,25 @@ void wt_status_print(struct wt_status *s)
                else if (s->nowarn)
                        ; /* nothing */
                else if (s->workdir_dirty) {
-                       if (advice_status_hints)
+                       if (s->hints)
                                printf(_("no changes added to commit "
                                         "(use \"git add\" and/or \"git commit -a\")\n"));
                        else
                                printf(_("no changes added to commit\n"));
                } else if (s->untracked.nr) {
-                       if (advice_status_hints)
+                       if (s->hints)
                                printf(_("nothing added to commit but untracked files "
                                         "present (use \"git add\" to track)\n"));
                        else
                                printf(_("nothing added to commit but untracked files present\n"));
                } else if (s->is_initial) {
-                       if (advice_status_hints)
+                       if (s->hints)
                                printf(_("nothing to commit (create/copy files "
                                         "and use \"git add\" to track)\n"));
                        else
                                printf(_("nothing to commit\n"));
                } else if (!s->show_untracked_files) {
-                       if (advice_status_hints)
+                       if (s->hints)
                                printf(_("nothing to commit (use -u to show untracked files)\n"));
                        else
                                printf(_("nothing to commit\n"));