Skip to content

Commit 7e30944

Browse files
Mathieu Lienard--Mayorgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Jorge Juan Garcia Garcia <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 914dc02 commit 7e30944

File tree

5 files changed

+37
-1
lines changed

5 files changed

+37
-1
lines changed

Documentation/config.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ advice.*::
199199
amWorkDir::
200200
Advice that shows the location of the patch file when
201201
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.
202205
--
203206

204207
core.fileMode::

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ int advice_resolve_conflict = 1;
1414
int advice_implicit_identity = 1;
1515
int advice_detached_head = 1;
1616
int advice_set_upstream_failure = 1;
17+
int advice_rm_hints = 1;
1718

1819
static struct {
1920
const char *name;
@@ -33,6 +34,7 @@ static struct {
3334
{ "implicitidentity", &advice_implicit_identity },
3435
{ "detachedhead", &advice_detached_head },
3536
{ "setupstreamfailure", &advice_set_upstream_failure },
37+
{ "rmhints", &advice_rm_hints },
3638

3739
/* make this an alias for backward compatibility */
3840
{ "pushnonfastforward", &advice_push_update_rejected }

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ extern int advice_resolve_conflict;
1717
extern int advice_implicit_identity;
1818
extern int advice_detached_head;
1919
extern int advice_set_upstream_failure;
20+
extern int advice_rm_hints;
2021

2122
int git_default_advice_config(const char *var, const char *value);
2223
void advise(const char *advice, ...);

builtin/rm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ static void print_error_files(struct string_list *files_list,
5151
strbuf_addf(&err_msg,
5252
"\n %s",
5353
files_list->items[i].string);
54-
strbuf_addstr(&err_msg, hints_msg);
54+
if (advice_rm_hints)
55+
strbuf_addstr(&err_msg, hints_msg);
5556
*errs = error("%s", err_msg.buf);
5657
strbuf_release(&err_msg);
5758
}

t/t3600-rm.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,18 @@ test_expect_success 'rm files with different staged content' '
707707
test_i18ncmp expect actual
708708
'
709709

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+
'
710722

711723
test_expect_success 'rm file with local modification' '
712724
cat >expect <<-\EOF &&
@@ -720,6 +732,15 @@ test_expect_success 'rm file with local modification' '
720732
test_i18ncmp expect actual
721733
'
722734

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+
'
723744

724745
test_expect_success 'rm file with changes in the index' '
725746
cat >expect <<-\EOF &&
@@ -734,6 +755,14 @@ test_expect_success 'rm file with changes in the index' '
734755
test_i18ncmp expect actual
735756
'
736757

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+
'
737766

738767
test_expect_success 'rm files with two different errors' '
739768
cat >expect <<-\EOF &&

0 commit comments

Comments
 (0)