rm: introduce advice.rmHints to shorten messages

Introduce advice.rmHints to choose whether to display advice or not when git rm fails. Defaults to true, in order to preserve current behavior. As an example, the message: error: 'foo.txt' has changes staged in the index (use --cached to keep the file, or -f to force removal) would look like, with advice.rmHints=false: error: 'foo.txt' has changes staged in the index Signed-off-by: Mathieu Lienard--Mayor <Mathieu.Lienard--Mayor@ensimag.imag.fr> Signed-off-by: Jorge Juan Garcia Garcia <Jorge-Juan.Garcia-Garcia@ensimag.imag.fr> Signed-off-by: Matthieu Moy <Matthieu.Moy@grenoble-inp.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mathieu Lienard--Mayor committed Jun 12, 2013 at 10:06 UTC 7e30944622573ebdf87beed057b098af7360234c
5 files changed +37 -1
Documentation/config.txt
+3
@@ -199,6 +199,9 @@ advice.*::
199 amWorkDir::
200 Advice that shows the location of the patch file when
201 linkgit:git-am[1] fails to apply it.
202 + rmHints::
203 + In case of failure in the output of linkgit:git-rm[1],
204 + show directions on how to proceed from the current state.
205 --
206
207 core.fileMode::
advice.c
+2
@@ -14,6 +14,7 @@ int advice_resolve_conflict = 1;
14 int advice_implicit_identity = 1;
15 int advice_detached_head = 1;
16 int advice_set_upstream_failure = 1;
17 +int advice_rm_hints = 1;
18
19 static struct {
20 const char *name;
@@ -33,6 +34,7 @@ static struct {
34 { "implicitidentity", &advice_implicit_identity },
35 { "detachedhead", &advice_detached_head },
36 { "setupstreamfailure", &advice_set_upstream_failure },
37 + { "rmhints", &advice_rm_hints },
38
39 /* make this an alias for backward compatibility */
40 { "pushnonfastforward", &advice_push_update_rejected }
advice.h
+1
@@ -17,6 +17,7 @@ extern int advice_resolve_conflict;
17 extern int advice_implicit_identity;
18 extern int advice_detached_head;
19 extern int advice_set_upstream_failure;
20 +extern int advice_rm_hints;
21
22 int git_default_advice_config(const char *var, const char *value);
23 void advise(const char *advice, ...);
builtin/rm.c
+2 -1
@@ -51,7 +51,8 @@ static void print_error_files(struct string_list *files_list,
51 strbuf_addf(&err_msg,
52 "\n %s",
53 files_list->items[i].string);
54 - strbuf_addstr(&err_msg, hints_msg);
54 + if (advice_rm_hints)
55 + strbuf_addstr(&err_msg, hints_msg);
56 *errs = error("%s", err_msg.buf);
57 strbuf_release(&err_msg);
58 }
t/t3600-rm.sh
+29
@@ -707,6 +707,18 @@ test_expect_success 'rm files with different staged content' '
707 test_i18ncmp expect actual
708 '
709
710 +test_expect_success 'rm files with different staged content without hints' '
711 + cat >expect <<-\EOF &&
712 + error: the following files have staged content different from both the
713 + file and the HEAD:
714 + bar.txt
715 + foo.txt
716 + EOF
717 + echo content2 >foo.txt &&
718 + echo content2 >bar.txt &&
719 + test_must_fail git -c advice.rmhints=false rm foo.txt bar.txt 2>actual &&
720 + test_i18ncmp expect actual
721 +'
722
723 test_expect_success 'rm file with local modification' '
724 cat >expect <<-\EOF &&
@@ -720,6 +732,15 @@ test_expect_success 'rm file with local modification' '
732 test_i18ncmp expect actual
733 '
734
735 +test_expect_success 'rm file with local modification without hints' '
736 + cat >expect <<-\EOF &&
737 + error: the following file has local modifications:
738 + bar.txt
739 + EOF
740 + echo content4 >bar.txt &&
741 + test_must_fail git -c advice.rmhints=false rm bar.txt 2>actual &&
742 + test_i18ncmp expect actual
743 +'
744
745 test_expect_success 'rm file with changes in the index' '
746 cat >expect <<-\EOF &&
@@ -734,6 +755,14 @@ test_expect_success 'rm file with changes in the index' '
755 test_i18ncmp expect actual
756 '
757
758 +test_expect_success 'rm file with changes in the index without hints' '
759 + cat >expect <<-\EOF &&
760 + error: the following file has changes staged in the index:
761 + foo.txt
762 + EOF
763 + test_must_fail git -c advice.rmhints=false rm foo.txt 2>actual &&
764 + test_i18ncmp expect actual
765 +'
766
767 test_expect_success 'rm files with two different errors' '
768 cat >expect <<-\EOF &&