Skip to content

Commit c2f599e

Browse files
author
Junio C Hamano
committed
git-clone: don't get fooled by $PWD
If you have /home/me/git symlink pointing at /pub/git/mine, trying to clone from /pub/git/his/ using relative path would not work as expected: $ cd /home/me $ cd git $ ls ../ his mine $ git clone -l -s -n ../his/stuff.git This is because "cd ../his/stuff.git" done inside git-clone to check if the repository is local is confused by $PWD, which is set to /home/me, and tries to go to /home/his/stuff.git which is different from /pub/git/his/stuff.git. We could probably say "set -P" (or "cd -P") instead, if we know the shell is POSIX, but the way the patch is coded is probably more portable. [jc: this is updated with Andy Whitcroft's improvements] Signed-off-by: Junio C Hamano <[email protected]>
1 parent c69f405 commit c2f599e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

git-clone.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,14 @@ usage() {
1818
}
1919

2020
get_repo_base() {
21-
(cd "$1" && (cd .git ; pwd)) 2> /dev/null
21+
(
22+
cd "`/bin/pwd`" &&
23+
cd "$1" &&
24+
{
25+
cd .git 2>/dev/null
26+
pwd
27+
}
28+
)
2229
}
2330

2431
if [ -n "$GIT_SSL_NO_VERIFY" ]; then

0 commit comments

Comments
 (0)