From: "Daniel Sonbolian via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Daniel Sonbolian <dsal3389@gmail.com>,
Daniel Sonbolian <dsal3389@gmail.com>
Subject: [PATCH] git.c: fix, stop passing options after --help
Date: Mon, 10 Oct 2022 16:17:57 +0000 [thread overview]
Message-ID: <pull.1357.git.git.1665418677535.gitgitgadget@gmail.com> (raw)
From: Daniel Sonbolian <dsal3389@gmail.com>
Since commit c6b6d9f7d8a when passing --help option
to a Git command, we try to open that command man page, we
do it for both commands and concepts, it is done by
converting the entered command to a help command
for the given Git command, for example:
"git commit --help -i" into "git help --exclude-guides commit -i"
But the options after --help option are also
passed to the new command (-i option from the example)
which can lead to unexpected output, because the
help command will try to execute those extra options.
This fixed by building the argv statically, meaning
instead of switching places between argv arguments and then
passing all the arguments to a new memory vector that will
later be used as the new argv, we directly passing that
memory vector only the required arguments and in the
correct order, after that we also updating the
argc to a static number:
strvec_push(&args, "help"); // argv[0]
strvec_push(&args, "--exclude-guides"); // argv[1]
strvec_push(&args, argv[0]); // argv[2]
argv = args.v;
argc = 3; // update based on the amount of pushs we did
Now no matter how many arguments we pass after
the --help, the results will always stay the same:
"git commit --help foo-hello-world"
"git commit --help pull -i -f"
"git commit --help -i"
|
v
"git help --exclude-guides commit"
Signed-off-by: Daniel Sonbolian <dsal3389@gmail.com>
---
git.c: fix, passing options after --help
Since commit c6b6d9f7d8a when passing --help option to a Git command, we
try to open that command man page, we do it for both commands and
concepts, it is done by converting the entered command to a help command
for the given Git command, for example:
"git commit --help -i" into "git help --exclude-guides commit -i"
But the options after --help option are also passed to the new command
(-i option from the example) which can lead to unexpected output,
because the help command will try to execute those extra options.
This fixed by building the argv statically, meaning instead of switching
places between argv arguments and then passing all the arguments to a
new memory vector that will later be used as the new argv, we directly
passing that memory vector only the required arguments and in the
correct order, after that we also updating the argc to a static number:
strvec_push(&args, "help"); // argv[0]
strvec_push(&args, "--exclude-guides"); // argv[1]
strvec_push(&args, argv[0]); // argv[2]
argv = args.v;
argc = 3; // update based on the amount of pushs we did
Now no matter how many arguments we pass after the --help, the results
will always stay the same:
"git commit --help foo-hello-world"
"git commit --help pull -i -f"
"git commit --help -i"
|
v
"git help --exclude-guides commit"
Signed-off-by: Daniel Sonbolian dsal3389@gmail.com
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1357%2Fdsal3389%2Fcmd-help-tweaks-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1357/dsal3389/cmd-help-tweaks-v1
Pull-Request: https://github.com/git/git/pull/1357
git.c | 18 ++++++------------
1 file changed, 6 insertions(+), 12 deletions(-)
diff --git a/git.c b/git.c
index da411c53822..75dcefa534d 100644
--- a/git.c
+++ b/git.c
@@ -697,25 +697,19 @@ static void handle_builtin(int argc, const char **argv)
struct cmd_struct *builtin;
strip_extension(argv);
- cmd = argv[0];
/* Turn "git cmd --help" into "git help --exclude-guides cmd" */
if (argc > 1 && !strcmp(argv[1], "--help")) {
- int i;
-
- argv[1] = argv[0];
- argv[0] = cmd = "help";
-
- for (i = 0; i < argc; i++) {
- strvec_push(&args, argv[i]);
- if (!i)
- strvec_push(&args, "--exclude-guides");
- }
+ strvec_push(&args, "help");
+ strvec_push(&args, "--exclude-guides");
+ strvec_push(&args, argv[0]);
- argc++;
argv = args.v;
+ argc = 3;
}
+ cmd = argv[0];
+
builtin = get_builtin(cmd);
if (builtin)
exit(run_builtin(builtin, argc, argv));
base-commit: 3dcec76d9df911ed8321007b1d197c1a206dc164
--
gitgitgadget
next reply other threads:[~2022-10-10 16:18 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-10 16:17 Daniel Sonbolian via GitGitGadget [this message]
2022-10-10 18:58 ` [PATCH] git.c: fix, stop passing options after --help Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1357.git.git.1665418677535.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=dsal3389@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).