Skip to content

Commit

Permalink
grep: fix worktree setup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Aug 29, 2008
1 parent 4f38f6b commit 6577f54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
5 changes: 5 additions & 0 deletions t/t1501-worktree.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6577f54

Please sign in to comment.