{"thread":{"id":"30995","subject":"[PATCH] submodules: don't stumble over symbolic links when cloning recursively","startedAt":"2012-07-11T18:11:58Z","lastAt":"2012-07-12T17:12:21Z","messageCount":6,"participants":["Jens Lehmann","Johannes Sixt"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"194924","messageId":"4FFDC1EE.8080106@web.de","threadId":"30995","inReplyTo":null,"subject":"[PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-11T18:11:58Z","receivedAt":"2012-07-11T18:11:58Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Since 69c305178 (submodules: refactor computation of relative gitdir path)\ncloning a submodule recursively fails for recursive 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\nwork tree and git dir. When a symbolic link in current $PWD points to a\ndirectory in a different level determining the number of \"../\" needed to\ntraverse to the superprojects work tree leads to a wrong result.\n\nAs there is no portable way to say \"pwd -P\" use cd_to_toplevel to remove\nthe link from the pwd, which fixes this problem.\n\nA test for this problem 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\nThanks to Bob for providing a very detailed bug report and test case!\n\n git-submodule.sh            |  4 ++--\n t/t7406-submodule-update.sh | 13 +++++++++++++\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 5629d87..f73e32e 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -186,8 +186,8 @@ 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+\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..05521de 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 '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.gb8ff004\n"},{"id":"194928","messageId":"4FFDCFA4.9060602@kdbg.org","threadId":"30995","inReplyTo":"4FFDC1EE.8080106@web.de","subject":"Re: [PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2012-07-11T19:10:28Z","receivedAt":"2012-07-11T19:10:28Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11.07.2012 20:11, schrieb Jens Lehmann:\n> Since 69c305178 (submodules: refactor computation of relative gitdir path)\n> cloning a submodule recursively fails for recursive submodules when a\n> symbolic link is part of the path to the work tree of the superproject.\n> \n> This happens when module_clone() tries to find the relative paths between\n> work tree and git dir. When a symbolic link in current $PWD points to a\n> directory in a different level determining the number of \"../\" needed to\n> traverse to the superprojects work tree leads to a wrong result.\n> \n> As there is no portable way to say \"pwd -P\" use cd_to_toplevel to remove\n> the link from the pwd, which fixes this problem.\n...\n> -\ta=$(cd \"$gitdir\" && pwd)/\n> -\tb=$(cd \"$sm_path\" && pwd)/\n> +\ta=$(cd_to_toplevel && cd \"$gitdir\" && pwd)/\n> +\tb=$(cd_to_toplevel && cd \"$sm_path\" && pwd)/\n\nBut if you cd out, how can it be correct not to cd in again if $gitdir\nand/or $sm_path are relative?\n\nAnd if $gitdir and/or $sm_path are absolute, how can the earlier\ncd_to_toplevel make a difference?\n\n> +test_expect_success 'submodule update can handle symbolic links in pwd' '\n\nPlease add a SYMLINKS prerequisite.\n\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-- Hannes\n"},{"id":"194929","messageId":"4FFDDCAD.5080001@web.de","threadId":"30995","inReplyTo":"4FFDCFA4.9060602@kdbg.org","subject":"Re: [PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-11T20:06:05Z","receivedAt":"2012-07-11T20:06:05Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 11.07.2012 21:10, schrieb Johannes Sixt:\n> Am 11.07.2012 20:11, schrieb Jens Lehmann:\n>> Since 69c305178 (submodules: refactor computation of relative gitdir path)\n>> cloning a submodule recursively fails for recursive submodules when a\n>> symbolic link is part of the path to the work tree of the superproject.\n>>\n>> This happens when module_clone() tries to find the relative paths between\n>> work tree and git dir. When a symbolic link in current $PWD points to a\n>> directory in a different level determining the number of \"../\" needed to\n>> traverse to the superprojects work tree leads to a wrong result.\n>>\n>> As there is no portable way to say \"pwd -P\" use cd_to_toplevel to remove\n>> the link from the pwd, which fixes this problem.\n> ...\n>> -\ta=$(cd \"$gitdir\" && pwd)/\n>> -\tb=$(cd \"$sm_path\" && pwd)/\n>> +\ta=$(cd_to_toplevel && cd \"$gitdir\" && pwd)/\n>> +\tb=$(cd_to_toplevel && cd \"$sm_path\" && pwd)/\n> \n> But if you cd out, how can it be correct not to cd in again if $gitdir\n> and/or $sm_path are relative?\n\nI'm not sure what you mean by \"cd out\", but the two \"cd_to_toplevel\"\nmake sure that when $gitdir or $sm_path are relative the symbolic link\ngets removed from the output of pwd. So it's rather \"cd into the path\nwhere the symlink is resolved\".\n\n> And if $gitdir and/or $sm_path are absolute, how can the earlier\n> cd_to_toplevel make a difference?\n\nThen it doesn't, but $sm_path is always relative while $gitdir is\nsometimes (in the superproject it returns \".git\"). Just drop either\nof the \"cd_to_toplevel\" and run the test ;-)\n\nBut it looks like the commit message could use some tuning ...\n\n>> +test_expect_success 'submodule update can handle symbolic links in pwd' '\n> \n> Please add a SYMLINKS prerequisite.\n\nOops. Thanks, will add that.\n\nWill wait some time for other comments before preparing v2.\n"},{"id":"194931","messageId":"4FFDE48B.7060802@kdbg.org","threadId":"30995","inReplyTo":"4FFDDCAD.5080001@web.de","subject":"Re: [PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2012-07-11T20:39:39Z","receivedAt":"2012-07-11T20:39:39Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11.07.2012 22:06, schrieb Jens Lehmann:\n> Am 11.07.2012 21:10, schrieb Johannes Sixt:\n>> Am 11.07.2012 20:11, schrieb Jens Lehmann:\n>>> Since 69c305178 (submodules: refactor computation of relative gitdir path)\n>>> cloning a submodule recursively fails for recursive submodules when a\n>>> symbolic link is part of the path to the work tree of the superproject.\n>>>\n>>> This happens when module_clone() tries to find the relative paths between\n>>> work tree and git dir. When a symbolic link in current $PWD points to a\n>>> directory in a different level determining the number of \"../\" needed to\n>>> traverse to the superprojects work tree leads to a wrong result.\n>>>\n>>> As there is no portable way to say \"pwd -P\" use cd_to_toplevel to remove\n>>> the link from the pwd, which fixes this problem.\n>> ...\n>>> -\ta=$(cd \"$gitdir\" && pwd)/\n>>> -\tb=$(cd \"$sm_path\" && pwd)/\n>>> +\ta=$(cd_to_toplevel && cd \"$gitdir\" && pwd)/\n>>> +\tb=$(cd_to_toplevel && cd \"$sm_path\" && pwd)/\n>>\n>> But if you cd out, how can it be correct not to cd in again if $gitdir\n>> and/or $sm_path are relative?\n> \n> I'm not sure what you mean by \"cd out\", but the two \"cd_to_toplevel\"\n> make sure that when $gitdir or $sm_path are relative the symbolic link\n> gets removed from the output of pwd. So it's rather \"cd into the path\n> where the symlink is resolved\".\n\nAt this point we can be in a subdirectory of the worktree. With\ncd_to_toplevel we move up in the directory hierarchy (\"cd out\"). Then a\nrelative $gitdir or $sm_path now points to the wrong directory. No?\n\n-- Hannes\n"},{"id":"194934","messageId":"4FFDEB46.6010403@web.de","threadId":"30995","inReplyTo":"4FFDE48B.7060802@kdbg.org","subject":"Re: [PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2012-07-11T21:08:22Z","receivedAt":"2012-07-11T21:08:22Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 11.07.2012 22:39, schrieb Johannes Sixt:\n> Am 11.07.2012 22:06, schrieb Jens Lehmann:\n>> Am 11.07.2012 21:10, schrieb Johannes Sixt:\n>>> Am 11.07.2012 20:11, schrieb Jens Lehmann:\n>>>> Since 69c305178 (submodules: refactor computation of relative gitdir path)\n>>>> cloning a submodule recursively fails for recursive submodules when a\n>>>> symbolic link is part of the path to the work tree of the superproject.\n>>>>\n>>>> This happens when module_clone() tries to find the relative paths between\n>>>> work tree and git dir. When a symbolic link in current $PWD points to a\n>>>> directory in a different level determining the number of \"../\" needed to\n>>>> traverse to the superprojects work tree leads to a wrong result.\n>>>>\n>>>> As there is no portable way to say \"pwd -P\" use cd_to_toplevel to remove\n>>>> the link from the pwd, which fixes this problem.\n>>> ...\n>>>> -\ta=$(cd \"$gitdir\" && pwd)/\n>>>> -\tb=$(cd \"$sm_path\" && pwd)/\n>>>> +\ta=$(cd_to_toplevel && cd \"$gitdir\" && pwd)/\n>>>> +\tb=$(cd_to_toplevel && cd \"$sm_path\" && pwd)/\n>>>\n>>> But if you cd out, how can it be correct not to cd in again if $gitdir\n>>> and/or $sm_path are relative?\n>>\n>> I'm not sure what you mean by \"cd out\", but the two \"cd_to_toplevel\"\n>> make sure that when $gitdir or $sm_path are relative the symbolic link\n>> gets removed from the output of pwd. So it's rather \"cd into the path\n>> where the symlink is resolved\".\n> \n> At this point we can be in a subdirectory of the worktree. With\n> cd_to_toplevel we move up in the directory hierarchy (\"cd out\"). Then a\n> relative $gitdir or $sm_path now points to the wrong directory. No?\n\nNope, \"git submodule\" will refuse to run in anything but the root of\nthe worktree. So we already are at the toplevel and use \"cd_to_toplevel\"\nonly to resolve any symlinks present in $PWD. Looks like a comment\nexplaining that above those lines would be a good idea ... will add one.\n"},{"id":"194970","messageId":"4FFF0575.3050203@kdbg.org","threadId":"30995","inReplyTo":"4FFDEB46.6010403@web.de","subject":"Re: [PATCH] submodules: don't stumble over symbolic links when cloning recursively","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2012-07-12T17:12:21Z","receivedAt":"2012-07-12T17:12:21Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Am 11.07.2012 23:08, schrieb Jens Lehmann:\n> Am 11.07.2012 22:39, schrieb Johannes Sixt:\n>> At this point we can be in a subdirectory of the worktree. With\n>> cd_to_toplevel we move up in the directory hierarchy (\"cd out\"). Then a\n>> relative $gitdir or $sm_path now points to the wrong directory. No?\n> \n> Nope, \"git submodule\" will refuse to run in anything but the root of\n> the worktree. So we already are at the toplevel and use \"cd_to_toplevel\"\n> only to resolve any symlinks present in $PWD. Looks like a comment\n> explaining that above those lines would be a good idea ... will add one.\n\nAh, OK. I missed the lack of SUBDIRECTORY_OK=Yes, but noticed a few\ncd_to_toplevel sprinkled throughout the script, so I thought it was OK\nto be in a subdirectory.\n\n-- Hannes\n"}]}