Skip to content

Commit bf66db3

Browse files
HebaWalygitster
authored andcommitted
add: use advise function to display hints
Use the advise function in advice.c to display hints to the users, as it provides a neat and a standard format for hint messages, i.e: the text is colored in yellow and the line starts by the word "hint:". Also this will enable us to control the messages using advice.* configuration variables. Signed-off-by: Heba Waly <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d0654dc commit bf66db3

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

advice.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ 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;
3435

3536
static int advice_use_color = -1;
3637
static char advice_colors[][COLOR_MAXLEN] = {
@@ -91,6 +92,7 @@ static struct {
9192
{ "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
9293
{ "nestedTag", &advice_nested_tag },
9394
{ "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
95+
{ "addNothing", &advice_add_nothing },
9496

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

advice.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ 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;
3435

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

builtin/add.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,8 @@ 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-
fprintf(stderr, _("Use -f if you really want to add them.\n"));
393+
if (advice_add_nothing)
394+
advise(_("Use -f if you really want to add them.\n"));
394395
exit_status = 1;
395396
}
396397

@@ -480,7 +481,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
480481

481482
if (require_pathspec && pathspec.nr == 0) {
482483
fprintf(stderr, _("Nothing specified, nothing added.\n"));
483-
fprintf(stderr, _("Maybe you wanted to say 'git add .'?\n"));
484+
if (advice_add_nothing)
485+
advise( _("Maybe you wanted to say 'git add .'?\n"));
484486
return 0;
485487
}
486488

t/t3700-add.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ 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.
330330
EOF
331331
cat >expect.out <<\EOF
332332
add 'track-this'

0 commit comments

Comments
 (0)