diff options
author | Junio C Hamano <gitster@pobox.com> | 2007-11-25 10:10:10 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-11-25 10:23:13 -0800 |
commit | 3f061887c562b20d3ed3d1f764462cf986a1ad12 (patch) | |
tree | 636a0f9c085aac7ba539ef2ace03b3081481891a /builtin-add.c | |
parent | 324ccbd6a09816af830b22b02bbeb06349141849 (diff) | |
download | git-3f061887c562b20d3ed3d1f764462cf986a1ad12.tar.gz |
add -i: Fix running from a subdirectory
This fixes the pathspec interactive_add() passes to the underlying
git-add--interactive helper. When the command was run from a
subdirectory, cmd_add() already has gone up to the toplevel of the work
tree, and the helper will be spawned from there. The pathspec given on
the command line from the user needs to be adjusted for this.
This adds "validate_pathspec()" function in the callchain, but it does
not validate yet. The function can be changed to barf if there are
unmatching pathspec given by the user, but that is not strictly
necessary.
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-add.c')
-rw-r--r-- | builtin-add.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/builtin-add.c b/builtin-add.c index 7c6a296af1..865c475ec9 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -135,13 +135,29 @@ static void refresh(int verbose, const char **pathspec) free(seen); } -int interactive_add(int argc, const char **argv) +static const char **validate_pathspec(int argc, const char **argv, const char *prefix) +{ + const char **pathspec = get_pathspec(prefix, argv); + + return pathspec; +} + +int interactive_add(int argc, const char **argv, const char *prefix) { int status; - const char **args = xcalloc(sizeof(const char *), (argc + 2)); + const char **args; + const char **pathspec = NULL; + + if (argc) { + pathspec = validate_pathspec(argc, argv, prefix); + if (!pathspec) + return -1; + } + args = xcalloc(sizeof(const char *), (argc + 2)); args[0] = "add--interactive"; - memcpy(&(args[1]), argv, sizeof(const char *) * argc); + if (argc) + memcpy(&(args[1]), pathspec, sizeof(const char *) * argc); args[argc + 1] = NULL; status = run_command_v_opt(args, RUN_GIT_CMD); @@ -177,7 +193,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) argc = parse_options(argc, argv, builtin_add_options, builtin_add_usage, 0); if (add_interactive) - exit(interactive_add(argc, argv)); + exit(interactive_add(argc, argv, prefix)); git_config(git_default_config); |