[PATCH v8 2/2] interpret_trailers: for three options parse add warning
- From
ZheNing Hu via GitGitGadget <gitgitgadget@gmail.com>
- Date
- Mar 15, 2021, 13:07 UTC
- Message-ID
- <68e0bd9e2d6f0a89d60db730eb77507d6a17a5ae.1615813658.git.gitgitgadget@gmail.com>
- In-Reply-To
- <pull.901.v8.git.1615813658.gitgitgadget@gmail.com>
From: ZheNing Hu <adlternative@gmail.com>
When using `interpret-trailers`, if user accidentally fill in the wrong option values (e.g. `--if-exists=addd` or `--where=begin` or `--if-missing=do-nothing`), git will exit quietly, and the user may not even know what happened.
So lets provides warnings when git parsing this three options: "unknown value '%s' for key ('where'|'--if-exist'|'--if-missing')". This will remind the user :"Oh, it was because of my spelling error." (or using a synonym for error).
Signed-off-by: ZheNing Hu <adlternative@gmail.com> --- builtin/interpret-trailers.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-)
diff --git a/builtin/interpret-trailers.c b/builtin/interpret-trailers.c index 84748eafc01b..6d8e86a44d43 100644 --- a/builtin/interpret-trailers.c +++ b/builtin/interpret-trailers.c @@ -24,19 +24,38 @@ static enum trailer_if_missing if_missing; static int option_parse_where(const struct option *opt, const char *arg, int unset) { - return trailer_set_where(&where, arg); + int ret; + + ret = trailer_set_where(&where, arg); + if (ret) + warning(_("unknown value '%s' for key 'where'"), + arg); + return ret; + } static int option_parse_if_exists(const struct option *opt, const char *arg, int unset) { - return trailer_set_if_exists(&if_exists, arg); + int ret; + + ret = trailer_set_if_exists(&if_exists, arg); + if (ret) + warning(_("unknown value '%s' for key 'if_exists'"), + arg); + return ret; } static int option_parse_if_missing(const struct option *opt, const char *arg, int unset) { - return trailer_set_if_missing(&if_missing, arg); + int ret; + + ret = trailer_set_if_missing(&if_missing, arg); + if (ret) + warning(_("unknown value '%s' for key 'if_missing'"), + arg); + return ret; } static void new_trailers_clear(struct list_head *trailers)
-- gitgitgadget