From: Nguyễn Thái Ngọc Duy Date: Thu, 28 Aug 2008 13:04:30 +0000 (+0700) Subject: grep: fix worktree setup X-Git-Tag: v1.6.0.2~22^2~3 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6577f542b3ab64594c7d7a7db752e96be7234fb0;p=git.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin-grep.c b/builtin-grep.c index 631129ddf..3ded1ba9d 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -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."); diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 8244b3a86..c039ee3fd 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -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