Re: [PATCH 2/2] Use $(git rev-parse --show-toplevel) in cd_to_toplevel()
- From
Jonathan Nieder <jrnieder@gmail.com>
- Date
- Jan 10, 2010, 10:11 UTC
- Message-ID
- <20100110101154.GA18138@progeny.tock>
- In-Reply-To
- <alpine.LNX.2.00.1001102016380.2560@vqena.qenxr.bet.am>
Steven Drake wrote:
> 'cd -P' is not supported by all shell implementations.
Makes sense.
git already does not handle those cases where 'cd "$(pwd)"' fails while 'cd .' does not, so your patch shouldn’t break anything. [1]
Show 21 quoted lines
> diff --git a/git-sh-setup.sh b/git-sh-setup.sh
> index dfcb807..3cbec05 100755
> --- a/git-sh-setup.sh
> +++ b/git-sh-setup.sh
> @@ -120,16 +120,10 @@ is_bare_repository () {
> }
>
> cd_to_toplevel () {
> - cdup=$(git rev-parse --show-cdup)
> - if test ! -z "$cdup"
> + if test ! -z "$(git rev-parse --show-cdup)"
> then
> - # The "-P" option says to follow "physical" directory
> - # structure instead of following symbolic links. When cdup is
> - # "../", this means following the ".." entry in the current
> - # directory instead textually removing a symlink path element
> - # from the PWD shell variable. The "-P" behavior is more
> - # consistent with the C-style chdir used by most of Git.
> - cd -P "$cdup" || {
> + cdup=$(git rev-parse --show-toplevel)
> + cd "$cdup" || {Why not 'cdup=$(git rev-parse --show-toplevel) && cd "$cdup"' unconditionally? That would avoid having to look for the .git dir twice and would mirror setup_work_tree() a bit more closely.
Avoiding -P not only improves portability but makes the function easier to understand. I like it.
Thanks, Jonathan
[1] http://thread.gmane.org/gmane.comp.version-control.git/135563/focus=135571