status: don't suggest "git rm" or "git add" if not appropriate
authorLucien Kong <Lucien.Kong@ensimag.imag.fr>
Tue, 5 Jun 2012 20:21:26 +0000 (22:21 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Jun 2012 17:15:19 +0000 (10:15 -0700)
The display of the advice '(use git add/rm [...])' (when there are
unmerged files) after running 'git status' is now depending of the
mark, whether it's 'both deleted', 'deleted by us/them' or others. For
instance, when there is just one file that's marked as 'both deleted',
'git status' shows '(use git rm [...])' and if there are two files,
one as 'both deleted' and the other as 'added by them', the advice is
'(use git add/rm [...])'.

The previous tests in t7512-status-help.sh are updated.

Test about the case of only 'both deleted' is added in
t7060-wtstatus.sh

Signed-off-by: Lucien Kong <Lucien.Kong@ensimag.imag.fr>
Signed-off-by: Valentin Duperray <Valentin.Duperray@ensimag.imag.fr>
Signed-off-by: Franck Jonas <Franck.Jonas@ensimag.imag.fr>
Signed-off-by: Thomas Nguy <Thomas.Nguy@ensimag.imag.fr>
Signed-off-by: Huynh Khoi Nguyen Nguyen <Huynh-Khoi-Nguyen.Nguyen@ensimag.imag.fr>
Signed-off-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t7060-wtstatus.sh
t/t7512-status-help.sh
wt-status.c
index e8c3690dac5021a3afde9fd18ce89133831863c1..f4f38a5e7387694e16ff6f4a54020843630c2ac7 100755 (executable)
@@ -152,7 +152,7 @@ test_expect_success 'status when conflicts with add and rm advice (deleted by th
 '
 
 
-test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
+test_expect_success 'prepare for conflicts' '
        git reset --hard &&
        git checkout -b conflict &&
        test_commit one main.txt one &&
@@ -161,7 +161,11 @@ test_expect_success 'status when conflicts with add and rm advice (both deleted)
        git commit -m "main.txt renamed in sub_master.txt" &&
        git checkout conflict_second &&
        git mv main.txt sub_second.txt &&
-       git commit -m "main.txt renamed in sub_second.txt" &&
+       git commit -m "main.txt renamed in sub_second.txt"
+'
+
+
+test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
        test_must_fail git merge conflict &&
        cat >expected <<-\EOF &&
        # On branch conflict_second
@@ -182,4 +186,32 @@ test_expect_success 'status when conflicts with add and rm advice (both deleted)
 '
 
 
+test_expect_success 'status when conflicts with only rm advice (both deleted)' '
+       git reset --hard conflict_second &&
+       test_must_fail git merge conflict &&
+       git add sub_master.txt &&
+       git add sub_second.txt &&
+       cat >expected <<-\EOF &&
+       # On branch conflict_second
+       # You have unmerged paths.
+       #   (fix conflicts and run "git commit")
+       #
+       # Changes to be committed:
+       #
+       #       new file:   sub_master.txt
+       #
+       # Unmerged paths:
+       #   (use "git rm <file>..." to mark resolution)
+       #
+       #       both deleted:       main.txt
+       #
+       # Untracked files not listed (use -u option to show untracked files)
+       EOF
+       git status --untracked-files=no >actual &&
+       test_i18ncmp expected actual &&
+       git reset --hard &&
+       git checkout master
+'
+
+
 test_done
index 3714e8e9c20ea3de6df102798459bf48696c2853..bdce1923d91ed8b3cec0e6c13c60047ea536483d 100755 (executable)
@@ -30,7 +30,7 @@ test_expect_success 'status when conflicts unresolved' '
        #   (fix conflicts and run "git commit")
        #
        # Unmerged paths:
-       #   (use "git add/rm <file>..." as appropriate to mark resolution)
+       #   (use "git add <file>..." to mark resolution)
        #
        #       both modified:      main.txt
        #
@@ -83,7 +83,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
        #
        # Unmerged paths:
        #   (use "git reset HEAD <file>..." to unstage)
-       #   (use "git add/rm <file>..." as appropriate to mark resolution)
+       #   (use "git add <file>..." to mark resolution)
        #
        #       both modified:      main.txt
        #
@@ -140,7 +140,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
        #
        # Unmerged paths:
        #   (use "git reset HEAD <file>..." to unstage)
-       #   (use "git add/rm <file>..." as appropriate to mark resolution)
+       #   (use "git add <file>..." to mark resolution)
        #
        #       both modified:      main.txt
        #
@@ -336,7 +336,7 @@ test_expect_success 'status when cherry-picking before resolving conflicts' '
        #   (fix conflicts and run "git commit")
        #
        # Unmerged paths:
-       #   (use "git add/rm <file>..." as appropriate to mark resolution)
+       #   (use "git add <file>..." to mark resolution)
        #
        #       both modified:      main.txt
        #
index e404f2d9ec01c6c44f3c1723d5cc272425dec94d..6d0b71f74733e7bf345b04abb0987f7ad6602101 100644 (file)
@@ -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, "");
 }