git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Cc: git@vger.kernel.org, snoksrud@gmail.com
Subject: Re: [PATCH] setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR
Date: Fri, 26 Jun 2015 10:30:28 -0700	[thread overview]
Message-ID: <xmqqlhf6v0ln.fsf@gitster.dls.corp.google.com> (raw)
In-Reply-To: <1435315055-27011-1-git-send-email-pclouds@gmail.com> ("Nguyễn	Thái Ngọc Duy"'s message of "Fri, 26 Jun 2015 17:37:35 +0700")

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> This is where the "fun" is. The legacy behavior is, if $GIT_WORK_TREE is
> not set but $GIT_DIR is, cwd is chosen as worktree's top. If you happen
> to stand at worktree's top when you do this, all is well.

It is not legacy, though.  It is how things were designed to be
used, and how things are supposed to work in the future.

Until we do the deprecation dance to force people to update existing
scripts to explicitly export GIT_WORK_TREE=$(pwd) or something like
that, that is.

And I wouldn't be opposed to such a transition plan; something along
the lines of what Peff outlined in that old thread.

http://thread.gmane.org/gmane.comp.version-control.git/219096/focus=219197

> Bottom line is, when $GIT_DIR is set, $GIT_WORK_TREE should be set too
> unless there's no work tree. But setting $GIT_WORK_TREE inside
> set_git_dir() may backfire. We don't know at that point if work tree is
> already configured by the caller. So set it when work tree is
> detected. It does not harm if $GIT_WORK_TREE is set while $GIT_DIR is
> not.

I am inclined to queue this on 'next' per "experimental" basis so
that other people with different workflows (especially those who
use existing scripts around Git plumbing heavily) can see if this
does not have any unintended fallouts.  I cannot convince myself
that it is generally a safe thing to do to muck with environment
partially, hoping nobody would care.

Thanks for looking into it.

>  environment.c      |  2 ++
>  t/t0002-gitfile.sh | 17 +++++++++++++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/environment.c b/environment.c
> index 61c685b..8f1b249 100644
> --- a/environment.c
> +++ b/environment.c
> @@ -231,6 +231,8 @@ void set_git_work_tree(const char *new_work_tree)
>  	}
>  	git_work_tree_initialized = 1;
>  	work_tree = xstrdup(real_path(new_work_tree));
> +	if (setenv(GIT_WORK_TREE_ENVIRONMENT, work_tree, 1))
> +		error("Could not set GIT_WORK_TREE to '%s'", work_tree);
>  }
>  
>  const char *get_git_work_tree(void)
> diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
> index 37e9396..9393322 100755
> --- a/t/t0002-gitfile.sh
> +++ b/t/t0002-gitfile.sh
> @@ -99,4 +99,21 @@ test_expect_success 'check rev-list' '
>  	test "$SHA" = "$(git rev-list HEAD)"
>  '
>  
> +test_expect_success 'setup_git_dir twice in subdir' '
> +	git init sgd &&
> +	(
> +		cd sgd &&
> +		git config alias.lsfi ls-files &&
> +		mv .git .realgit &&
> +		echo "gitdir: .realgit" >.git &&
> +		mkdir subdir &&
> +		cd subdir &&
> +		>foo &&
> +		git add foo &&
> +		git lsfi >actual &&
> +		echo foo >expected &&
> +		test_cmp expected actual
> +	)
> +'
> +
>  test_done

      parent reply	other threads:[~2015-06-26 17:30 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-25 14:15 Linked workdirs break typo-correction Bjørnar Snoksrud
2015-06-26 10:37 ` [PATCH] setup: set env $GIT_WORK_TREE when work tree is set, like $GIT_DIR Nguyễn Thái Ngọc Duy
2015-06-26 11:56   ` Jeff King
2015-06-27  5:57     ` Duy Nguyen
2015-06-26 17:15   ` Junio C Hamano
2015-06-26 19:02     ` Junio C Hamano
2015-06-26 17:30   ` Junio C Hamano [this message]

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=xmqqlhf6v0ln.fsf@gitster.dls.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=snoksrud@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 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).