From: "Ayman Bagabas via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Elijah Newren" <newren@gmail.com>,
"Junio C Hamano" <gitster@pobox.com>, "Jeff King" <peff@peff.net>,
"Taylor Blau" <me@ttaylorr.com>,
"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
"Ayman Bagabas" <ayman.bagabas@gmail.com>,
"Ayman Bagabas" <ayman.bagabas@gmail.com>
Subject: [PATCH v2] shell: allow overriding built-in commands
Date: Sun, 23 Mar 2025 00:12:20 +0000 [thread overview]
Message-ID: <pull.1930.v2.git.git.1742688740650.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1930.git.git.1742637713157.gitgitgadget@gmail.com>
From: Ayman Bagabas <ayman.bagabas@gmail.com>
This patch allows overriding the shell built-in commands by placing a
script with the same name under git-shell-commands directory.
This is useful for users who want to extend the shell built-in commands
without replacing the original command binary. For instance, a user
wanting to allow only a subset of users to run the git-receive-pack can
override the command with a script that checks the user and calls the
original command if the user is allowed.
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
---
shell: allow overriding built-in commands
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1930%2Faymanbagabas%2Fshell-override-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1930/aymanbagabas/shell-override-v2
Pull-Request: https://github.com/git/git/pull/1930
Range-diff vs v1:
1: 4fe18878afa ! 1: 60c6339e790 [RFC] shell: allow overriding built-in commands
@@ Metadata
Author: Ayman Bagabas <ayman.bagabas@gmail.com>
## Commit message ##
- [RFC] shell: allow overriding built-in commands
+ shell: allow overriding built-in commands
- This patch allows overriding built-in commands by placing a script
- with the same name under git-shell-commands directory.
+ This patch allows overriding the shell built-in commands by placing a
+ script with the same name under git-shell-commands directory.
- This is useful for users who want to extend the built-in commands
+ This is useful for users who want to extend the shell built-in commands
without replacing the original command binary. For instance, a user
- wanting to allow only a subset of users to run the git-receive-pack
- can override the command with a script that checks the user and
- calls the original command if the user is allowed.
+ wanting to allow only a subset of users to run the git-receive-pack can
+ override the command with a script that checks the user and calls the
+ original command if the user is allowed.
- CC: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
- CC: Taylor Blau <me@ttaylorr.com>
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
## shell.c ##
@@ shell.c: int cmd_main(int argc, const char **argv)
default:
continue;
}
-- return cmd->exec(cmd->name, arg);
+ /* Allow overriding built-in commands */
+ full_cmd = make_cmd(cmd->name);
+ if (!access(full_cmd, F_OK)) {
+ const char *argv[3] = { cmd->name, arg, NULL };
+ return execv(full_cmd, (char *const *) argv);
-+ } else {
-+ return cmd->exec(cmd->name, arg);
+ }
+ return cmd->exec(cmd->name, arg);
}
- cd_to_homedir();
shell.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/shell.c b/shell.c
index 76333c80686..76c0157e321 100644
--- a/shell.c
+++ b/shell.c
@@ -194,9 +194,11 @@ int cmd_main(int argc, const char **argv)
/* Accept "git foo" as if the caller said "git-foo". */
prog[3] = '-';
+ cd_to_homedir();
for (cmd = cmd_list ; cmd->name ; cmd++) {
int len = strlen(cmd->name);
char *arg;
+ char *full_cmd;
if (strncmp(cmd->name, prog, len))
continue;
arg = NULL;
@@ -210,10 +212,15 @@ int cmd_main(int argc, const char **argv)
default:
continue;
}
+ /* Allow overriding built-in commands */
+ full_cmd = make_cmd(cmd->name);
+ if (!access(full_cmd, F_OK)) {
+ const char *argv[3] = { cmd->name, arg, NULL };
+ return execv(full_cmd, (char *const *) argv);
+ }
return cmd->exec(cmd->name, arg);
}
- cd_to_homedir();
count = split_cmdline(prog, &user_argv);
if (count >= 0) {
if (is_valid_cmd_name(user_argv[0])) {
base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e
--
gitgitgadget
next prev parent reply other threads:[~2025-03-23 0:12 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-22 10:01 [PATCH] [RFC] shell: allow overriding built-in commands Ayman Bagabas via GitGitGadget
2025-03-22 17:39 ` Elijah Newren
2025-03-22 18:02 ` Ayman Bagabas
2025-03-22 18:26 ` Elijah Newren
2025-03-23 0:12 ` Ayman Bagabas via GitGitGadget [this message]
2025-03-23 1:11 ` [PATCH v2] " Chris Torek
2025-03-23 15:05 ` Ayman Bagabas
2025-03-23 15:12 ` Chris Torek
2025-03-23 15:29 ` [PATCH v3] " Ayman Bagabas via GitGitGadget
2025-03-24 3:25 ` Jeff King
2025-03-24 5:27 ` Junio C Hamano
2025-03-24 20:28 ` Jeff King
2025-03-25 22:44 ` Ayman Bagabas
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=pull.1930.v2.git.git.1742688740650.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=avarab@gmail.com \
--cc=ayman.bagabas@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=me@ttaylorr.com \
--cc=newren@gmail.com \
--cc=peff@peff.net \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.