* [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
@ 2010-07-28 16:47 Tor Arne Vestbø
2010-07-28 23:00 ` Junio C Hamano
2010-08-02 14:37 ` Michael J Gruber
0 siblings, 2 replies; 6+ messages in thread
From: Tor Arne Vestbø @ 2010-07-28 16:47 UTC (permalink / raw)
To: git; +Cc: trast, Tor Arne Vestbø
The documentation describes require_work_tree as guarding against
bare repositories, and that's also the way it's used from porcelain
such as git-rebase. When implemented using --is-inside-work-tree
the samantics change, causing git-rebase to fail if run from outside
GIT_WORK_TREE, even if GIT_WORK_TREE is valid.
Signed-off-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
---
git-sh-setup.sh | 2 +-
t/t1501-worktree.sh | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletions(-)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 6131670..f8e4428 100644
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -141,7 +141,7 @@ cd_to_toplevel () {
}
require_work_tree () {
- test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
+ test -n "$(git rev-parse --show-toplevel 2>/dev/null)" ||
die "fatal: $0 cannot be used without a working tree."
}
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index bd8b607..45b09e7 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -114,6 +114,15 @@ test_expect_success 'repo finds its work tree from work tree, too' '
test sub/dir/tracked = "$(git ls-files)")
'
+test_expect_success 'require_work_tree finds work tree' '
+ (cd repo.git/work &&
+ . "$(git --exec-path)"/git-sh-setup &&
+ cd .. &&
+ require_work_tree &&
+ cd .. &&
+ require_work_tree)
+'
+
test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
(cd repo.git/work/sub/dir &&
GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
--
1.7.2.19.g48995
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
2010-07-28 16:47 [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree Tor Arne Vestbø
@ 2010-07-28 23:00 ` Junio C Hamano
2010-07-30 11:04 ` Tor Arne Vestbø
2010-08-02 14:37 ` Michael J Gruber
1 sibling, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2010-07-28 23:00 UTC (permalink / raw)
To: Tor Arne Vestbø; +Cc: git, trast
Tor Arne Vestbø <tor.arne.vestbo@nokia.com> writes:
> The documentation describes require_work_tree as guarding against
> bare repositories, and that's also the way it's used from porcelain
> such as git-rebase. When implemented using --is-inside-work-tree
> the samantics change, causing git-rebase to fail if run from outside
> GIT_WORK_TREE, even if GIT_WORK_TREE is valid.
>
> Signed-off-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
> ---
The "requirement" is that we _have_ work tree somewhere that we can
cd-to-toplevel to if we wanted to, not that we _are_ already in the work
tree. I can buy that rationale.
However, I notice that "git bisect", "git mergetool" and "git submodule"
do not seem to do cd_to_topleve immediately after require_work_tree. The
last one has cd_to_toplevel in later parts of the codepath, presumably so
that it can collect paths relative to the subdirectory in the work tree.
I wonder if all of them actually need to be run from inside a work tree?
Don't they need a separate "git rev-parse --is-inside-work-tree || die"
check after require_work_tree (or perhaps cd_to_toplevel) if we apply this
patch?
"git rebase--interactive" also lacks cd_to_toplevel but that is done by
the calling "git rebase" and I think that one is Ok.
> git-sh-setup.sh | 2 +-
> t/t1501-worktree.sh | 9 +++++++++
> 2 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/git-sh-setup.sh b/git-sh-setup.sh
> index 6131670..f8e4428 100644
> --- a/git-sh-setup.sh
> +++ b/git-sh-setup.sh
> @@ -141,7 +141,7 @@ cd_to_toplevel () {
> }
>
> require_work_tree () {
> - test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
> + test -n "$(git rev-parse --show-toplevel 2>/dev/null)" ||
> die "fatal: $0 cannot be used without a working tree."
> }
>
> diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
> index bd8b607..45b09e7 100755
> --- a/t/t1501-worktree.sh
> +++ b/t/t1501-worktree.sh
> @@ -114,6 +114,15 @@ test_expect_success 'repo finds its work tree from work tree, too' '
> test sub/dir/tracked = "$(git ls-files)")
> '
>
> +test_expect_success 'require_work_tree finds work tree' '
> + (cd repo.git/work &&
> + . "$(git --exec-path)"/git-sh-setup &&
> + cd .. &&
> + require_work_tree &&
> + cd .. &&
> + require_work_tree)
> +'
> +
> test_expect_success '_gently() groks relative GIT_DIR & GIT_WORK_TREE' '
> (cd repo.git/work/sub/dir &&
> GIT_DIR=../../.. GIT_WORK_TREE=../.. GIT_PAGER= \
> --
> 1.7.2.19.g48995
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
2010-07-28 23:00 ` Junio C Hamano
@ 2010-07-30 11:04 ` Tor Arne Vestbø
0 siblings, 0 replies; 6+ messages in thread
From: Tor Arne Vestbø @ 2010-07-30 11:04 UTC (permalink / raw)
To: ext Junio C Hamano; +Cc: git, trast
Hey, and thanks for your feedback Junio!
On 29.07.10 01.00, ext Junio C Hamano wrote:
> Tor Arne Vestbø <tor.arne.vestbo@nokia.com> writes:
>
> > The documentation describes require_work_tree as guarding against
> > bare repositories, and that's also the way it's used from porcelain
> > such as git-rebase. When implemented using --is-inside-work-tree
> > the samantics change, causing git-rebase to fail if run from outside
> > GIT_WORK_TREE, even if GIT_WORK_TREE is valid.
> >
> > Signed-off-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
> > ---
>
> The "requirement" is that we _have_ work tree somewhere that we can
> cd-to-toplevel to if we wanted to, not that we _are_ already in the work
> tree. I can buy that rationale.
Right. You put it much nicer than me :)
> However, I notice that "git bisect", "git mergetool" and "git submodule"
> do not seem to do cd_to_topleve immediately after require_work_tree. The
> last one has cd_to_toplevel in later parts of the codepath, presumably so
> that it can collect paths relative to the subdirectory in the work tree.
> I wonder if all of them actually need to be run from inside a work tree?
> Don't they need a separate "git rev-parse --is-inside-work-tree || die"
> check after require_work_tree (or perhaps cd_to_toplevel) if we apply this
> patch?
I think if we have a work tree somewhere, we can at least do "git
rev-parse --is-inside-work-tree || cd_to_toplevel" instead of dying,
unless there's some danger to that (the user running a command from
outside GIT_WORK_TREE but expecting GIT_WORK_TREE to not be touched).
For "git bisect" and "git submodule" running them in a sub-directory of
the work tree complains about needing to be run from the top-level, so I
assume we can do an unconditional cd_to_toplevel after the
require_work_tree?
For "git mergetool" we should probably do it conditionally only if the
user is not inside a work tree already, so that the behavior of running
the tool in a sub-directory is not changed.
Tor Arne
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
2010-07-28 16:47 [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree Tor Arne Vestbø
2010-07-28 23:00 ` Junio C Hamano
@ 2010-08-02 14:37 ` Michael J Gruber
2010-08-02 17:46 ` Junio C Hamano
1 sibling, 1 reply; 6+ messages in thread
From: Michael J Gruber @ 2010-08-02 14:37 UTC (permalink / raw)
To: Tor Arne Vestbø; +Cc: git, trast, Junio C Hamano
Tor Arne Vestbø venit, vidit, dixit 28.07.2010 18:47:
> The documentation describes require_work_tree as guarding against
> bare repositories, and that's also the way it's used from porcelain
> such as git-rebase. When implemented using --is-inside-work-tree
> the samantics change, causing git-rebase to fail if run from outside
> GIT_WORK_TREE, even if GIT_WORK_TREE is valid.
>
> Signed-off-by: Tor Arne Vestbø <tor.arne.vestbo@nokia.com>
> ---
> git-sh-setup.sh | 2 +-
> t/t1501-worktree.sh | 9 +++++++++
> 2 files changed, 10 insertions(+), 1 deletions(-)
>
> diff --git a/git-sh-setup.sh b/git-sh-setup.sh
> index 6131670..f8e4428 100644
> --- a/git-sh-setup.sh
> +++ b/git-sh-setup.sh
> @@ -141,7 +141,7 @@ cd_to_toplevel () {
> }
>
> require_work_tree () {
> - test "$(git rev-parse --is-inside-work-tree 2>/dev/null)" = true ||
> + test -n "$(git rev-parse --show-toplevel 2>/dev/null)" ||
> die "fatal: $0 cannot be used without a working tree."
> }
>
An alternative which does not change the established behavior of
require_work_tree would be changing the order of require_work_tree and
cd_to_top_level in the callers where possible along the lines of
http://mid.gmane.org/96abf622ca2cf92998ce4ed393ccaa75d95dd9a8.1279112025.git.git@drmicha.warpmail.net
which got lost somehow. (The other callers, as mentioned by Junio, would
need to be changed differently, e.g. by moving cd_to... earlier.)
Another problem I noticed back then (I was away since) was that a
relative GIT_WORK_TREE is left in place after a cd_to_top_level and
messes things up completely - it does not seem to be relative to
GIT_DIR. So, there seems to be more to fix in this area.
Cheers,
Michael
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
2010-08-02 14:37 ` Michael J Gruber
@ 2010-08-02 17:46 ` Junio C Hamano
2010-08-03 7:57 ` Michael J Gruber
0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2010-08-02 17:46 UTC (permalink / raw)
To: Michael J Gruber; +Cc: Tor Arne Vestbø, git, trast
Michael J Gruber <git@drmicha.warpmail.net> writes:
> An alternative which does not change the established behavior of
> require_work_tree would be changing the order of require_work_tree and
> cd_to_top_level in the callers where possible along the lines of
>
> http://mid.gmane.org/96abf622ca2cf92998ce4ed393ccaa75d95dd9a8.1279112025.git.git@drmicha.warpmail.net
>
> which got lost somehow. (The other callers, as mentioned by Junio, would
> need to be changed differently, e.g. by moving cd_to... earlier.)
Doesn't it sound stupid to "cd-to-toplevel" and then "require-work-tree"?
If you can go to the top-level, and once you successfully got there, you
already _know_ that you have a work tree (and also you already know at
that point you are in the work tree). The reason why "require-work-tree"
has been placed before "cd-to-toplevel" is exactly for that purpose, I
think. It is possible that some callers wanted to "require-work-tree" to
mean "I want you to not just _have_ a work tree, but actually be _in_ it",
but I somehow doubt it. It is more like "I am going to ask you to go to
the top, but let's make sure that you do have a top before doing so", I
think.
I on the other hand do not think it is wrong to lose the existing calls to
require-work-tree if you know that you are going to call cd-to-toplevel
before doing any git operation that needs to have a work-tree, though.
> Another problem I noticed back then (I was away since) was that a
> relative GIT_WORK_TREE is left in place after a cd_to_top_level and
> messes things up completely - it does not seem to be relative to
> GIT_DIR. So, there seems to be more to fix in this area.
I agree; I don't think GIT_WORK_TREE was designed to be anything but an
absolute path to begin with. If a command chdir's around and exports the
environment to its hooks and subcommands, it should be prepared to adjust
it before doing so.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree
2010-08-02 17:46 ` Junio C Hamano
@ 2010-08-03 7:57 ` Michael J Gruber
0 siblings, 0 replies; 6+ messages in thread
From: Michael J Gruber @ 2010-08-03 7:57 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Tor Arne Vestbø, git, trast
Junio C Hamano venit, vidit, dixit 02.08.2010 19:46:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
>
>> An alternative which does not change the established behavior of
>> require_work_tree would be changing the order of require_work_tree and
>> cd_to_top_level in the callers where possible along the lines of
>>
>> http://mid.gmane.org/96abf622ca2cf92998ce4ed393ccaa75d95dd9a8.1279112025.git.git@drmicha.warpmail.net
>>
>> which got lost somehow. (The other callers, as mentioned by Junio, would
>> need to be changed differently, e.g. by moving cd_to... earlier.)
>
> Doesn't it sound stupid to "cd-to-toplevel" and then "require-work-tree"?
It sounds outright silly, agreed.
Though, unless you know the implementation, "cd_to_toplevel" may succeed
cd'ing to what "rev-parse --show-toplevel" returns without
require_work_tree being happy.
But don't we try to preserve existing behavior unless it's a bug? We
certainly have a mismatch of behavior and documentation here. The
question is whether we want to break anyone who relied on
"require_work_tree" dieing when cwd is not within the work-tree.
>
> If you can go to the top-level, and once you successfully got there, you
> already _know_ that you have a work tree (and also you already know at
> that point you are in the work tree). The reason why "require-work-tree"
> has been placed before "cd-to-toplevel" is exactly for that purpose, I
> think. It is possible that some callers wanted to "require-work-tree" to
> mean "I want you to not just _have_ a work tree, but actually be _in_ it",
> but I somehow doubt it. It is more like "I am going to ask you to go to
> the top, but let's make sure that you do have a top before doing so", I
> think.
Well, if people relied on current behavior...
I didn't, I don't mind changing this, in fact I'm usually in "changing
mood" and running into the "preserve behavior" wall ;)
In any case, I think "require_work_tree" should really test whether we
can cd into the worktree, i.e. whether a cd_to_toplevel would succeed,
and not just whether "rev-parse --show-toplevel" returns a non-empty string.
>
> I on the other hand do not think it is wrong to lose the existing calls to
> require-work-tree if you know that you are going to call cd-to-toplevel
> before doing any git operation that needs to have a work-tree, though.
>
>> Another problem I noticed back then (I was away since) was that a
>> relative GIT_WORK_TREE is left in place after a cd_to_top_level and
>> messes things up completely - it does not seem to be relative to
>> GIT_DIR. So, there seems to be more to fix in this area.
>
> I agree; I don't think GIT_WORK_TREE was designed to be anything but an
> absolute path to begin with. If a command chdir's around and exports the
> environment to its hooks and subcommands, it should be prepared to adjust
> it before doing so.
We do have some magic to re-export a relative GIT_DIR as absolute, and
the doc says GIT_WORK_TREE is relative to GIT_DIR. We even have a test
which succeeds by pure chance, as playing around with different layouts
shows. I'll try to come up at least with tests for this when I get to it.
Cheers,
Michael
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-03 7:57 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-28 16:47 [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree Tor Arne Vestbø
2010-07-28 23:00 ` Junio C Hamano
2010-07-30 11:04 ` Tor Arne Vestbø
2010-08-02 14:37 ` Michael J Gruber
2010-08-02 17:46 ` Junio C Hamano
2010-08-03 7:57 ` Michael J Gruber
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).