All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>
Cc: "Jonathan Nieder" <jrnieder@gmail.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] t7810: test git grep --no-index from a bare repository
Date: Fri, 23 Jul 2010 07:22:52 +0700	[thread overview]
Message-ID: <1279844572-17780-1-git-send-email-pclouds@gmail.com> (raw)

From: Jonathan Nieder <jrnieder@gmail.com>

If git grep --no-index is to be a general-purpose replacement for
standard grep, then it should work even for examining the content of a
.git directory.  The current implementation has some problems:

 * .git/info/exclude is honored though it shouldn’t be
 * when run from within a .git directory, grep --no-index searches
   the entire .git directory instead of just directories below
   the current working directory.

The last few tests (which demonstrate that grep --no-index looks for
.git/info/exclude even when no repository is involved) are by Duy.
Any bugs in the other tests are my fault.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 The original version. Good thing anyway, with or without tp/setup series.

 t/t7810-grep.sh |  116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)

diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 8a63227..7329433 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -494,6 +494,98 @@ test_expect_success 'inside git repository but with --no-index' '
 	)
 '
 
+test_expect_success 'set up bare repository' '
+
+	rm -fr bare &&
+	mkdir -p bare/basis/sub &&
+	echo hello >bare/basis/file1 &&
+	echo world >bare/basis/sub/file2 &&
+	echo ".*o*" >bare/basis/.gitignore &&
+	(
+		cd bare/basis &&
+		git init &&
+		git ls-files --other | git update-index --add --stdin &&
+		tree=$(git write-tree) &&
+		commit=$(printf "basis\n" | git commit-tree "$tree") &&
+		git update-ref -m init refs/heads/master "$commit" &&
+		git update-index --refresh &&
+		git diff-index --exit-code HEAD
+	) &&
+	git clone --no-checkout --bare bare/basis bare/d.git &&
+	mkdir -p bare/d.git/sub &&
+	echo olleh >bare/d.git/fich1 &&
+	echo dlrow >bare/d.git/sub/file2 &&
+	echo "file2" >bare/d.git/.gitignore &&
+	echo "o*" >>bare/d.git/.gitignore
+	{
+		echo "HEAD:.gitignore:.*o*" &&
+		echo HEAD:file1:hello &&
+		echo HEAD:sub/file2:world
+	} >bare/expect.full &&
+	: >bare/expect.empty &&
+	echo file2:dlrow >bare/expect.sub
+'
+
+test_expect_success 'in bare repo, grep without --no-index or --cached fails' '
+	(
+		cd bare/d.git &&
+		test_must_fail git grep o >../actual.plain 2>../actual.msg &&
+		grep "work tree" ../actual.msg &&
+		test_cmp ../expect.empty ../actual.plain &&
+		cd sub &&
+		test_must_fail git grep o >../../actual.sub 2>../../actual.msg &&
+		test_cmp ../../expect.empty ../../actual.sub &&
+		grep "work tree" ../../actual.msg
+	)
+'
+
+test_expect_success 'in bare repo, --cached and HEAD ignore working dir' '
+
+	(
+		cd bare/d.git &&
+		test_must_fail git grep --cached o >../actual.cached 2>../actual.msg &&
+		test_cmp ../expect.empty ../actual.cached &&
+		! grep fatal ../actual.msg &&
+		git grep -e o HEAD >../actual.full &&
+		test_cmp ../expect.full ../actual.full &&
+		cd sub &&
+		test_must_fail git grep o >../../actual.sub 2>../../actual.msg &&
+		test_cmp ../../expect.empty ../../actual.sub &&
+		git grep -e o HEAD >../../actual.full-sub &&
+		test_cmp ../../expect.full ../../actual.full-sub
+	)
+'
+
+test_expect_success '--no-index from a bare repository' '
+	rm -f bare/d.git/info/exclude &&
+	(
+		cd bare/d.git &&
+		git grep --no-index o >../actual.noindex &&
+		grep "^fich1:olleh\$" ../actual.noindex &&
+		grep "^.gitignore:o[*]\$" ../actual.noindex &&
+		! grep file2 ../actual.noindex
+	)
+'
+
+test_expect_failure '--no-index from a subdirectory of a bare repository' '
+	(
+		cd bare/d.git/sub &&
+		git grep --no-index o >../../actual.sub &&
+		test_cmp ../../expect.sub ../../actual.sub
+	)
+'
+
+test_expect_failure '--no-index neglects info/exclude in bare repo' '
+	echo "fich1" >bare/d.git/info/exclude &&
+	(
+		cd bare/d.git &&
+		git grep --no-index o >../actual.noindex &&
+		grep "^fich1:olleh\$" ../actual.noindex &&
+		grep "^.gitignore:o[*]\$" ../actual.noindex &&
+		! grep file2 ../actual.noindex
+	)
+'
+
 test_expect_success 'setup double-dash tests' '
 cat >double-dash <<EOF &&
 --
@@ -527,4 +619,28 @@ test_expect_success 'grep -e -- -- path' '
 	test_cmp expected actual
 '
 
+test_expect_success 'Setup fake .git' '
+	cd t &&
+	GIT_CEILING_DIRECTORIES="`pwd`" &&
+	export GIT_CEILING_DIRECTORIES &&
+	cd a &&
+	mkdir -p .git/info &&
+	cd ../..
+
+'
+
+test_expect_failure 'Ignore fake .git/info/exclude' '
+	(
+		cd t/a &&
+		echo v > .git/info/exclude &&
+		git grep --no-index vvv . &&
+		rm .git/info/exclude
+	)
+'
+
+test_expect_success 'Unsetup fake .git' '
+	rm -rf t/a &&
+	unset GIT_CEILING_DIRECTORIES
+'
+
 test_done
-- 
1.7.1.rc1.69.g24c2f7

                 reply	other threads:[~2010-07-22 22:41 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1279844572-17780-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.