grep: fix worktree setup
PATCH 1/1 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 <[email protected]>
--- builtin-grep.c | 5 ++++- t/t1501-worktree.sh | 5 +++++ 2 files changed, 9 insertions(+), 1 deletions(-)
builtin-grep.c +4 -1
@@ -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." );
t/t1501-worktree.sh +5 -0
@@ -169,4 +169,9 @@ test_expect_success 'git diff' ' 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
Signature · 1 line
1.6.0.96.g2fad1.dirty