diff options
author | Jeff King <peff@peff.net> | 2017-05-30 01:11:23 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2017-05-30 14:39:47 +0900 |
commit | f3a2fffe06d13b216cbc18acba5a46b8a00ae326 (patch) | |
tree | e1c0add6c48819ef7ceb42a1d71aae3ee54b897b /builtin | |
parent | Git 2.13 (diff) | |
download | tgif-f3a2fffe06d13b216cbc18acba5a46b8a00ae326.tar.xz |
am: handle "-h" argument earlier
If the user provides "-h" on the command line, then our
parse_options() invocation will show a usage message and
quit. But if "-h" is the only argument, the git wrapper
behaves specially: it ignores our RUN_SETUP flag and calls
cmd_am() without having done repository setup at all. This
is due to 99caeed05 (Let 'git <command> -h' show usage
without a git dir, 2009-11-09).
Before cmd_am() calls parse_options(), though, it runs a few
other setup functions. One of these is am_state_init(),
which uses git_pathdup() to set up the default rebase-apply
path. But calling git_pathdup() when we haven't done
repository setup will fall back to using ".git". That's
mostly harmless (since we won't use the value anyway), but
is forbidden since b1ef400eec ("setup_git_env: avoid blind
fall-back to ".git"", 2016-10-20), and we now BUG().
We can't easily move that setup to after the parse_options()
call; the point is to set up defaults that are overwritten
by the option parsing. Instead, we'll detect the "-h" case
early and show the usage then. This matches the behavior of
other builtins which have a similar setup-ordering issue
(e.g., git-branch).
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/am.c | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/builtin/am.c b/builtin/am.c index a95dd8b4e6..c74df14722 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -2319,6 +2319,9 @@ int cmd_am(int argc, const char **argv, const char *prefix) OPT_END() }; + if (argc == 2 && !strcmp(argv[1], "-h")) + usage_with_options(usage, options); + git_config(git_am_config, NULL); am_state_init(&state); |