Skip to content

Commit daef1b3

Browse files
committed
Merge branch 'hw/advice-add-nothing'
Two help messages given when "git add" notices the user gave it nothing to add have been updated to use advise() API. * hw/advice-add-nothing: add: change advice config variables used by the add API add: use advise function to display hints
2 parents d8437c5 + 887a0fd commit daef1b3

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

Documentation/config/advice.txt

Lines changed: 6 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +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_ignored_file = 1;
35+
int advice_add_empty_pathspec = 1;
3436

3537
static int advice_use_color = -1;
3638
static char advice_colors[][COLOR_MAXLEN] = {
@@ -91,6 +93,8 @@ static struct {
9193
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
9294
{ "nestedTag", &advice_nested_tag },
9395
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
96+
{ "addIgnoredFile", &advice_add_ignored_file },
97+
{ "addEmptyPathspec", &advice_add_empty_pathspec },
9498

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

advice.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +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_ignored_file;
35+
extern int advice_add_empty_pathspec;
3436

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

builtin/add.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,10 @@ static int add_files(struct dir_struct *dir, int flags)
406406
fprintf(stderr, _(ignore_error));
407407
for (i = 0; i < dir->ignored_nr; i++)
408408
fprintf(stderr, "%s\n", dir->ignored[i]->name);
409-
fprintf(stderr, _("Use -f if you really want to add them.\n"));
409+
if (advice_add_ignored_file)
410+
advise(_("Use -f if you really want to add them.\n"
411+
"Turn this message off by running\n"
412+
"\"git config advice.addIgnoredFile false\""));
410413
exit_status = 1;
411414
}
412415

@@ -507,7 +510,10 @@ int cmd_add(int argc, const char **argv, const char *prefix)
507510

508511
if (require_pathspec && pathspec.nr == 0) {
509512
fprintf(stderr, _("Nothing specified, nothing added.\n"));
510-
fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n"));
513+
if (advice_add_empty_pathspec)
514+
advise( _("Maybe you wanted to say 'git add .'?\n"
515+
"Turn this message off by running\n"
516+
"\"git config advice.addEmptyPathspec false\""));
511517
return 0;
512518
}
513519

t/t3700-add.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ test_expect_success 'git add --dry-run of an existing file output' "
326326
cat >expect.err <<\EOF
327327
The following paths are ignored by one of your .gitignore files:
328328
ignored-file
329-
Use -f if you really want to add them.
329+
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'

t/t7400-submodule-basic.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ test_expect_success 'submodule add to .gitignored path fails' '
158158
cat <<-\EOF >expect &&
159159
The following paths are ignored by one of your .gitignore files:
160160
submod
161-
Use -f if you really want to add them.
161+
hint: Use -f if you really want to add them.
162+
hint: Turn this message off by running
163+
hint: "git config advice.addIgnoredFile false"
162164
EOF
163165
# Does not use test_commit due to the ignore
164166
echo "*" > .gitignore &&

0 commit comments

Comments
 (0)