Skip to content

Commit 9da49be

Browse files
rjustogitster
authored andcommitted
add: use advise_if_enabled for ADVICE_ADD_IGNORED_FILE
Since b3b18d1 (advice: revamp advise API, 2020-03-02), we can use advise_if_enabled() to display an advice. This API encapsulates three actions: 1.- checking the visibility of the advice 2.- displaying the advice when appropriate 3.- displaying instructions on how to disable the advice, when appropriate The code we have in builtin/add.c to display the ADVICE_ADD_IGNORED_FILE advice, is doing these three things. However, the instructions displayed on how to disable the hint are not shown in the normalized way that advise_if_enabled() introduced. This may cause distraction. There is no reason not to use the new API here. On the contrary, by using it we gain simplicity in the code and avoid possible distractions. For these reasons, use the newer advise_if_enabled() machinery to show the ADVICE_ADD_IGNORED_FILE advice, and don't bother checking the visibility or displaying the instruction on how to disable the advice. Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 9da49be

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

builtin/add.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,8 @@ static int add_files(struct dir_struct *dir, int flags)
328328
fprintf(stderr, _(ignore_error));
329329
for (i = 0; i < dir->ignored_nr; i++)
330330
fprintf(stderr, "%s\n", dir->ignored[i]->name);
331-
if (advice_enabled(ADVICE_ADD_IGNORED_FILE))
332-
advise(_("Use -f if you really want to add them.\n"
333-
"Turn this message off by running\n"
334-
"\"git config advice.addIgnoredFile false\""));
331+
advise_if_enabled(ADVICE_ADD_IGNORED_FILE,
332+
_("Use -f if you really want to add them."));
335333
exit_status = 1;
336334
}
337335

t/t3700-add.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,8 +370,7 @@ cat >expect.err <<\EOF
370370
The following paths are ignored by one of your .gitignore files:
371371
ignored-file
372372
hint: Use -f if you really want to add them.
373-
hint: Turn this message off by running
374-
hint: "git config advice.addIgnoredFile false"
373+
hint: Disable this message with "git config advice.addIgnoredFile false"
375374
EOF
376375
cat >expect.out <<\EOF
377376
add 'track-this'

t/t7400-submodule-basic.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,7 @@ test_expect_success 'submodule add to .gitignored path fails' '
212212
The following paths are ignored by one of your .gitignore files:
213213
submod
214214
hint: Use -f if you really want to add them.
215-
hint: Turn this message off by running
216-
hint: "git config advice.addIgnoredFile false"
215+
hint: Disable this message with "git config advice.addIgnoredFile false"
217216
EOF
218217
# Does not use test_commit due to the ignore
219218
echo "*" > .gitignore &&

0 commit comments

Comments
 (0)