From: Ayman Bagabas <ayman.bagabas@xxxxxxxxx> This patch allows overriding 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 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. CC: Junio C Hamano <gitster@xxxxxxxxx>, Jeff King <peff@xxxxxxxx> CC: Taylor Blau <me@xxxxxxxxxxxx> Signed-off-by: Ayman Bagabas <ayman.bagabas@xxxxxxxxx> --- [RFC] shell: allow overriding built-in commands Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-1930%2Faymanbagabas%2Fshell-override-v1 Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-1930/aymanbagabas/shell-override-v1 Pull-Request: https://github.com/git/git/pull/1930 shell.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/shell.c b/shell.c index 76333c80686..3a6d2e8a044 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,16 @@ 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); + } } - cd_to_homedir(); count = split_cmdline(prog, &user_argv); if (count >= 0) { if (is_valid_cmd_name(user_argv[0])) { base-commit: 683c54c999c301c2cd6f715c411407c413b1d84e -- gitgitgadget