]> git.ipfire.org Git - thirdparty/git.git/commitdiff
grep: fix worktree setup
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Thu, 28 Aug 2008 13:04:30 +0000 (20:04 +0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 29 Aug 2008 05:46:16 +0000 (22:46 -0700)
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>
builtin-grep.c
t/t1501-worktree.sh

index 631129ddfd0ffe06f919882d22cfc494d9553f50..3ded1ba9da9166c09fb1b65d315499e24036466d 100644 (file)
@@ -783,8 +783,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
                paths[1] = NULL;
        }
 
-       if (!list.nr)
+       if (!list.nr) {
+               if (!cached)
+                       setup_work_tree();
                return !grep_cache(&opt, paths, cached);
+       }
 
        if (cached)
                die("both --cached and trees are given.");
index 8244b3a86f80110925613bac29e9f20ccc7303be..c039ee3fd86fc30a551a301066528a8574c34c1e 100755 (executable)
@@ -169,4 +169,9 @@ test_expect_success 'git diff' '
        test_cmp diff-FILES.expected result
 '
 
+test_expect_success 'git grep' '
+       (cd repo.git/work/sub &&
+       GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)
+'
+
 test_done