git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] grep: fix worktree setup
@ 2008-08-28 13:04 Nguyễn Thái Ngọc Duy
  0 siblings, 0 replies; only message in thread
From: Nguyễn Thái Ngọc Duy @ 2008-08-28 13:04 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

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>
---
 builtin-grep.c      |    5 ++++-
 t/t1501-worktree.sh |    5 +++++
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 631129d..3ded1ba 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 e9e352c..e60116c 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -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
-- 
1.6.0.96.g2fad1.dirty

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2008-08-28 13:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-28 13:04 [PATCH] grep: fix worktree setup Nguyễn Thái Ngọc Duy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).