status: don't suggest "git rm" or "git add" if not appropriate

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>

Lucien Kong committed Jun 5, 2012 at 22:21 UTC 96b0ec1a4c3cafd17bc397c9ac836950c316dab6
3 files changed +74 -7
t/t7060-wtstatus.sh
+34 -2
@@ -152,7 +152,7 @@ test_expect_success 'status when conflicts with add and rm advice (deleted by th
152 '
153
154
155 -test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
155 +test_expect_success 'prepare for conflicts' '
156 git reset --hard &&
157 git checkout -b conflict &&
158 test_commit one main.txt one &&
@@ -161,7 +161,11 @@ test_expect_success 'status when conflicts with add and rm advice (both deleted)
161 git commit -m "main.txt renamed in sub_master.txt" &&
162 git checkout conflict_second &&
163 git mv main.txt sub_second.txt &&
164 - git commit -m "main.txt renamed in sub_second.txt" &&
164 + git commit -m "main.txt renamed in sub_second.txt"
165 +'
166 +
167 +
168 +test_expect_success 'status when conflicts with add and rm advice (both deleted)' '
169 test_must_fail git merge conflict &&
170 cat >expected <<-\EOF &&
171 # On branch conflict_second
@@ -182,4 +186,32 @@ test_expect_success 'status when conflicts with add and rm advice (both deleted)
186 '
187
188
189 +test_expect_success 'status when conflicts with only rm advice (both deleted)' '
190 + git reset --hard conflict_second &&
191 + test_must_fail git merge conflict &&
192 + git add sub_master.txt &&
193 + git add sub_second.txt &&
194 + cat >expected <<-\EOF &&
195 + # On branch conflict_second
196 + # You have unmerged paths.
197 + # (fix conflicts and run "git commit")
198 + #
199 + # Changes to be committed:
200 + #
201 + # new file: sub_master.txt
202 + #
203 + # Unmerged paths:
204 + # (use "git rm <file>..." to mark resolution)
205 + #
206 + # both deleted: main.txt
207 + #
208 + # Untracked files not listed (use -u option to show untracked files)
209 + EOF
210 + git status --untracked-files=no >actual &&
211 + test_i18ncmp expected actual &&
212 + git reset --hard &&
213 + git checkout master
214 +'
215 +
216 +
217 test_done
t/t7512-status-help.sh
+4 -4
@@ -30,7 +30,7 @@ test_expect_success 'status when conflicts unresolved' '
30 # (fix conflicts and run "git commit")
31 #
32 # Unmerged paths:
33 - # (use "git add/rm <file>..." as appropriate to mark resolution)
33 + # (use "git add <file>..." to mark resolution)
34 #
35 # both modified: main.txt
36 #
@@ -83,7 +83,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
83 #
84 # Unmerged paths:
85 # (use "git reset HEAD <file>..." to unstage)
86 - # (use "git add/rm <file>..." as appropriate to mark resolution)
86 + # (use "git add <file>..." to mark resolution)
87 #
88 # both modified: main.txt
89 #
@@ -140,7 +140,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
140 #
141 # Unmerged paths:
142 # (use "git reset HEAD <file>..." to unstage)
143 - # (use "git add/rm <file>..." as appropriate to mark resolution)
143 + # (use "git add <file>..." to mark resolution)
144 #
145 # both modified: main.txt
146 #
@@ -336,7 +336,7 @@ test_expect_success 'status when cherry-picking before resolving conflicts' '
336 # (fix conflicts and run "git commit")
337 #
338 # Unmerged paths:
339 - # (use "git add/rm <file>..." as appropriate to mark resolution)
339 + # (use "git add <file>..." to mark resolution)
340 #
341 # both modified: main.txt
342 #
wt-status.c
+36 -1
@@ -131,9 +131,34 @@ void wt_status_prepare(struct wt_status *s)
131
132 static void wt_status_print_unmerged_header(struct wt_status *s)
133 {
134 + int i;
135 + int del_mod_conflict = 0;
136 + int both_deleted = 0;
137 + int not_deleted = 0;
138 const char *c = color(WT_STATUS_HEADER, s);
139
140 status_printf_ln(s, c, _("Unmerged paths:"));
141 +
142 + for (i = 0; i < s->change.nr; i++) {
143 + struct string_list_item *it = &(s->change.items[i]);
144 + struct wt_status_change_data *d = it->util;
145 +
146 + switch (d->stagemask) {
147 + case 0:
148 + break;
149 + case 1:
150 + both_deleted = 1;
151 + break;
152 + case 3:
153 + case 5:
154 + del_mod_conflict = 1;
155 + break;
156 + default:
157 + not_deleted = 1;
158 + break;
159 + }
160 + }
161 +
162 if (!advice_status_hints)
163 return;
164 if (s->whence != FROM_COMMIT)
@@ -142,7 +167,17 @@ static void wt_status_print_unmerged_header(struct wt_status *s)
167 status_printf_ln(s, c, _(" (use \"git reset %s <file>...\" to unstage)"), s->reference);
168 else
169 status_printf_ln(s, c, _(" (use \"git rm --cached <file>...\" to unstage)"));
145 - status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
170 +
171 + if (!both_deleted) {
172 + if (!del_mod_conflict)
173 + status_printf_ln(s, c, _(" (use \"git add <file>...\" to mark resolution)"));
174 + else
175 + status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
176 + } else if (!del_mod_conflict && !not_deleted) {
177 + status_printf_ln(s, c, _(" (use \"git rm <file>...\" to mark resolution)"));
178 + } else {
179 + status_printf_ln(s, c, _(" (use \"git add/rm <file>...\" as appropriate to mark resolution)"));
180 + }
181 status_printf_ln(s, c, "");
182 }
183