{"thread":{"id":"9540","subject":"[PATCH] git-add -u paths... now works from subdirectory","startedAt":"2007-08-15T17:01:43Z","lastAt":"2007-08-15T22:17:20Z","messageCount":2,"participants":["Salikh Zakirov","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"50796","messageId":"20070815170143.GA3068@makoto.usen.ad.jp","threadId":"9540","inReplyTo":null,"subject":"[PATCH] git-add -u paths... now works from subdirectory","fromName":"Salikh Zakirov","fromEmail":"salikh.zakirov@gmail.com","sentAt":"2007-08-15T17:01:43Z","receivedAt":"2007-08-15T17:01:43Z","isPatch":true,"sender":{"key":"salikh.zakirov@gmail.com","avatar":null},"body":"git-add used to take the path limiters, but always considered them\nas top-level paths, and thus didn't work from subdirectories.\nHowever, using git-add -u from subdirectories is very convenient,\nespecially when development is done from within a subdirectory,\n(e.g. for easier grepping), as it allows to use a universal\nincantation 'git-add -u .' from anywhere.\n\nDocumentaion for git-add does not mention if the paths were supposed to be\nrelative to current directory of from the top, and the relative paths are far\nmore intuitive.\n\nSigned-off-by: Salikh Zakirov <salikh@gmail.com>\n---\n\nThe trivial test added with this patch failed before the patch and passes\nafter. All tests pass with this modification on my machine (Linux/i686).\n\nNote that the potentially incorrect 'git-add -u ; git commit' behaviour is not\naffected by this patch and still can cause horribly incorrect commits.\n\n builtin-add.c         |    8 ++++----\n t/t2200-add-update.sh |    8 ++++++++\n 2 files changed, 12 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin-add.c b/builtin-add.c\nindex 82c806a..a09771f 100644\n--- a/builtin-add.c\n+++ b/builtin-add.c\n@@ -109,12 +109,12 @@ static void update_callback(struct diff_queue_struct *q,\n \t}\n }\n \n-static void update(int verbose, const char **files)\n+static void update(int verbose, const char *prefix, const char **files)\n {\n \tstruct rev_info rev;\n-\tinit_revisions(&rev, \"\");\n+\tinit_revisions(&rev, prefix);\n \tsetup_revisions(0, NULL, &rev, NULL);\n-\trev.prune_data = get_pathspec(rev.prefix, files);\n+\trev.prune_data = get_pathspec(prefix, files);\n \trev.diffopt.output_format = DIFF_FORMAT_CALLBACK;\n \trev.diffopt.format_callback = update_callback;\n \trev.diffopt.format_callback_data = &verbose;\n@@ -216,7 +216,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (take_worktree_changes) {\n-\t\tupdate(verbose, argv + i);\n+\t\tupdate(verbose, prefix, argv + i);\n \t\tgoto finish;\n \t}\n \ndiff --git t/t2200-add-update.sh t/t2200-add-update.sh\nindex 0a703af..93c007d 100755\n--- a/t/t2200-add-update.sh\n+++ b/t/t2200-add-update.sh\n@@ -35,4 +35,12 @@ test_expect_success 'update did not touch other tracked files' \\\n test_expect_success 'update did not touch untracked files' \\\n   'test \"`git diff-files --name-status dir/other`\" = \"\"'\n \n+test_expect_success 'more changes' 'echo modified >> dir/sub'\n+\n+test_expect_success 'update from subdirectory' \\\n+  '(cd dir; git add -u sub)'\n+\n+test_expect_success 'update touched correct path' \\\n+  'test \"`git diff-files --name-status dir/sub`\" = \"\"'\n+\n test_done\n-- \n1.5.3.rc5.24.gac513\n"},{"id":"50831","messageId":"7vk5rwo32n.fsf@gitster.siamese.dyndns.org","threadId":"9540","inReplyTo":"20070815170143.GA3068@makoto.usen.ad.jp","subject":"Re: [PATCH] git-add -u paths... now works from subdirectory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-08-15T22:17:20Z","receivedAt":"2007-08-15T22:17:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks.\n"}]}