Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2022-05-21 01:26:52 +0300
committerJunio C Hamano <gitster@pobox.com>2022-05-21 01:26:53 +0300
commit4976f244f3cd8a9161fdbcc3cfd1ed7b65bb349e (patch)
treee379593c50747e24ecb5b8ff1c8e7c454225dde3 /git.c
parent796388bebdd4942a689a9356e26dbb0d8affea08 (diff)
parent6b52f48b8f1cda8d428d3e4fe685bd28713f293f (diff)
Merge branch 'gf/shorthand-version-and-help'
"git -v" and "git -h" are now understood as "git --version" and "git --help". * gf/shorthand-version-and-help: cli: add -v and -h shorthands
Diffstat (limited to 'git.c')
-rw-r--r--git.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/git.c b/git.c
index 3d8e48cf55..5ff4f3e25b 100644
--- a/git.c
+++ b/git.c
@@ -25,7 +25,7 @@ struct cmd_struct {
};
const char git_usage_string[] =
- N_("git [--version] [--help] [-C <path>] [-c <name>=<value>]\n"
+ N_("git [-v | --version] [-h | --help] [-C <path>] [-c <name>=<value>]\n"
" [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]\n"
" [-p | --paginate | -P | --no-pager] [--no-replace-objects] [--bare]\n"
" [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]\n"
@@ -146,7 +146,8 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
* commands can be written with "--" prepended
* to make them look like flags.
*/
- if (!strcmp(cmd, "--help") || !strcmp(cmd, "--version"))
+ if (!strcmp(cmd, "--help") || !strcmp(cmd, "-h") ||
+ !strcmp(cmd, "--version") || !strcmp(cmd, "-v"))
break;
/*
@@ -893,8 +894,10 @@ int cmd_main(int argc, const char **argv)
argc--;
handle_options(&argv, &argc, NULL);
if (argc > 0) {
- /* translate --help and --version into commands */
- skip_prefix(argv[0], "--", &argv[0]);
+ if (!strcmp("--version", argv[0]) || !strcmp("-v", argv[0]))
+ argv[0] = "version";
+ else if (!strcmp("--help", argv[0]) || !strcmp("-h", argv[0]))
+ argv[0] = "help";
} else {
/* The user didn't specify a command; give them help */
commit_pager_choice();