@matheusbsbs / matheus-bagliano / commits / 6577f542b3
Fork 0

grep: fix worktree setup

Unless used with --cached or grepping on a tree, "git grep" will search on working directory, so set up worktree properly Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Aug 28, 2008 at 20:04 UTC 6577f542b3ab64594c7d7a7db752e96be7234fb0
2 files changed +9 -1
builtin-grep.c
+4 -1
@@ -783,8 +783,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
783 paths[1] = NULL;
784 }
785
786 - if (!list.nr)
786 + if (!list.nr) {
787 + if (!cached)
788 + setup_work_tree();
789 return !grep_cache(&opt, paths, cached);
790 + }
791
792 if (cached)
793 die("both --cached and trees are given.");
t/t1501-worktree.sh
+5
@@ -169,4 +169,9 @@ test_expect_success 'git diff' '
169 test_cmp diff-FILES.expected result
170 '
171
172 +test_expect_success 'git grep' '
173 + (cd repo.git/work/sub &&
174 + GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)
175 +'
176 +
177 test_done