Re: [PATCH] grep: simple test for operation in a bare repository
- From
René Scharfe <rene.scharfe@lsrfire.ath.cx>
- Date
- Feb 5, 2010, 00:24 UTC
- Message-ID
- <4B6B653A.8060909@lsrfire.ath.cx>
- In-Reply-To
- <4B6A0BDE.2050908@lsrfire.ath.cx>
Am 04.02.2010 00:50, schrieb René Scharfe:
Show 16 quoted lines
> Am 03.02.2010 19:16, schrieb René Scharfe: >> Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> >> --- >> t/t7002-grep.sh | 17 +++++++++++++++++ >> 1 files changed, 17 insertions(+), 0 deletions(-) > > Err, no, that won't do. Sorry. > > The test script fails to demonstrate the issue I've run into. It runs > successfully, but running git grep manually fails: > > $ cd t/trash\ directory.t7002-grep/.git/bare_test_repo/ > $ git grep bla HEAD > fatal: This operation must be run in a work tree > > I have to dig a bit deeper and try to come back with a better test script.
OK, I have to admit defeat: I can't come up with a test script. But the issue is reproducible: git grep in a bare repository fails when run with a pager.
$ mkdir /tmp/a $ cd /tmp/a $ git init Initialized empty Git repository in /tmp/a/.git/ $ echo a >a $ git add a $ git commit -m. [master (root-commit) e11f955] . 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 a
$ git clone --bare . ../b Initialized empty Git repository in /tmp/b/ $ cd /tmp/b
$ git grep a HEAD fatal: This operation must be run in a work tree $ git grep a HEAD | cat HEAD:a:a $ git --no-pager grep a HEAD HEAD:a:a
Reverting 7e622650 (grep: prepare to run outside of a work tree), or rather just setting the flag RUN_SETUP for grep in git.c again, makes the first git grep call succeed, too.
As does the following patch, but I don't know why. The call chain is quite deep. It seems that without the patch the static variable git_dir in environment.c isn't updated when git finds out that it runs in a bare repo -- but only if a pager is used.
There are five more sites in git.c, path.c and setup.c where $GIT_DIR is set directly with setenv(). I wonder if they should better call set_git_dir() instead, too.
diff --git a/setup.c b/setup.c index 710e2f3..5fb9b25 100644 --- a/setup.c +++ b/setup.c @@ -406,7 +406,7 @@ const char *setup_git_directory_gently(int *nongit_ok) cwd[offset] = '\0'; setenv(GIT_DIR_ENVIRONMENT, cwd, 1); } else - setenv(GIT_DIR_ENVIRONMENT, ".", 1); + set_git_dir("."); check_repository_format_gently(nongit_ok); return NULL; }