git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Marcel M. Cary" <marcel@oak.homeunix.org>
To: git@vger.kernel.org
Cc: gitster@pobox.com, jnareb@gmail.com, ae@op5.se,
	j.sixt@viscovery.net, git-dev@marzelpan.de, win@wincent.com,
	benji@silverinsanity.com,
	"Marcel M. Cary" <marcel@oak.homeunix.org>
Subject: [RFC PATCH] git-sh-setup: Use "cd" option, not /bin/pwd, for symlinked work tree
Date: Fri,  6 Feb 2009 19:24:28 -0800	[thread overview]
Message-ID: <1233977068-24861-1-git-send-email-marcel@oak.homeunix.org> (raw)
In-Reply-To: <7viqq1hghw.fsf@gitster.siamese.dyndns.org>

In cd_to_toplevel, instead of 'cd $(unset PWD; /bin/pwd)/$path'
use 'cd -P $path'.  The "-P" option yields a desirable similarity to
C chdir.

While the "-P" option may be slightly less commonly supported than
/bin/pwd, it is more concise, better tested, and less error prone.
I've already added the 'unset PWD' to fix the /bin/pwd solution on
BSD; there may be more edge cases out there.

This still passes all the same test cases in t5521-pull-symlink.sh and
t2300-cd-to-toplevel.sh, even before updating them to use 'pwd -P'.
---

> ... I think it would probably be better to bite the bullet
> and start using "cd -P" soon after 1.6.1 goes final, ...

Here's a post-1.6.1 way to make Git shell scripts work like C programs
when in symlinked directories.

> ... and at the same time
> existing places that use "cd `pwd`" as a workaround if there are some.

I haven't found other places that use the "cd `/bin/pwd`" workaround.

I also wasn't able to think of a test case that fails under the previous
way and works under this new way either.

Any opinions on whether this is worthwhile?  It seems more standardized
if less supported, odd as that seems to me.

Marcel

 git-sh-setup.sh           |   29 ++++++++---------------------
 t/t2300-cd-to-toplevel.sh |    4 ++--
 2 files changed, 10 insertions(+), 23 deletions(-)

diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index 2142308..8382339 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -85,27 +85,14 @@ cd_to_toplevel () {
 	cdup=$(git rev-parse --show-cdup)
 	if test ! -z "$cdup"
 	then
-		case "$cdup" in
-		/*)
-			# Not quite the same as if we did "cd -P '$cdup'" when
-			# $cdup contains ".." after symlink path components.
-			# Don't fix that case at least until Git switches to
-			# "cd -P" across the board.
-			phys="$cdup"
-			;;
-		..|../*|*/..|*/../*)
-			# Interpret $cdup relative to the physical, not logical, cwd.
-			# Probably /bin/pwd is more portable than passing -P to cd or pwd.
-			phys="$(unset PWD; /bin/pwd)/$cdup"
-			;;
-		*)
-			# There's no "..", so no need to make things absolute.
-			phys="$cdup"
-			;;
-		esac
-
-		cd "$phys" || {
-			echo >&2 "Cannot chdir to $phys, the toplevel of the working tree"
+		# 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" || {
+			echo >&2 "Cannot chdir to $cdup, the toplevel of the working tree"
 			exit 1
 		}
 	fi
diff --git a/t/t2300-cd-to-toplevel.sh b/t/t2300-cd-to-toplevel.sh
index e42cbfe..293dc35 100755
--- a/t/t2300-cd-to-toplevel.sh
+++ b/t/t2300-cd-to-toplevel.sh
@@ -10,12 +10,12 @@ test_cd_to_toplevel () {
 			cd '"'$1'"' &&
 			. git-sh-setup &&
 			cd_to_toplevel &&
-			[ "$(unset PWD; /bin/pwd)" = "$TOPLEVEL" ]
+			[ "$(pwd -P)" = "$TOPLEVEL" ]
 		)
 	'
 }
 
-TOPLEVEL="$(unset PWD; /bin/pwd)/repo"
+TOPLEVEL="$(pwd -P)/repo"
 mkdir -p repo/sub/dir
 mv .git repo/
 SUBDIRECTORY_OK=1
-- 
1.6.1

  parent reply	other threads:[~2009-02-07  3:26 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-15 15:11 [RFC PATCH 0/2] fixing git pull from symlinked directory Marcel M. Cary
2008-11-15 15:11 ` [RFC PATCH 1/2] Add failing test for "git pull" in " Marcel M. Cary
2008-11-15 15:11   ` [RFC PATCH 2/2] Support shell scripts that run from symlinks into a git working dir Marcel M. Cary
2008-11-22 21:33 ` [PATCH] rev-parse: Fix shell scripts whose cwd is a symlink into a git work-dir Marcel M. Cary
2008-11-22 21:54   ` Jakub Narebski
2008-11-23  7:10     ` Andreas Ericsson
2008-11-25  5:54       ` Marcel M. Cary
2008-11-25  6:50         ` Andreas Ericsson
2008-11-25  5:17     ` Marcel M. Cary
2008-11-25  7:30   ` Johannes Sixt
2008-11-25 16:16     ` Marcel M. Cary
2008-11-25 16:30       ` Johannes Sixt
2008-11-25 18:17       ` Junio C Hamano
2008-12-03  5:27         ` [PATCH] git-sh-setup: Fix scripts whose PWD " Marcel M. Cary
2008-12-03  7:20           ` Junio C Hamano
2008-12-10 15:04             ` [PATCH v2] " Marcel M. Cary
2008-12-10 20:18               ` Junio C Hamano
2008-12-13 20:47                 ` [PATCH v3] " Marcel M. Cary
2008-12-14  3:54                   ` Junio C Hamano
2008-12-15 17:34                     ` Marcel M. Cary
2008-12-15 17:38                       ` [PATCH v3] <-- really v4 Marcel M. Cary
2009-02-07  3:24             ` Marcel M. Cary [this message]
2009-02-07 12:25               ` [RFC PATCH] git-sh-setup: Use "cd" option, not /bin/pwd, for symlinked work tree Johannes Schindelin
2009-02-08 18:11                 ` Marcel M. Cary
2009-02-08 20:56                   ` Johannes Schindelin
2009-02-11 14:44                     ` Marcel M. Cary
2009-02-11 18:16                       ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1233977068-24861-1-git-send-email-marcel@oak.homeunix.org \
    --to=marcel@oak.homeunix.org \
    --cc=ae@op5.se \
    --cc=benji@silverinsanity.com \
    --cc=git-dev@marzelpan.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=jnareb@gmail.com \
    --cc=win@wincent.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).