@matheusbsbs / matheus-bagliano / commits / bf66db37f1
Fork 0

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 <heba.waly@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Heba Waly committed Jan 7, 2020 at 23:12 UTC bf66db37f1e17b71e8edb93d78ec407fbc1e0989
4 files changed +8 -3
advice.c
+2
@@ -31,6 +31,7 @@ int advice_graft_file_deprecated = 1;
31 int advice_checkout_ambiguous_remote_branch_name = 1;
32 int advice_nested_tag = 1;
33 int advice_submodule_alternate_error_strategy_die = 1;
34 +int advice_add_nothing = 1;
35
36 static int advice_use_color = -1;
37 static char advice_colors[][COLOR_MAXLEN] = {
@@ -91,6 +92,7 @@ static struct {
92 { "checkoutAmbiguousRemoteBranchName", &advice_checkout_ambiguous_remote_branch_name },
93 { "nestedTag", &advice_nested_tag },
94 { "submoduleAlternateErrorStrategyDie", &advice_submodule_alternate_error_strategy_die },
95 + { "addNothing", &advice_add_nothing },
96
97 /* make this an alias for backward compatibility */
98 { "pushNonFastForward", &advice_push_update_rejected }
advice.h
+1
@@ -31,6 +31,7 @@ extern int advice_graft_file_deprecated;
31 extern int advice_checkout_ambiguous_remote_branch_name;
32 extern int advice_nested_tag;
33 extern int advice_submodule_alternate_error_strategy_die;
34 +extern int advice_add_nothing;
35
36 int git_default_advice_config(const char *var, const char *value);
37 __attribute__((format (printf, 1, 2)))
builtin/add.c
+4 -2
@@ -390,7 +390,8 @@ static int add_files(struct dir_struct *dir, int flags)
390 fprintf(stderr, _(ignore_error));
391 for (i = 0; i < dir->ignored_nr; i++)
392 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"));
395 exit_status = 1;
396 }
397
@@ -480,7 +481,8 @@ int cmd_add(int argc, const char **argv, const char *prefix)
481
482 if (require_pathspec && pathspec.nr == 0) {
483 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"));
486 return 0;
487 }
488
t/t3700-add.sh
+1 -1
@@ -326,7 +326,7 @@ test_expect_success 'git add --dry-run of an existing file output' "
326 cat >expect.err <<\EOF
327 The following paths are ignored by one of your .gitignore files:
328 ignored-file
329 -Use -f if you really want to add them.
329 +hint: Use -f if you really want to add them.
330 EOF
331 cat >expect.out <<\EOF
332 add 'track-this'