Re: `git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE

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

 



On Tue, Mar 29, 2016 at 08:08:29AM -0700, Junio C Hamano wrote:

> So it is a misconfiguration if you only set GIT_WORK_TREE without
> setting GIT_DIR.

Hmm. I have frequently done this when my cwd is a git repository (e.g.,
a bare one), and it works as you'd expect (find the git-dir in the
current path, then the working tree via $GIT_WORK_TREE).

I always assumed that was the intended behavior, as it is the only one
that makes sense. I suspect I am not alone in having relied on this.

> Also, if you set both and run Git from outside $GIT_WORK_TREE, even
> though Git may try to do its best to give you a reasonable behaviour
> [*1*], it is working by accident not by design (see the statement
> you are making by setting GIT_WORK_TREE in the third bullet above).
> 
> IOW, running from outside GIT_WORK_TREE is a misconfiguration.
> 
> [Footnote]
> 
> *1* Think what should happen when you are outside GIT_WORK_TREE and
>     say this:
> 
> 	$ git grep foo
> 
>     As you are not even inside the working tree, the command would
>     not know in which subdirectory you want to find the string foo;
>     the "reasonable behaviour" is to work on the whole working tree
>     in this case.

Likewise, I always assumed this "reasonable behavior" was intended. When
we setup_git_directory(), we end up in the root of the working tree as
usual. The "prefix" must be empty, as we were not in the work tree at
all, and we do a whole-tree operation.

Those behaviors may not have been fully designed, but as they do the
only reasonable thing (besides dying with an error), and people may have
baked that assumption into their scripts, I think we should avoid
changing them unless there is a compelling reason.

-Peff
--
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]