{"thread":{"id":"30726","subject":"[PATCH v9 0/4] submodule: improve support for relative superproject origin URLs","startedAt":"2012-06-06T11:57:26Z","lastAt":"2012-06-06T11:57:30Z","messageCount":5,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":9,"patchTotal":4},"messages":[{"id":"192974","messageId":"1338983850-9872-1-git-send-email-jon.seymour@gmail.com","threadId":"30726","inReplyTo":null,"subject":"[PATCH v9 0/4] submodule: improve support for relative superproject origin URLs","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-06-06T11:57:26Z","receivedAt":"2012-06-06T11:57:26Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"This series improves handling by 'git submodule' of relative superproject origin URLs. \n\nCurrently, 'git submodule':\n\n* incorrectly configures origin URL for submodules with a path that is relative to\nthe work tree of the superproject when the configured path needs to be relative \nto the work tree of the submodule\n\n* unnecessarily fails with an error if the superproject origin URL is of the form: foo\n\nThis series corrects these problems for paths like the following:\n  foo\n  foo/bar\n  ./foo\n  ./foo/bar\n  ../foo\n  ../foo/bar\n\nIt does not change current behaviour for URLs that begin with a leading '/' or contain\na ':' as such URLs are deemed to be absolute URLs for which no correction is required.\n\nIn addition, this series ensures that relative URLs configured by git submodule do\nnot include a superfluous leading or embedded './'.\n\nThis series differs from v7 by removing the patches dealing incorrect handling \nof greedy submodule URLs (those with too many leading ../'s) and those that deal\nwith improperly normalized superproject origin URLs. These patches may resubmitted\nat a later date.\n\nThis series differs from v8 by fixing the indentation of case branches, using \na sed idiom that avoids a Solaris sed bug, and reverts the name of the \n'module_url' variable used by cmd_sync() to 'url'. The commentary for\nresolve_relative_url is adjusted slightly to remove the implication that the \nfirst argument is always a relative URL.\n\nJon Seymour (4):\n  submodule: additional regression tests for relative URLs\n  submodule: document failure to handle relative superproject origin\n    URLs\n  submodule: fix sync handling of some relative superproject origin\n    URLs\n  submodule: fix handling of superproject origin URLs like foo, ./foo\n    and ./foo/bar\n\n git-submodule.sh           |  60 +++++++++++++++++--\n t/t7400-submodule-basic.sh | 144 ++++++++++++++++++++++++++++++++++++++++++++-\n t/t7403-submodule-sync.sh  |  90 +++++++++++++++++++++++++++-\n 3 files changed, 284 insertions(+), 10 deletions(-)\n\n-- \n1.7.10.2.650.g9c513dd.dirty\n"},{"id":"192977","messageId":"1338983850-9872-2-git-send-email-jon.seymour@gmail.com","threadId":"30726","inReplyTo":"1338983850-9872-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v9 1/4] submodule: additional regression tests for relative URLs","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-06-06T11:57:27Z","receivedAt":"2012-06-06T11:57:27Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Some additional tests are added to support regression testing of the changes in the\nremainder of the series.\n\nWe also add a pristine copy of .gitmodules in anticipation of this being\nrequired by later tests.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t7400-submodule-basic.sh | 110 +++++++++++++++++++++++++++++++++++++++++++--\n 1 file changed, 107 insertions(+), 3 deletions(-)\n\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 81827e6..9428c7a 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -483,21 +483,67 @@ test_expect_success 'set up for relative path tests' '\n \t\tgit add sub &&\n \t\tgit config -f .gitmodules submodule.sub.path sub &&\n \t\tgit config -f .gitmodules submodule.sub.url ../subrepo &&\n-\t\tcp .git/config pristine-.git-config\n+\t\tcp .git/config pristine-.git-config &&\n+\t\tcp .gitmodules pristine-.gitmodules\n \t)\n '\n \n-test_expect_success 'relative path works with URL' '\n+test_expect_success '../subrepo works with URL - ssh://hostname/repo' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n \t\tgit config remote.origin.url ssh://hostname/repo &&\n \t\tgit submodule init &&\n \t\ttest \"$(git config submodule.sub.url)\" = ssh://hostname/subrepo\n \t)\n '\n \n-test_expect_success 'relative path works with user@host:path' '\n+test_expect_success '../subrepo works with port-qualified URL - ssh://hostname:22/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url ssh://hostname:22/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ssh://hostname:22/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo path works with local path - /foo/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url /foo/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = /foo/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with file URL - file:///tmp/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url file:///tmp/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = file:///tmp/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with helper URL- helper:://hostname/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url helper:://hostname/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = helper:://hostname/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with scp-style URL - user@host:repo' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\n@@ -507,6 +553,64 @@ test_expect_success 'relative path works with user@host:path' '\n \t)\n '\n \n+test_expect_success '../subrepo works with scp-style URL - user@host:path/to/repo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url user@host:path/to/repo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = user@host:path/to/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with relative local path - foo/bar' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url foo/bar &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = foo/subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with relative local path - ../foo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url ../foo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ../subrepo\n+\t)\n+'\n+\n+test_expect_success '../subrepo works with relative local path - ../foo/bar' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url ../foo/bar &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = ../foo/subrepo\n+\t)\n+'\n+\n+test_expect_success '../bar/a/b/c works with relative local path - ../foo/bar.git' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tmkdir -p a/b/c &&\n+\t\t(cd a/b/c; git init) &&\n+\t\tgit config remote.origin.url ../foo/bar.git &&\n+\t\tgit submodule add ../bar/a/b/c ./a/b/c &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.a/b/c.url)\" = ../foo/bar/a/b/c\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.650.g9c513dd.dirty\n"},{"id":"192976","messageId":"1338983850-9872-3-git-send-email-jon.seymour@gmail.com","threadId":"30726","inReplyTo":"1338983850-9872-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v9 2/4] submodule: document failure to handle relative superproject origin URLs","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-06-06T11:57:28Z","receivedAt":"2012-06-06T11:57:28Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"This test case documents several cases where handling of relative\nsuperproject origin URLs doesn't produce an expected result.\n\nsubmodule.{sub}.url in the superproject is incorrect in these cases:\n  foo\n  ./foo\n  ./foo/bar\n\nThe remote.origin.url of the submodule is incorrect in the above cases\nand also when the superproject origin URL is like:\n  foo/bar\n  ../foo\n  ../foo/bar\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n t/t7400-submodule-basic.sh | 34 ++++++++++++++++++\n t/t7403-submodule-sync.sh  | 90 +++++++++++++++++++++++++++++++++++++++++++++-\n 2 files changed, 123 insertions(+), 1 deletion(-)\n\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 9428c7a..09e2b9b 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -564,6 +564,18 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep\n \t)\n '\n \n+test_expect_failure '../subrepo works with relative local path - foo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url foo &&\n+\t\t# actual: fails with an error\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = subrepo\n+\t)\n+'\n+\n test_expect_success '../subrepo works with relative local path - foo/bar' '\n \t(\n \t\tcd reltest &&\n@@ -575,6 +587,28 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '\n \t)\n '\n \n+test_expect_failure '../subrepo works with relative local path - ./foo' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url ./foo &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = subrepo\n+\t)\n+'\n+\n+test_expect_failure '../subrepo works with relative local path - ./foo/bar' '\n+\t(\n+\t\tcd reltest &&\n+\t\tcp pristine-.git-config .git/config &&\n+\t\tcp pristine-.gitmodules .gitmodules &&\n+\t\tgit config remote.origin.url ./foo/bar &&\n+\t\tgit submodule init &&\n+\t\ttest \"$(git config submodule.sub.url)\" = foo/subrepo\n+\t)\n+'\n+\n test_expect_success '../subrepo works with relative local path - ../foo' '\n \t(\n \t\tcd reltest &&\ndiff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\nindex 3620215..56b933d 100755\n--- a/t/t7403-submodule-sync.sh\n+++ b/t/t7403-submodule-sync.sh\n@@ -26,7 +26,9 @@ test_expect_success setup '\n \t(cd super-clone && git submodule update --init) &&\n \tgit clone super empty-clone &&\n \t(cd empty-clone && git submodule init) &&\n-\tgit clone super top-only-clone\n+\tgit clone super top-only-clone &&\n+\tgit clone super relative-clone &&\n+\t(cd relative-clone && git submodule update --init)\n '\n \n test_expect_success 'change submodule' '\n@@ -86,4 +88,90 @@ test_expect_success '\"git submodule sync\" should not vivify uninteresting submod\n \t)\n '\n \n+test_expect_failure '\"git submodule sync\" handles origin URL of the form foo' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin foo &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual fails with: \"cannot strip off url foo\n+\t test \"$(git config remote.origin.url)\" = \"../submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form foo/bar' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin foo/bar &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual foo/submodule\n+\t test \"$(git config remote.origin.url)\" = \"../foo/submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin ./foo &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual ./submodule\n+\t test \"$(git config remote.origin.url)\" = \"../submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo/bar' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin ./foo/bar &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual ./foo/submodule\n+\t test \"$(git config remote.origin.url)\" = \"../foo/submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin ../foo &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual ../submodule\n+\t test \"$(git config remote.origin.url)\" = \"../../submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo/bar' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin ../foo/bar &&\n+\t git submodule sync &&\n+\t(cd submodule &&\n+\t #actual ../foo/submodule\n+\t test \"$(git config remote.origin.url)\" = \"../../foo/submodule\"\n+\t)\n+\t)\n+'\n+\n+test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo/bar with deeply nested submodule' '\n+\t(cd relative-clone &&\n+\t git remote set-url origin ../foo/bar &&\n+\t mkdir -p a/b/c &&\n+\t ( cd a/b/c &&\n+\t   git init &&\n+\t   :> .gitignore &&\n+\t   git add .gitignore &&\n+\t   test_tick &&\n+\t   git commit -m \"initial commit\" ) &&\n+\t git submodule add ../bar/a/b/c ./a/b/c &&\n+\t git submodule sync &&\n+\t(cd a/b/c &&\n+\t #actual ../foo/bar/a/b/c\n+\t test \"$(git config remote.origin.url)\" = \"../../../../foo/bar/a/b/c\"\n+\t)\n+\t)\n+'\n+\n+\n test_done\n-- \n1.7.10.2.650.g9c513dd.dirty\n"},{"id":"192975","messageId":"1338983850-9872-4-git-send-email-jon.seymour@gmail.com","threadId":"30726","inReplyTo":"1338983850-9872-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v9 3/4] submodule: fix sync handling of some relative superproject origin URLs","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-06-06T11:57:29Z","receivedAt":"2012-06-06T11:57:29Z","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, git submodule sync\nconfigures the remote.origin.url configuration property of the submodule\nwith a path that is relative to the work tree of the superproject\nrather than the work tree of the submodule.\n\nTo fix this an 'up_path' that navigates from the work tree of the submodule\nto the work tree of the superproject needs to be prepended to the URL\notherwise calculated.\n\nCorrect handling of superproject origin URLs like foo, ./foo and ./foo/bar is\nleft to a subsequent patch since an additional change is required to handle\nthese cases.\n\nThe documentation of resolve_relative_url() is expanded to give a more thorough\ndescription of the function's objective.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-submodule.sh          | 48 ++++++++++++++++++++++++++++++++++++++++++-----\n t/t7403-submodule-sync.sh |  8 ++++----\n 2 files changed, 47 insertions(+), 9 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 64a70d6..227ba59 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -30,7 +30,22 @@ nofetch=\n update=\n prefix=\n \n-# Resolve relative url by appending to parent's url\n+# The function takes at most 2 arguments. The first argument is the\n+# URL that navigates to the submodule origin repo. When relative, this URL\n+# is relative to the superproject origin URL repo. The second up_path \n+# argument, if specified, is the relative path that navigates \n+# from the submodule working tree to the superproject working tree.\n+#\n+# The output of the function is the origin URL of the submodule.\n+#\n+# The output will either be an absolute URL or filesystem path (if the\n+# superproject origin URL is an absolute URL or filesystem path,\n+# respectively) or a relative file system path (if the superproject\n+# origin URL is a relative file system path).\n+#\n+# When the output is a relative file system path, the path is either\n+# relative to the submodule working tree, if up_path is specified, or to\n+# the superproject working tree otherwise.\n resolve_relative_url ()\n {\n \tremote=$(get_default_remote)\n@@ -39,6 +54,17 @@ resolve_relative_url ()\n \turl=\"$1\"\n \tremoteurl=${remoteurl%/}\n \tsep=/\n+\tup_path=\"$2\"\n+\n+\tcase \"$remoteurl\" in\n+\t*:*|/*)\n+\t\tis_relative=\n+\t\t;;\n+\t*)\n+\t\tis_relative=t\n+\t\t;;\n+\tesac\n+\n \twhile test -n \"$url\"\n \tdo\n \t\tcase \"$url\" in\n@@ -64,7 +90,7 @@ resolve_relative_url ()\n \t\t\tbreak;;\n \t\tesac\n \tdone\n-\techo \"$remoteurl$sep${url%/}\"\n+\techo \"${is_relative:+${up_path}}$remoteurl$sep${url%/}\"\n }\n \n #\n@@ -964,14 +990,26 @@ 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\t# rewrite foo/bar as ../.. to find path from\n+\t\t\t# submodule work tree to superproject work tree\n+\t\t\tup_path=\"$(echo \"$sm_path\" | sed \"s/[^/][^/]*/../g\")\" &&\n+\t\t\t# guarantee a trailing /\n+\t\t\tup_path=${up_path%/}/ &&\n+\t\t\t# path from submodule work tree to submodule origin repo\n+\t\t\tsub_origin_url=$(resolve_relative_url \"$url\" \"$up_path\") &&\n+\t\t\t# path from superproject work tree to submodule origin repo\n+\t\t\tsuper_config_url=$(resolve_relative_url \"$url\") || exit\n+\t\t\t;;\n+\t\t*)\n+\t\t\tsub_origin_url=\"$url\"\n+\t\t\tsuper_config_url=\"$url\"\n \t\t\t;;\n \t\tesac\n \n \t\tif git config \"submodule.$name.url\" >/dev/null 2>/dev/null\n \t\tthen\n \t\t\tsay \"$(eval_gettext \"Synchronizing submodule url for '\\$name'\")\"\n-\t\t\tgit config submodule.\"$name\".url \"$url\"\n+\t\t\tgit config submodule.\"$name\".url \"$super_config_url\"\n \n \t\t\tif test -e \"$sm_path\"/.git\n \t\t\tthen\n@@ -979,7 +1017,7 @@ cmd_sync()\n \t\t\t\tclear_local_git_env\n \t\t\t\tcd \"$sm_path\"\n \t\t\t\tremote=$(get_default_remote)\n-\t\t\t\tgit config remote.\"$remote\".url \"$url\"\n+\t\t\t\tgit config remote.\"$remote\".url \"$sub_origin_url\"\n \t\t\t)\n \t\t\tfi\n \t\tfi\ndiff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\nindex 56b933d..98bc74a 100755\n--- a/t/t7403-submodule-sync.sh\n+++ b/t/t7403-submodule-sync.sh\n@@ -99,7 +99,7 @@ test_expect_failure '\"git submodule sync\" handles origin URL of the form foo' '\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form foo/bar' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form foo/bar' '\n \t(cd relative-clone &&\n \t git remote set-url origin foo/bar &&\n \t git submodule sync &&\n@@ -132,7 +132,7 @@ test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo/b\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form ../foo' '\n \t(cd relative-clone &&\n \t git remote set-url origin ../foo &&\n \t git submodule sync &&\n@@ -143,7 +143,7 @@ test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo'\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo/bar' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form ../foo/bar' '\n \t(cd relative-clone &&\n \t git remote set-url origin ../foo/bar &&\n \t git submodule sync &&\n@@ -154,7 +154,7 @@ test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo/\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form ../foo/bar with deeply nested submodule' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form ../foo/bar with deeply nested submodule' '\n \t(cd relative-clone &&\n \t git remote set-url origin ../foo/bar &&\n \t mkdir -p a/b/c &&\n-- \n1.7.10.2.650.g9c513dd.dirty\n"},{"id":"192978","messageId":"1338983850-9872-5-git-send-email-jon.seymour@gmail.com","threadId":"30726","inReplyTo":"1338983850-9872-1-git-send-email-jon.seymour@gmail.com","subject":"[PATCH v9 4/4] submodule: fix handling of superproject origin URLs like foo, ./foo and ./foo/bar","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2012-06-06T11:57:30Z","receivedAt":"2012-06-06T11:57:30Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"Currently git submodule init and git submodule sync fail with an error\nif the superproject origin URL is of the form foo but succeed if the\nsuperproject origin URL is of the form ./foo or ./foo/bar or foo/bar.\n\nThis change makes handling of the foo case behave like the handling\nof the ./foo case and also ensures that superfluous leading and\nembedded ./'s are removed from the resulting derived URLs.\n\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n---\n git-submodule.sh           | 14 ++++++++++++--\n t/t7400-submodule-basic.sh |  6 +++---\n t/t7403-submodule-sync.sh  |  6 +++---\n 3 files changed, 18 insertions(+), 8 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 227ba59..cff1348 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -60,8 +60,12 @@ resolve_relative_url ()\n \t*:*|/*)\n \t\tis_relative=\n \t\t;;\n+\t./*|../*)\n+\t\tis_relative=t\n+\t\t;;\n \t*)\n \t\tis_relative=t\n+\t\tremoteurl=\"./$remoteurl\"\n \t\t;;\n \tesac\n \n@@ -79,7 +83,12 @@ resolve_relative_url ()\n \t\t\t\tsep=:\n \t\t\t\t;;\n \t\t\t*)\n-\t\t\t\tdie \"$(eval_gettext \"cannot strip one component off url '\\$remoteurl'\")\"\n+\t\t\t\tif test -z \"$is_relative\" || test \".\" = \"$remoteurl\"\n+\t\t\t\tthen\n+\t\t\t\t\tdie \"$(eval_gettext \"cannot strip one component off url '\\$remoteurl'\")\"\n+\t\t\t\telse\n+\t\t\t\t\tremoteurl=.\n+\t\t\t\tfi\n \t\t\t\t;;\n \t\t\tesac\n \t\t\t;;\n@@ -90,7 +99,8 @@ resolve_relative_url ()\n \t\t\tbreak;;\n \t\tesac\n \tdone\n-\techo \"${is_relative:+${up_path}}$remoteurl$sep${url%/}\"\n+\tremoteurl=\"$remoteurl$sep${url%/}\"\n+\techo \"${is_relative:+${up_path}}${remoteurl#./}\"\n }\n \n #\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 09e2b9b..a899e6d 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -564,7 +564,7 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep\n \t)\n '\n \n-test_expect_failure '../subrepo works with relative local path - foo' '\n+test_expect_success '../subrepo works with relative local path - foo' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\n@@ -587,7 +587,7 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '\n \t)\n '\n \n-test_expect_failure '../subrepo works with relative local path - ./foo' '\n+test_expect_success '../subrepo works with relative local path - ./foo' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\n@@ -598,7 +598,7 @@ test_expect_failure '../subrepo works with relative local path - ./foo' '\n \t)\n '\n \n-test_expect_failure '../subrepo works with relative local path - ./foo/bar' '\n+test_expect_success '../subrepo works with relative local path - ./foo/bar' '\n \t(\n \t\tcd reltest &&\n \t\tcp pristine-.git-config .git/config &&\ndiff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh\nindex 98bc74a..524d5c1 100755\n--- a/t/t7403-submodule-sync.sh\n+++ b/t/t7403-submodule-sync.sh\n@@ -88,7 +88,7 @@ test_expect_success '\"git submodule sync\" should not vivify uninteresting submod\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form foo' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form foo' '\n \t(cd relative-clone &&\n \t git remote set-url origin foo &&\n \t git submodule sync &&\n@@ -110,7 +110,7 @@ test_expect_success '\"git submodule sync\" handles origin URL of the form foo/bar\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form ./foo' '\n \t(cd relative-clone &&\n \t git remote set-url origin ./foo &&\n \t git submodule sync &&\n@@ -121,7 +121,7 @@ test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo'\n \t)\n '\n \n-test_expect_failure '\"git submodule sync\" handles origin URL of the form ./foo/bar' '\n+test_expect_success '\"git submodule sync\" handles origin URL of the form ./foo/bar' '\n \t(cd relative-clone &&\n \t git remote set-url origin ./foo/bar &&\n \t git submodule sync &&\n-- \n1.7.10.2.650.g9c513dd.dirty\n"}]}