{"thread":{"id":"30577","subject":"[PATCH v3 1/4] submodule: verify support for superproject origin URLs of the form ./foo/bar or ../foo/bar","startedAt":"2012-05-21T13:31:39Z","lastAt":"2012-05-21T22:20:07Z","messageCount":6,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"191801","messageId":"1337607102-14737-1-git-send-email-jon.seymour@gmail.com","threadId":"30577","inReplyTo":null,"subject":"[PATCH v3 1/4] submodule: verify support for superproject origin URLs of the form ./foo/bar or ../foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T13:31:39Z","receivedAt":"2012-05-21T13:31:39Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"These tests are expected to fail, pending a subsequent corrective patch.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t7400-submodule-basic.sh | 26 ++++++++++++++++++++++++++\n t/t7403-submodule-sync.sh  | 10 ++++++++++\n 2 files changed, 36 insertions(+)\n\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 81827e6..02e6428 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -507,6 +507,32 @@ test_expect_success 'relative path works with user@host:path' '\n \t)\n '\n \n+test_expect_failure 'relative path works with ../relative/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tgit config remote.origin.url ../relative/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ../../relative/subrepo\n+\t)\n+'\n+\n+test_expect_failure 'test that submodule add creates the correct url when super origin url is ../relative/repo' '\n+\tmkdir reladd &&\n+\t(\n+\t\tcd reladd &&\n+\t\tgit init &&\n+\t\tgit remote add origin ../relative/repo\n+\t\tmkdir sub &&\n+\t\t(\n+\t\t\tcd sub &&\n+\t\t\tgit init &&\n+\t\t\ttest_commit foo\n+\t\t) &&\n+\t\tgit submodule add ../subrepo ./sub &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ../../relative/subrepo\n+\t)\n+'\n test_expect_success 'moving the superproject does not break submodules' '\n \t(\n \t\tcd addtest &&\ndiff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\nindex 3620215..788bc24 100755\n--- a/t/t7403-submodule-sync.sh\n+++ b/t/t7403-submodule-sync.sh\n@@ -86,4 +86,14 @@ test_expect_success '\"git submodule sync\" should not vivify uninteresting submod\n \t)\n '\n \n+test_expect_failure '\"git submodule sync\" should handle a super with a relative origin URL' '\n+\tgit clone super relative-clone &&\n+\t(cd relative-clone &&\n+\t git submodule update --init &&\n+\t git remote set-url origin ../relative/super.git &&\n+\t git submodule sync &&\n+\t test \"$(git config submodule.submodule.url)\" == ../../relative/moved-submodule\n+\t)\n+'\n+\n test_done\n-- \n1.7.10.2.594.g5c52315\n"},{"id":"191803","messageId":"1337607102-14737-2-git-send-email-jon.seymour@gmail.com","threadId":"30577","inReplyTo":"1337607102-14737-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v3 2/4] submodule: support superproject origin URLs of the form ./foo/bar or ../foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T13:31:40Z","receivedAt":"2012-05-21T13:31:40Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"When the origin URL of the superproject is itself relative, an operation\nsuch as git submodule add, init or sync produces a relative\nURL for the submodule that doesn't point at the correct location.\n\nThe issue arises in these cases because the origin URL of\nthe superproject needs to be prepended with a prefix that navigates\nfrom the submodule to the superproject so that when the submodule\nURL is concatenated the resulting URL is relative to the working tree\nof the submodule.\n\nThis change ensures that this is done for add, sync and init.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-submodule.sh           | 35 ++++++++++++++++++++---------------\n t/t7400-submodule-basic.sh |  4 ++--\n t/t7403-submodule-sync.sh  |  2 +-\n 3 files changed, 23 insertions(+), 18 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 64a70d6..230c219 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -45,6 +45,10 @@ resolve_relative_url ()\n \t\t../*)\n \t\t\turl=\"${url#../}\"\n \t\t\tcase \"$remoteurl\" in\n+\t\t\t.*/*)\n+\t\t\t\tup_path=\"$(echo \"$2\" | sed \"s/[^/]*/../g\")\"\n+\t\t\t\tremoteurl=\"${up_path%/}/${remoteurl%/*}\"\n+\t\t\t\t;;\n \t\t\t*/*)\n \t\t\t\tremoteurl=\"${remoteurl%/*}\"\n \t\t\t\t;;\n@@ -235,11 +239,24 @@ cmd_add()\n \t\tusage\n \tfi\n \n+\t# normalize path:\n+\t# multiple //; leading ./; /./; /../; trailing /\n+\tsm_path=$(printf '%s/\\n' \"$sm_path\" |\n+\t\tsed -e '\n+\t\t\ts|//*|/|g\n+\t\t\ts|^\\(\\./\\)*||\n+\t\t\ts|/\\./|/|g\n+\t\t\t:start\n+\t\t\ts|\\([^/]*\\)/\\.\\./||\n+\t\t\ttstart\n+\t\t\ts|/*$||\n+\t\t')\n+\n \t# assure repo is absolute or relative to parent\n \tcase \"$repo\" in\n \t./*|../*)\n \t\t# dereference source url relative to parent's url\n-\t\trealrepo=$(resolve_relative_url \"$repo\") || exit\n+\t\trealrepo=$(resolve_relative_url \"$repo\" \"$sm_path\") || exit\n \t\t;;\n \t*:*|/*)\n \t\t# absolute url\n@@ -250,18 +267,6 @@ cmd_add()\n \t;;\n \tesac\n \n-\t# normalize path:\n-\t# multiple //; leading ./; /./; /../; trailing /\n-\tsm_path=$(printf '%s/\\n' \"$sm_path\" |\n-\t\tsed -e '\n-\t\t\ts|//*|/|g\n-\t\t\ts|^\\(\\./\\)*||\n-\t\t\ts|/\\./|/|g\n-\t\t\t:start\n-\t\t\ts|\\([^/]*\\)/\\.\\./||\n-\t\t\ttstart\n-\t\t\ts|/*$||\n-\t\t')\n \tgit ls-files --error-unmatch \"$sm_path\" > /dev/null 2>&1 &&\n \tdie \"$(eval_gettext \"'\\$sm_path' already exists in the index\")\"\n \n@@ -407,7 +412,7 @@ cmd_init()\n \t\t\t# Possibly a url relative to parent\n \t\t\tcase \"$url\" in\n \t\t\t./*|../*)\n-\t\t\t\turl=$(resolve_relative_url \"$url\") || exit\n+\t\t\t\turl=$(resolve_relative_url \"$url\" \"$sm_path\") || exit\n \t\t\t\t;;\n \t\t\tesac\n \t\t\tgit config submodule.\"$name\".url \"$url\" ||\n@@ -964,7 +969,7 @@ cmd_sync()\n \t\t# Possibly a url relative to parent\n \t\tcase \"$url\" in\n \t\t./*|../*)\n-\t\t\turl=$(resolve_relative_url \"$url\") || exit\n+\t\t\turl=$(resolve_relative_url \"$url\" \"$sm_path\") || exit\n \t\t\t;;\n \t\tesac\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 02e6428..b838f43 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -507,7 +507,7 @@ test_expect_success 'relative path works with user@host:path' '\n \t)\n '\n \n-test_expect_failure 'relative path works with ../relative/repo' '\n+test_expect_success 'relative path works with ../relative/repo' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\n@@ -517,7 +517,7 @@ test_expect_failure 'relative path works with ../relative/repo' '\n \t)\n '\n \n-test_expect_failure 'test that submodule add creates the correct url when super origin url is ../relative/repo' '\n+test_expect_sucess 'test that submodule add creates the correct url when super origin url is ../relative/repo' '\n \tmkdir reladd &&\n \t(\n \t\tcd reladd &&\ndiff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\nindex 788bc24..35700ef 100755\n--- a/t/t7403-submodule-sync.sh\n+++ b/t/t7403-submodule-sync.sh\n@@ -86,7 +86,7 @@ test_expect_success '\"git submodule sync\" should not vivify uninteresting submod\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" should handle a super with a relative origin URL' '\n+test_expect_success '\"git submodule sync\" should handle a super with a relative origin URL' '\n \tgit clone super relative-clone &&\n \t(cd relative-clone &&\n \t git submodule update --init &&\n-- \n1.7.10.2.594.g5c52315\n"},{"id":"191802","messageId":"1337607102-14737-3-git-send-email-jon.seymour@gmail.com","threadId":"30577","inReplyTo":"1337607102-14737-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v3 3/4] submodule: verify support for superproject URLs of the form foo/bar.","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T13:31:41Z","receivedAt":"2012-05-21T13:31:41Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"This test shows that git submodule add produces the wrong submodule URL\nwhen the origin URL of the superproject is of the form: foo/bar.\n\nThe problem is fixed by a subsequent patch.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t7400-submodule-basic.sh | 17 +++++++++++++++++\n 1 file changed, 17 insertions(+)\n\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex b838f43..71f30d8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -533,6 +533,23 @@ test_expect_sucess 'test that submodule add creates the correct url when super o\n \t\ttest \"$(git config submodule.sub.url)\" = ../../relative/subrepo\n \t)\n '\n+test_expect_failure 'test that submodule add creates the correct url when super origin url is relative/repo' '\n+\tmkdir reladd &&\n+\t(\n+\t\tcd reladd &&\n+\t\tgit init &&\n+\t\tgit remote add origin relative/repo\n+\t\tmkdir sub &&\n+\t\t(\n+\t\t\tcd sub &&\n+\t\t\tgit init &&\n+\t\t\ttest_commit foo\n+\t\t) &&\n+\t\tgit submodule add ../subrepo ./sub &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ../relative/subrepo\n+\t)\n+'\n+\n test_expect_success 'moving the superproject does not break submodules' '\n \t(\n \t\tcd addtest &&\n-- \n1.7.10.2.594.g5c52315\n"},{"id":"191804","messageId":"1337607102-14737-4-git-send-email-jon.seymour@gmail.com","threadId":"30577","inReplyTo":"1337607102-14737-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v3 4/4] submodule: support superproject origin URLs of the form foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T13:31:42Z","receivedAt":"2012-05-21T13:31:42Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"When the origin URL of a superproject is of the form foo/bar, submodule\noperations such as add, sync or init will configure the URL of any\nsubmodule with an origin URL that points at the incorrect location.\n\nOrigin URLs of this form are not expected in most cases, since\nthe origin URL of a repo will usually point to a location that is not\nnested within the current working tree.\n\nHowever, the situation can arise when the physical location\nof an upstream repo is managed with a symbolic link nested within\nthe working tree itself.\n\nFor example, suppose that a toolset is installed in ~/tools and\n~/tools/mnt/usb is a occasionally used as the origin for a refresh of the\ntoolset. Different users with different USB devices may map ~/tools/mnt/usb\nto a different subdirectory of /media, but the auto-update function of the\ntoolset may simply pull an update from mnt/usb, assuming that the user has\ndone what is required to initialise mnt/usb to refer to the correct subdirectory\nof /media.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-submodule.sh           | 2 ++\n t/t7400-submodule-basic.sh | 2 +-\n 2 files changed, 3 insertions(+), 1 deletion(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 230c219..b8a7403 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -37,6 +37,7 @@ resolve_relative_url ()\n \tremoteurl=$(git config \"remote.$remote.url\") ||\n \t\tremoteurl=$(pwd) # the repository is its own authoritative upstream\n \turl=\"$1\"\n+\tremoteurl=$(echo \"$remoteurl\" | sed \"s|^[^/][^:]*\\$|./&|\")\n \tremoteurl=${remoteurl%/}\n \tsep=/\n \twhile test -n \"$url\"\n@@ -47,6 +48,7 @@ resolve_relative_url ()\n \t\t\tcase \"$remoteurl\" in\n \t\t\t.*/*)\n \t\t\t\tup_path=\"$(echo \"$2\" | sed \"s/[^/]*/../g\")\"\n+\t\t\t\tremoteurl=${remoteurl#./}\n \t\t\t\tremoteurl=\"${up_path%/}/${remoteurl%/*}\"\n \t\t\t\t;;\n \t\t\t*/*)\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 71f30d8..a4a8363 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -533,7 +533,7 @@ test_expect_sucess 'test that submodule add creates the correct url when super o\n \t\ttest \"$(git config submodule.sub.url)\" = ../../relative/subrepo\n \t)\n '\n-test_expect_failure 'test that submodule add creates the correct url when super origin url is relative/repo' '\n+test_expect_success 'test that submodule add creates the correct url when super origin url is relative/repo' '\n \tmkdir reladd &&\n \t(\n \t\tcd reladd &&\n-- \n1.7.10.2.594.g5c52315\n"},{"id":"191817","messageId":"CAH3AnrqBeD3JisjoK2dqnPWcBAFTxB5NYgRkfSPqb-CS8a0hsw@mail.gmail.com","threadId":"30577","inReplyTo":"1337607102-14737-2-git-send-email-jon.seymour@gmail.com","subject":"Re: [PATCH v3 2/4] submodule: support superproject origin URLs of the form ./foo/bar or ../foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T16:35:27Z","receivedAt":"2012-05-21T16:35:27Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"On Mon, May 21, 2012 at 11:31 PM, Jon Seymour <jon.seymour@gmail.com> wrote:\n> When the origin URL of the superproject is itself relative, an operation\n> such as git submodule add, init or sync produces a relative\n> URL for the submodule that doesn't point at the correct location.\n>\n> The issue arises in these cases because the origin URL of\n> the superproject needs to be prepended with a prefix that navigates\n> from the submodule to the superproject so that when the submodule\n> URL is concatenated the resulting URL is relative to the working tree\n> of the submodule.\n>\n> This change ensures that this is done for add, sync and init.\n>\n> Signed-off-by: Jon Seymour <jon.seymour@gmail.com>\n> ---\n>  git-submodule.sh           | 35 ++++++++++++++++++++---------------\n>  t/t7400-submodule-basic.sh |  4 ++--\n>  t/t7403-submodule-sync.sh  |  2 +-\n>  3 files changed, 23 insertions(+), 18 deletions(-)\n>\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 64a70d6..230c219 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -45,6 +45,10 @@ resolve_relative_url ()\n>                ../*)\n>                        url=\"${url#../}\"\n>                        case \"$remoteurl\" in\n> +                       .*/*)\n> +                               up_path=\"$(echo \"$2\" | sed \"s/[^/]*/../g\")\"\n> +                               remoteurl=\"${up_path%/}/${remoteurl%/*}\"\n> +                               ;;\n>                        */*)\n>                                remoteurl=\"${remoteurl%/*}\"\n>                                ;;\n> @@ -235,11 +239,24 @@ cmd_add()\n>                usage\n>        fi\n>\n> +       # normalize path:\n> +       # multiple //; leading ./; /./; /../; trailing /\n> +       sm_path=$(printf '%s/\\n' \"$sm_path\" |\n> +               sed -e '\n> +                       s|//*|/|g\n> +                       s|^\\(\\./\\)*||\n> +                       s|/\\./|/|g\n> +                       :start\n> +                       s|\\([^/]*\\)/\\.\\./||\n> +                       tstart\n> +                       s|/*$||\n> +               ')\n> +\n>        # assure repo is absolute or relative to parent\n>        case \"$repo\" in\n>        ./*|../*)\n>                # dereference source url relative to parent's url\n> -               realrepo=$(resolve_relative_url \"$repo\") || exit\n> +               realrepo=$(resolve_relative_url \"$repo\" \"$sm_path\") || exit\n>                ;;\n>        *:*|/*)\n>                # absolute url\n> @@ -250,18 +267,6 @@ cmd_add()\n>        ;;\n>        esac\n>\n> -       # normalize path:\n> -       # multiple //; leading ./; /./; /../; trailing /\n> -       sm_path=$(printf '%s/\\n' \"$sm_path\" |\n> -               sed -e '\n> -                       s|//*|/|g\n> -                       s|^\\(\\./\\)*||\n> -                       s|/\\./|/|g\n> -                       :start\n> -                       s|\\([^/]*\\)/\\.\\./||\n> -                       tstart\n> -                       s|/*$||\n> -               ')\n>        git ls-files --error-unmatch \"$sm_path\" > /dev/null 2>&1 &&\n>        die \"$(eval_gettext \"'\\$sm_path' already exists in the index\")\"\n>\n> @@ -407,7 +412,7 @@ cmd_init()\n>                        # Possibly a url relative to parent\n>                        case \"$url\" in\n>                        ./*|../*)\n> -                               url=$(resolve_relative_url \"$url\") || exit\n> +                               url=$(resolve_relative_url \"$url\" \"$sm_path\") || exit\n>                                ;;\n>                        esac\n>                        git config submodule.\"$name\".url \"$url\" ||\n> @@ -964,7 +969,7 @@ cmd_sync()\n>                # Possibly a url relative to parent\n>                case \"$url\" in\n>                ./*|../*)\n> -                       url=$(resolve_relative_url \"$url\") || exit\n> +                       url=$(resolve_relative_url \"$url\" \"$sm_path\") || exit\n>                        ;;\n>                esac\n>\n> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\n> index 02e6428..b838f43 100755\n> --- a/t/t7400-submodule-basic.sh\n> +++ b/t/t7400-submodule-basic.sh\n> @@ -507,7 +507,7 @@ test_expect_success 'relative path works with user@host:path' '\n>        )\n>  '\n>\n> -test_expect_failure 'relative path works with ../relative/repo' '\n> +test_expect_success 'relative path works with ../relative/repo' '\n>        (\n>                cd reltest &&\n>                cp pristine-.git-config .git/config &&\n> @@ -517,7 +517,7 @@ test_expect_failure 'relative path works with ../relative/repo' '\n>        )\n>  '\n>\n> -test_expect_failure 'test that submodule add creates the correct url when super origin url is ../relative/repo' '\n> +test_expect_sucess 'test that submodule add creates the correct url when super origin url is ../relative/repo' '\n>        mkdir reladd &&\n>        (\n>                cd reladd &&\n> diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\n> index 788bc24..35700ef 100755\n> --- a/t/t7403-submodule-sync.sh\n> +++ b/t/t7403-submodule-sync.sh\n> @@ -86,7 +86,7 @@ test_expect_success '\"git submodule sync\" should not vivify uninteresting submod\n>        )\n>  '\n>\n> -test_expect_failure '\"git submodule sync\" should handle a super with a relative origin URL' '\n> +test_expect_success '\"git submodule sync\" should handle a super with a relative origin URL' '\n>        git clone super relative-clone &&\n>        (cd relative-clone &&\n>         git submodule update --init &&\n> --\n> 1.7.10.2.594.g5c52315\n>\n\nMmmm. Better hold off on this one for the moment, I have detected a\nbreak during a subsequent git submodule update that my selection of\nregression tests didn't pick up. The issue is that the URL used for\ncloning the submodule during the update is now not correct.\n\njon.\n"},{"id":"191840","messageId":"CAH3AnrrEnLEnN=EgzaDjFtN6r9RBpTmPNTX96QiMtGz9J12eCQ@mail.gmail.com","threadId":"30577","inReplyTo":"CAH3AnrqBeD3JisjoK2dqnPWcBAFTxB5NYgRkfSPqb-CS8a0hsw@mail.gmail.com","subject":"Re: [PATCH v3 2/4] submodule: support superproject origin URLs of the form ./foo/bar or ../foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-05-21T22:20:07Z","receivedAt":"2012-05-21T22:20:07Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"On Tue, May 22, 2012 at 2:35 AM, Jon Seymour <jon.seymour@gmail.com> wrote:\n> On Mon, May 21, 2012 at 11:31 PM, Jon Seymour <jon.seymour@gmail.com> wrote:\n>\n> Mmmm. Better hold off on this one for the moment, I have detected a\n> break during a subsequent git submodule update that my selection of\n> regression tests didn't pick up. The issue is that the URL used for\n> cloning the submodule during the update is now not correct.\n>\n> jon.\n\nI guess the issue here is that whereas the origin url of the submodule\n(as in remote.origin.url in the submodule) should be relative to the\nsubmodule's working tree, it might actually be better to keep\nsubmodule.{modulename}.url relative to the working directory of\nsuperproject (which is current behaviour).\n\nThoughts?\n\njon.\n"}]}