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

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

 



Jeff King <peff@xxxxxxxx> writes:

>   $ echo content >../file
>   $ GIT_WORK_TREE=$(cd ..; pwd) GIT_DIR=$(pwd) git add file
>   fatal: pathspec 'file' did not match any files
>
> I'd expect that to work, and it doesn't, because we pass ".git/" as the
> "prefix" to cmd_add(). Which I guess is true, but it feels kind of weird
> (I think most people who set both variables like that would generally
> point to some other directory entirely, and we would have a NULL
> prefix).

That reminds me of a related tangent.  If we really want to properly
support running from outside the working tree (or from inside .git
for that matter), I suspect we need two separate "prefix" for two
different uses.  The "we would have a NULL prefix" is what was
considered the true "prefix" traditionally, i.e. it is the directory
to which any pathspecs and relative paths that name paths in the
history are taken relative to.  E.g. if you run "git add HEAD" from
inside your GIT_DIR but you have GIT_WORK_TREE set up correctly, you
would want to add HEAD from the root of the working tree.

Another is the base directory for a relative filename that names a
file that does not have anything to do with the paths in the
history.  E.g. if you run "git grep --file patterns" from outside
the working tree but with GIT_DIR/GIT_WORK_TREE correctly set up,
you would still want to read the "patterns" file from the current
directory.

The former can be done by using prefix=NULL to say "we may or may
not have come from outside a working tree but we no longer care
after we chdir(2) to the root of the working tree.  Any path is
relative to the root of the working tree."  But then we may lose the
clue to read from the latter (the OPT_FILENAME option is handled by
prefix_filename() using the prefix).

The distinction between the two does not exist as long as you start
inside GIT_WORK_TREE and outside GIT_DIR.

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