Re: [PATCH] Teach git to change to a given directory using -C option

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

 



Jeff King wrote:
> On Fri, Apr 19, 2013 at 08:21:48PM +0800, Nazri Ramliy wrote:

>> Often I find myself needing to find out quickly the status of a repository that
>> is not in my currenct working directory, like this:
>>
>>          $ (cd ~/foo; git log -1)
>>
>> With this patch now i can simply do:
>>
>>          $ git -C ~/.zsh log -1 
>> 
>> That's just one example.
[...]
> You can _almost_ do this with "git --git-dir". But it expects the actual
> git directory, not a starting point for finding the git directory.
[...]
> It is redundant with "(cd foo && git ...)" in the shell, as you note,
> but sometimes it is more convenient to use "-C" (especially if you are
> exec-ing git from another program and want to avoid the shell entirely
> for quoting reasons).

When I want to run "git log" for a repository outside the cwd, I do
use --git-dir (or more precisely,

	$ GIT_DIR=$HOME/src/git/.git git log

), which works.

The "sometimes you just want to pass a command to 'exec'" use case
does not convince me.  I equally well might want to run "git" after
another command, or run "git" if and only if a repository exists
there, or do any number of other things.  If someone asked me how to
do that by passing a command to 'exec', I'd point them to

	sh -c 'cd foo && git ...'

as a way to answer all such questions at the same time.  So we're left
with "--git-dir does not automatically append .git when appropriate"
as the problem being solved, which is a real problem.  Maybe that is
worth fixing more directly?

It might also be convenient to be able to do something like

	git --git-dir=~/src/git log -- Documentation/

which this -C option makes easy.  *checks*  Actually it works without,
but for subtle reasons.  A more sensible way to spell that is

	git --git-dir=<wherever> -- :/Documentation/

which works fine.

All that said, I don't mind -C terribly as long as it can maintain
itself, which means including thorough documentation that covers the
purpose and how pathname parameters and envvars interact with the new
option and including tests under t/ to ensure it continues to work
correctly in the future.

Thanks for an interesting patch, and hope that helps,
Jonathan
--
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]