git-add used to take the path limiters, but always considered them as top-level paths, and thus didn't work from subdirectories. However, using git-add -u from subdirectories is very convenient, especially when development is done from within a subdirectory, (e.g. for easier grepping), as it allows to use a universal incantation 'git-add -u .' from anywhere. Documentaion for git-add does not mention if the paths were supposed to be relative to current directory of from the top, and the relative paths are far more intuitive. Signed-off-by: Salikh Zakirov <salikh@xxxxxxxxx> --- The trivial test added with this patch failed before the patch and passes after. All tests pass with this modification on my machine (Linux/i686). Note that the potentially incorrect 'git-add -u ; git commit' behaviour is not affected by this patch and still can cause horribly incorrect commits. builtin-add.c | 8 ++++---- t/t2200-add-update.sh | 8 ++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin-add.c b/builtin-add.c index 82c806a..a09771f 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -109,12 +109,12 @@ static void update_callback(struct diff_queue_struct *q, } } -static void update(int verbose, const char **files) +static void update(int verbose, const char *prefix, const char **files) { struct rev_info rev; - init_revisions(&rev, ""); + init_revisions(&rev, prefix); setup_revisions(0, NULL, &rev, NULL); - rev.prune_data = get_pathspec(rev.prefix, files); + rev.prune_data = get_pathspec(prefix, files); rev.diffopt.output_format = DIFF_FORMAT_CALLBACK; rev.diffopt.format_callback = update_callback; rev.diffopt.format_callback_data = &verbose; @@ -216,7 +216,7 @@ int cmd_add(int argc, const char **argv, const char *prefix) } if (take_worktree_changes) { - update(verbose, argv + i); + update(verbose, prefix, argv + i); goto finish; } diff --git t/t2200-add-update.sh t/t2200-add-update.sh index 0a703af..93c007d 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -35,4 +35,12 @@ test_expect_success 'update did not touch other tracked files' \ test_expect_success 'update did not touch untracked files' \ 'test "`git diff-files --name-status dir/other`" = ""' +test_expect_success 'more changes' 'echo modified >> dir/sub' + +test_expect_success 'update from subdirectory' \ + '(cd dir; git add -u sub)' + +test_expect_success 'update touched correct path' \ + 'test "`git diff-files --name-status dir/sub`" = ""' + test_done -- 1.5.3.rc5.24.gac513 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html