{"thread":{"id":"31009","subject":"[PATCH v2] submodules: don't stumble over symbolic links when cloning recursively","startedAt":"2012-07-12T17:45:32Z","lastAt":"2012-07-12T17:45:32Z","messageCount":1,"participants":["Jens Lehmann"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"194975","messageId":"4FFF0D3C.2060001@web.de","threadId":"31009","inReplyTo":null,"subject":"[PATCH v2] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-12T17:45:32Z","receivedAt":"2012-07-12T17:45:32Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Since 69c3051 (submodules: refactor computation of relative gitdir path)\ncloning a submodule recursively fails for nested submodules when a\nsymbolic link is part of the path to the work tree of the superproject.\n\nThis happens when module_clone() tries to find the relative paths between\nthe work tree and the git dir. When a symbolic link in current $PWD points\nto a directory that is at a different level, then determining the number\nof \"../\" needed to traverse to the superproject's work tree leads to a\nwrong result.\n\nAs there is no portable way to say \"pwd -P\", use cd_to_toplevel to remove\nthe link from $PWD, which fixes this problem.\n\nA test for this issue has been added to t7406.\n\nReported-by: Bob Halley <halley@play-bow.org>\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nThe changes in this version are:\n- the SYMLINKS prerequisite is used for the new test\n- a comment explaining why cd_to_toplevel is needed has been added\n- small updates to the commit message\n\nThanks to J6t for the input.\n\n git-submodule.sh            |  6 ++++--\n t/t7406-submodule-update.sh | 13 +++++++++++++\n 2 files changed, 17 insertions(+), 2 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5629d87..dba4d39 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -186,8 +186,10 @@ module_clone()\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n \tfi\n\n-\ta=$(cd \"$gitdir\" && pwd)/\n-\tb=$(cd \"$sm_path\" && pwd)/\n+\t# We already are at the root of the work tree but cd_to_toplevel will\n+\t# resolve any symlinks that might be present in $PWD\n+\ta=$(cd_to_toplevel && cd \"$gitdir\" && pwd)/\n+\tb=$(cd_to_toplevel && cd \"$sm_path\" && pwd)/\n \t# normalize Windows-style absolute paths to POSIX-style absolute paths\n \tcase $a in [a-zA-Z]:/*) a=/${a%%:*}${a#*:} ;; esac\n \tcase $b in [a-zA-Z]:/*) b=/${b%%:*}${b#*:} ;; esac\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex dcb195b..ce61d4c 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -636,4 +636,17 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n \t)\n '\n\n+test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n+\tmkdir -p linked/dir &&\n+\tln -s linked/dir linkto &&\n+\t(\n+\t\tcd linkto &&\n+\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n+\t\t(\n+\t\t\tcd super &&\n+\t\t\tgit submodule update --init --recursive\n+\t\t)\n+\t)\n+'\n+\n test_done\n-- \n1.7.11.1.166.gf56d108\n"}]}