completion: use "git -C $there" instead of (cd $there && git ...)
commitfca416a41e90be0102b48949522ff0d2dc258c53
authorJunio C Hamano <gitster@pobox.com>
Thu, 9 Oct 2014 20:45:21 +0000 (9 13:45 -0700)
committerJunio C Hamano <gitster@pobox.com>
Thu, 9 Oct 2014 22:06:08 +0000 (9 15:06 -0700)
tree67e15ab4b6e6b837b1d55f43719ae5a19ef04590
parenteeff891ac756fd97a05476446f15269b714ce4cc
completion: use "git -C $there" instead of (cd $there && git ...)

We have had "git -C $there" to first go to a different directory
and run a Git command without changing the arguments for quite some
time.  Use it instead of (cd $there && git ...) in the completion
script.

This allows us to lose the work-around for misfeatures of modern
interactive-minded shells that make "cd" unusable in scripts (e.g.
end users' $CDPATH taking us to unexpected places in any POSIX
shell, and chpwd functions spewing unwanted output in zsh).

Based on Ã˜ystein Walle's idea, which was raised during the
discussion on the solution by Brandon Turner for a problem zsh users
had with RVM which mucks with chpwd_functions in users' environments
(https://github.com/wayneeseguin/rvm/issues/3076).

As $root variable, which is used to direct where to chdir to, is set
to "." based on if $2 to __git_index_files is set (not if it is empty),
the only caller of the function is fixed not to pass the optional $2
when it does not want us to switch to a different directory.  Otherwise
we would end up doing "git -C '' command...", which would not work.

Maybe we would want "git -C '' command..." to mean "do not chdir
anywhere", but that is a spearate topic.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
contrib/completion/git-completion.bash