git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC/PATCHv2 4/5] add test for git grep --recursive

From
Chris Packham <judge.packham@gmail.com>
Date
Oct 15, 2010, 23:26 UTC
Message-ID
<1287185204-843-5-git-send-email-judge.packham@gmail.com>
In-Reply-To
<1287185204-843-1-git-send-email-judge.packham@gmail.com>
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
 t/t7820-grep-recursive.sh |  183 +++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 183 insertions(+), 0 deletions(-)
 create mode 100644 t/t7820-grep-recursive.sh
diff --git a/t/t7820-grep-recursive.sh b/t/t7820-grep-recursive.sh
new file mode 100644
index 0000000..3c386b4
--- /dev/null
+++ b/t/t7820-grep-recursive.sh
@@ -0,0 +1,183 @@
+#!/bin/sh
+#
+# Copyright (c) 2010 Chris Packham
+#
+
+test_description='git grep --recursive test
+
+This test checks the ability of git grep to search within submodules when told
+to do so with the --recursive option'
+
+. ./test-lib.sh
+
+restore_test_defaults()
+{
+	unset GIT_SUPER_REFNAME
+}
+
+test_expect_success 'setup' '
+	cat >t <<-\EOF &&
+	one two three
+	four five six
+	seven eight nine
+	EOF
+	git add t &&
+	git commit -m "initial commit"
+'
+submodurl=$TRASH_DIRECTORY
+
+test_expect_success 'setup submodules' '
+	for mod in submodule1 submodule2 submodule3 submodule4 submodule5; do
+		git submodule add "$submodurl" $mod &&
+		git submodule init $mod
+	done &&
+	git commit -m "setup submodules for test"
+'
+
+test_expect_success 'update data in each submodule' '
+	for n in 1 2 3 4 5; do
+		(cd submodule$n &&
+			sed -i "s/^four.*/& #$n/" t &&
+			git commit -a -m"update") &&
+		git add submodule$n
+	done &&
+	git commit -m "update data in each submodule"
+'
+
+test_expect_success 'non-recursive grep in base' '
+	cat >expected <<-\EOF &&
+	t:four five six
+	EOF
+	git grep "five" >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'submodule-ref option' '
+	cat >expected <<-\EOF &&
+	bar:t:four five six
+	EOF
+	GIT_SUPER_REFNAME=bar &&
+	export GIT_SUPER_REFNAME &&
+	git grep "five" master >actual &&
+	test_cmp expected actual &&
+	restore_test_defaults
+'
+
+test_expect_success 'non-recursive grep in submodule' '
+	(
+		cd submodule1 &&
+		cat >expected <<-\EOF &&
+		t:four five six #1
+		EOF
+		git grep "five" >actual &&
+		test_cmp expected actual
+	)
+'
+
+test_expect_success 'recursive grep' '
+	cat >expected <<-\EOF &&
+	submodule1/t:four five six #1
+	submodule2/t:four five six #2
+	submodule3/t:four five six #3
+	submodule4/t:four five six #4
+	submodule5/t:four five six #5
+	t:four five six
+	EOF
+	git grep --recursive "five" >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with -n)' '
+	cat >expected <<-\EOF &&
+	submodule1/t:2:four five six #1
+	submodule2/t:2:four five six #2
+	submodule3/t:2:four five six #3
+	submodule4/t:2:four five six #4
+	submodule5/t:2:four five six #5
+	t:2:four five six
+	EOF
+	git grep --recursive -n "five" >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with -l)' '
+	cat >expected <<-\EOF &&
+	submodule1/t
+	submodule2/t
+	submodule3/t
+	submodule4/t
+	submodule5/t
+	t
+	EOF
+	git grep --recursive -l "five" >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with --or)' '
+	cat >expected <<-\EOF &&
+	submodule1/t:one two three
+	submodule1/t:four five six #1
+	submodule2/t:one two three
+	submodule2/t:four five six #2
+	submodule3/t:one two three
+	submodule3/t:four five six #3
+	submodule4/t:one two three
+	submodule4/t:four five six #4
+	submodule5/t:one two three
+	submodule5/t:four five six #5
+	t:one two three
+	t:four five six
+	EOF
+	git grep --recursive \( -e "five" --or -e "two" \) >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep (with --and --not)' '
+	cat >expected <<-\EOF &&
+	submodule2/t:four five six #2
+	submodule3/t:four five six #3
+	submodule4/t:four five six #4
+	submodule5/t:four five six #5
+	t:four five six
+	EOF
+	git grep --recursive \( -e "five" --and --not -e "#1" \) >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with refspec' '
+	cat >expected <<-\EOF &&
+	master:submodule1/t:four five six #1
+	master:submodule2/t:four five six #2
+	master:submodule3/t:four five six #3
+	master:submodule4/t:four five six #4
+	master:submodule5/t:four five six #5
+	master:t:four five six
+	EOF
+	git grep --recursive five master >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with pathspec' '
+	cat >expected <<-\EOF &&
+	submodule2/t:four five six #2
+	EOF
+	git grep --recursive five -- submodule2 >actual &&
+	test_cmp expected actual
+'
+
+test_expect_success 'recursive grep with pathspec and refspec' '
+	cat >expected <<-\EOF &&
+	master:submodule2/t:four five six #2
+	EOF
+	git grep --recursive five master -- submodule2 >actual &&
+	test_cmp expected actual
+'
+
+test_expect_failure 'recursive grep with --max-depth' '
+	cat >expected <<-\EOF &&
+	t:four five six
+	EOF
+	git grep --recursive --max-depth=1 five  >actual &&
+	test_cmp expected actual
+'
+test_done
-- 
1.7.3.1
Previous: Chris PackhamNext: Chris Packham
Message 9 of 15 in “[RGC/PATCHv2] grep: submodule support”
  1. Chris PackhamOct 15, 2010
  2. 1/5 worktree: provide better prefix to go back to original cwdChris Packham, Oct 15, 2010
  3. Jonathan NiederOct 16, 2010
  4. Chris PackhamOct 17, 2010
  5. Nguyen Thai Ngoc DuyOct 17, 2010
  6. Chris PackhamOct 18, 2010
  7. 2/5 grep: output the path from cwd to worktreeChris Packham, Oct 15, 2010
  8. 3/5 grep_cache: check pathspec firstChris Packham, Oct 15, 2010
  9. 4/5 add test for git grep --recursiveChris Packham, Oct 15, 2010
  10. 5/5 grep: add support for grepping in submodulesChris Packham, Oct 15, 2010
  11. Nguyen Thai Ngoc DuyOct 17, 2010
  12. Chris PackhamOct 18, 2010
  13. Nguyen Thai Ngoc DuyOct 18, 2010
  14. Jens LehmannOct 16, 2010
  15. Chris PackhamOct 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.