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

Re: [PATCH RESEND] Git.pm: Set GIT_WORK_TREE if we set GIT_DIR

From
Petr Baudis <pasky@suse.cz>
Date
May 7, 2009, 19:40 UTC
Message-ID
<20090507194047.GA17989@machine.or.cz>
In-Reply-To
<1241703688-6892-1-git-send-email-frank@lichtenheld.de>
On Thu, May 07, 2009 at 03:41:27PM +0200, Frank Lichtenheld wrote:
Show 28 quoted lines
> From: Frank Lichtenheld <flichtenheld@astaro.com>
> 
> Otherwise git will use the current directory as work tree which will
> lead to unexpected results if we operate in sub directory of the
> work tree.
> 
> Signed-off-by: Frank Lichtenheld <flichtenheld@astaro.com>
> ---
>  perl/Git.pm         |    2 ++
>  t/t9700-perl-git.sh |    4 ++++
>  t/t9700/test.pl     |   13 +++++++++++++
>  3 files changed, 19 insertions(+), 0 deletions(-)
> 
> No comments and doesn't seem to have been applied, so resent unchanged.
> 
> diff --git a/perl/Git.pm b/perl/Git.pm
> index 291ff5b..4313db7 100644
> --- a/perl/Git.pm
> +++ b/perl/Git.pm
> @@ -1280,6 +1280,8 @@ sub _cmd_exec {
>  	my ($self, @args) = @_;
>  	if ($self) {
>  		$self->repo_path() and $ENV{'GIT_DIR'} = $self->repo_path();
> +		$self->repo_path() and $self->wc_path()
> +			and $ENV{'GIT_WORK_TREE'} = $self->wc_path();
>  		$self->wc_path() and chdir($self->wc_path());
>  		$self->wc_subdir() and chdir($self->wc_subdir());
>  	}
This looks obviously correct?

You could even skip the first chdir and use $self->wc_path() . $self->wc_subdir() in the second one to save a syscall, I guess. ;-)

I've really forgot most of the code already so it's not worth much, but
Acked-by: Petr Baudis <pasky@suse.cz>
Previous: Frank Lichtenheld
Message 7 of 7 in “Git.pm: Set GIT_WORK_TREE if we set GIT_DIR”
  1. Git.pm: Set GIT_WORK_TREE if we set GIT_DIRFrank Lichtenheld, May 7, 2009
  2. Git.pm: Always set Repository to absolute path if autodetectingFrank Lichtenheld, May 7, 2009
  3. Johannes SixtMay 25, 2009
  4. Frank LichtenheldMay 27, 2009
  5. Johannes SixtMay 27, 2009
  6. Frank LichtenheldMay 27, 2009
  7. Petr BaudisMay 7, 2009

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.