{"thread":{"id":"15245","subject":"[PATCH] grep: fix worktree setup","startedAt":"2008-08-28T13:04:30Z","lastAt":"2008-08-28T13:04:30Z","messageCount":1,"participants":["Nguyễn Thái Ngọc Duy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"88880","messageId":"1219928670-25219-1-git-send-email-pclouds@gmail.com","threadId":"15245","inReplyTo":null,"subject":"[PATCH] grep: fix worktree setup","fromName":"Nguyễn Thái Ngọc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2008-08-28T13:04:30Z","receivedAt":"2008-08-28T13:04:30Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"Unless used with --cached or grepping on a tree, \"git grep\" will\nsearch on working directory, so set up worktree properly\n\nSigned-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>\n---\n builtin-grep.c      |    5 ++++-\n t/t1501-worktree.sh |    5 +++++\n 2 files changed, 9 insertions(+), 1 deletions(-)\n\ndiff --git a/builtin-grep.c b/builtin-grep.c\nindex 631129d..3ded1ba 100644\n--- a/builtin-grep.c\n+++ b/builtin-grep.c\n@@ -783,8 +783,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tpaths[1] = NULL;\n \t}\n \n-\tif (!list.nr)\n+\tif (!list.nr) {\n+\t\tif (!cached)\n+\t\t\tsetup_work_tree();\n \t\treturn !grep_cache(&opt, paths, cached);\n+\t}\n \n \tif (cached)\n \t\tdie(\"both --cached and trees are given.\");\ndiff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh\nindex e9e352c..e60116c 100755\n--- a/t/t1501-worktree.sh\n+++ b/t/t1501-worktree.sh\n@@ -169,4 +169,9 @@ test_expect_success 'git diff' '\n \tcmp diff-FILES.expected result\n '\n \n+test_expect_success 'git grep' '\n+\t(cd repo.git/work/sub &&\n+\tGIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)\n+'\n+\n test_done\n-- \n1.6.0.96.g2fad1.dirty\n"}]}