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>
Junio C Hamano committed
Nov 25, 2007 at 10:10 UTC
3f061887c562b20d3ed3d1f764462cf986a1ad12
3 files changed
+22
-6
builtin-add.c
+20
-4
@@ -135,13 +135,29 @@ static void refresh(int verbose, const char **pathspec)
135
free(seen);
136
}
137
138
-int interactive_add(int argc, const char **argv)
138
+static const char **validate_pathspec(int argc, const char **argv, const char *prefix)
139
+{
140
+ const char **pathspec = get_pathspec(prefix, argv);
141
+
142
+ return pathspec;
143
+}
144
+
145
+int interactive_add(int argc, const char **argv, const char *prefix)
146
{
147
int status;
141
- const char **args = xcalloc(sizeof(const char *), (argc + 2));
148
+ const char **args;
149
+ const char **pathspec = NULL;
150
+
151
+ if (argc) {
152
+ pathspec = validate_pathspec(argc, argv, prefix);
153
+ if (!pathspec)
154
+ return -1;
155
+ }
156
157
+ args = xcalloc(sizeof(const char *), (argc + 2));
158
args[0] = "add--interactive";
144
- memcpy(&(args[1]), argv, sizeof(const char *) * argc);
159
+ if (argc)
160
+ memcpy(&(args[1]), pathspec, sizeof(const char *) * argc);
161
args[argc + 1] = NULL;
162
163
status = run_command_v_opt(args, RUN_GIT_CMD);
@@ -177,7 +193,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
193
argc = parse_options(argc, argv, builtin_add_options,
194
builtin_add_usage, 0);
195
if (add_interactive)
180
- exit(interactive_add(argc, argv));
196
+ exit(interactive_add(argc, argv, prefix));
197
198
git_config(git_default_config);
199
builtin-commit.c
+1
-1
@@ -165,7 +165,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix)
165
const char **pathspec = NULL;
166
167
if (interactive) {
168
- interactive_add(argc, argv);
168
+ interactive_add(argc, argv, prefix);
169
commit_style = COMMIT_AS_IS;
170
return get_index_file();
171
}
commit.h
+1
-1
@@ -113,7 +113,7 @@ extern struct commit_list *get_shallow_commits(struct object_array *heads,
113
114
int in_merge_bases(struct commit *, struct commit **, int);
115
116
-extern int interactive_add(int argc, const char **argv);
116
+extern int interactive_add(int argc, const char **argv, const char *prefix);
117
extern int rerere(void);
118
119
static inline int single_parent(struct commit *commit)