summaryrefslogtreecommitdiff
path: root/builtin/help.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-10-26 05:22:13 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-26 05:22:13 (GMT)
commit7752999cd6bbe1aff4e34f83ed078ffffc232667 (patch)
tree30af3445c8f1b76a70417b6ef3e71293a730c74e /builtin/help.c
parentd1f96fd84d362a31dd8a26ae18c10539e07cd600 (diff)
parent912104770d1b3b009a58e95ae57f6db65791b031 (diff)
downloadgit-7752999cd6bbe1aff4e34f83ed078ffffc232667.zip
git-7752999cd6bbe1aff4e34f83ed078ffffc232667.tar.gz
git-7752999cd6bbe1aff4e34f83ed078ffffc232667.tar.bz2
Merge branch 'rv/alias-help'
"git cmd --help" when "cmd" is aliased used to only say "cmd is aliased to ...". Now it shows that to the standard error stream and runs "git $cmd --help" where $cmd is the first word of the alias expansion. This could be misleading for those who alias a command with options (e.g. with "[alias] cpn = cherry-pick -n", "git cpn --help" would show the manual of "cherry-pick", and the reader would not be told to pay close attention to the part that describes the "--no-commit" option until closing the pager that showed the contents of the manual, if the pager is configured to restore the original screen, or would not be told at all, if the pager simply makes the message on the standard error scroll away. * rv/alias-help: git-help.txt: document "git help cmd" vs "git cmd --help" for aliases git.c: handle_alias: prepend alias info when first argument is -h help: redirect to aliased commands for "git cmd --help"
Diffstat (limited to 'builtin/help.c')
-rw-r--r--builtin/help.c34
1 files changed, 31 insertions, 3 deletions
diff --git a/builtin/help.c b/builtin/help.c
index d83dac2..7739a5c 100644
--- a/builtin/help.c
+++ b/builtin/help.c
@@ -415,9 +415,37 @@ static const char *check_git_cmd(const char* cmd)
alias = alias_lookup(cmd);
if (alias) {
- printf_ln(_("'%s' is aliased to '%s'"), cmd, alias);
- free(alias);
- exit(0);
+ const char **argv;
+ int count;
+
+ /*
+ * handle_builtin() in git.c rewrites "git cmd --help"
+ * to "git help --exclude-guides cmd", so we can use
+ * exclude_guides to distinguish "git cmd --help" from
+ * "git help cmd". In the latter case, or if cmd is an
+ * alias for a shell command, just print the alias
+ * definition.
+ */
+ if (!exclude_guides || alias[0] == '!') {
+ printf_ln(_("'%s' is aliased to '%s'"), cmd, alias);
+ free(alias);
+ exit(0);
+ }
+ /*
+ * Otherwise, we pretend that the command was "git
+ * word0 --help". We use split_cmdline() to get the
+ * first word of the alias, to ensure that we use the
+ * same rules as when the alias is actually
+ * used. split_cmdline() modifies alias in-place.
+ */
+ fprintf_ln(stderr, _("'%s' is aliased to '%s'"), cmd, alias);
+ count = split_cmdline(alias, &argv);
+ if (count < 0)
+ die(_("bad alias.%s string: %s"), cmd,
+ split_cmdline_strerror(count));
+ free(argv);
+ UNLEAK(alias);
+ return alias;
}
if (exclude_guides)