am: move advice.amWorkDir parsing back to advice.c
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 26 May 2018 13:55:27 +0000 (15:55 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 29 May 2018 05:51:28 +0000 (14:51 +0900)
The only benefit from this move (apart from cleaner code) is that
advice.amWorkDir should now show up in `git help --config`. There
should be no regression since advice config is always read by the
git_default_config().

While at there, use advise() like other code. We now get "hint: "
prefix and the output is stderr instead of stdout (which is also the
reason for the test update because stderr is checked in a following
test and the extra advice can fail it).

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
advice.c
advice.h
builtin/am.c
t/t4254-am-corrupt.sh
index 2aca11f45e1ed33e821c5cfd74dd710047b23617..52aa85bdfd9e9054c24445f259125bc4b81be038 100644 (file)
--- a/advice.c
+++ b/advice.c
@@ -17,6 +17,7 @@ int advice_implicit_identity = 1;
 int advice_detached_head = 1;
 int advice_set_upstream_failure = 1;
 int advice_object_name_warning = 1;
+int advice_amworkdir = 1;
 int advice_rm_hints = 1;
 int advice_add_embedded_repo = 1;
 int advice_ignored_hook = 1;
@@ -68,6 +69,7 @@ static struct {
        { "detachedHead", &advice_detached_head },
        { "setupStreamFailure", &advice_set_upstream_failure },
        { "objectNameWarning", &advice_object_name_warning },
+       { "amWorkDir", &advice_amworkdir },
        { "rmHints", &advice_rm_hints },
        { "addEmbeddedRepo", &advice_add_embedded_repo },
        { "ignoredHook", &advice_ignored_hook },
index 9f5064e82a862e6daaabe3f23ea9ea896aad87e6..7e9377864f8fca1051ce3fd27f3def62b8d234eb 100644 (file)
--- a/advice.h
+++ b/advice.h
@@ -17,6 +17,7 @@ extern int advice_implicit_identity;
 extern int advice_detached_head;
 extern int advice_set_upstream_failure;
 extern int advice_object_name_warning;
+extern int advice_amworkdir;
 extern int advice_rm_hints;
 extern int advice_add_embedded_repo;
 extern int advice_ignored_hook;
index d834f9e62b6a0f5550909b5a0bb43cce0e48e8ec..93130aaa3544a0f7b0aa5154ad0169f5afa31046 100644 (file)
@@ -1827,15 +1827,11 @@ static void am_run(struct am_state *state, int resume)
                }
 
                if (apply_status) {
-                       int advice_amworkdir = 1;
-
                        printf_ln(_("Patch failed at %s %.*s"), msgnum(state),
                                linelen(state->msg), state->msg);
 
-                       git_config_get_bool("advice.amworkdir", &advice_amworkdir);
-
                        if (advice_amworkdir)
-                               printf_ln(_("Use 'git am --show-current-patch' to see the failed patch"));
+                               advise(_("Use 'git am --show-current-patch' to see the failed patch"));
 
                        die_user_resolve(state);
                }
index 168739c7214c764ef7f35a83063d369c1db22ec4..fd3bdbfe2c0a30a0b712b1a59c2bacf0efde167c 100755 (executable)
@@ -25,7 +25,7 @@ test_expect_success setup '
 #   fatal: unable to write file '(null)' mode 100644: Bad address
 # Also, it had the unwanted side-effect of deleting f.
 test_expect_success 'try to apply corrupted patch' '
-       test_must_fail git am bad-patch.diff 2>actual
+       test_must_fail git -c advice.amWorkDir=false am bad-patch.diff 2>actual
 '
 
 test_expect_success 'compare diagnostic; ensure file is still here' '