Skip to content

Commit 887a0fd

Browse files
HebaWalygitster
authored andcommitted
add: change advice config variables used by the add API
advice.addNothing config variable is used to control the visibility of two advice messages in the add library. This config variable is replaced by two new variables, whose names are more clear and relevant to the two cases. Also add the two new variables to the documentation. Signed-off-by: Heba Waly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent bf66db3 commit 887a0fd

File tree

5 files changed

+22
-7
lines changed

5 files changed

+22
-7
lines changed

Documentation/config/advice.txt

+6
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,10 @@ advice.*::
110110
submoduleAlternateErrorStrategyDie::
111111
Advice shown when a submodule.alternateErrorStrategy option
112112
configured to "die" causes a fatal error.
113+
addIgnoredFile::
114+
Advice shown if a user attempts to add an ignored file to
115+
the index.
116+
addEmptyPathspec::
117+
Advice shown if a user runs the add command without providing
118+
the pathspec parameter.
113119
--

advice.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ int advice_graft_file_deprecated = 1;
3131
int advice_checkout_ambiguous_remote_branch_name = 1;
3232
int advice_nested_tag = 1;
3333
int advice_submodule_alternate_error_strategy_die = 1;
34-
int advice_add_nothing = 1;
34+
int advice_add_ignored_file = 1;
35+
int advice_add_empty_pathspec = 1;
3536

3637
static int advice_use_color = -1;
3738
static char advice_colors[][COLOR_MAXLEN] = {
@@ -92,7 +93,8 @@ static struct {
9293
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
9394
{ "nestedTag", &advice_nested_tag },
9495
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
95-
{ "addNothing", &advice_add_nothing },
96+
{ "addIgnoredFile", &advice_add_ignored_file },
97+
{ "addEmptyPathspec", &advice_add_empty_pathspec },
9698

9799
/* make this an alias for backward compatibility */
98100
{ "pushNonFastForward", &advice_push_update_rejected }

advice.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extern int advice_graft_file_deprecated;
3131
extern int advice_checkout_ambiguous_remote_branch_name;
3232
extern int advice_nested_tag;
3333
extern int advice_submodule_alternate_error_strategy_die;
34-
extern int advice_add_nothing;
34+
extern int advice_add_ignored_file;
35+
extern int advice_add_empty_pathspec;
3536

3637
int git_default_advice_config(const char *var, const char *value);
3738
__attribute__((format (printf, 1, 2)))

builtin/add.c

+8-4
Original file line numberDiff line numberDiff line change
@@ -390,8 +390,10 @@ static int add_files(struct dir_struct *dir, int flags)
390390
fprintf(stderr, _(ignore_error));
391391
for (i = 0; i < dir->ignored_nr; i++)
392392
fprintf(stderr, "%s\n", dir->ignored[i]->name);
393-
if (advice_add_nothing)
394-
advise(_("Use -f if you really want to add them.\n"));
393+
if (advice_add_ignored_file)
394+
advise(_("Use -f if you really want to add them.\n"
395+
"Turn this message off by running\n"
396+
"\"git config advice.addIgnoredFile false\""));
395397
exit_status = 1;
396398
}
397399

@@ -481,8 +483,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
481483

482484
if (require_pathspec && pathspec.nr == 0) {
483485
fprintf(stderr, _("Nothing specified, nothing added.\n"));
484-
if (advice_add_nothing)
485-
advise( _("Maybe you wanted to say 'git add .'?\n"));
486+
if (advice_add_empty_pathspec)
487+
advise( _("Maybe you wanted to say 'git add .'?\n"
488+
"Turn this message off by running\n"
489+
"\"git config advice.addEmptyPathspec false\""));
486490
return 0;
487491
}
488492

t/t3700-add.sh

+2
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,8 @@ cat >expect.err <<\EOF
327327
The following paths are ignored by one of your .gitignore files:
328328
ignored-file
329329
hint: Use -f if you really want to add them.
330+
hint: Turn this message off by running
331+
hint: "git config advice.addIgnoredFile false"
330332
EOF
331333
cat >expect.out <<\EOF
332334
add 'track-this'

0 commit comments

Comments
 (0)