Re: [PATCH] require_work_tree: Look for top-level instead of is-inside-work-tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Tor Arne Vestbø <tor.arne.vestbo@xxxxxxxxx> 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@xxxxxxxxx>
> ---

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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]