{"thread":{"id":"13138","subject":"[PATCH 6/7] git-submodule: \"update --force\" to enforce cloning non-submodule","startedAt":"2008-04-16T14:19:30Z","lastAt":"2008-04-22T17:20:18Z","messageCount":18,"participants":["Ping Yin","Junio C Hamano","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"74549","messageId":"1208355577-8734-1-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":null,"subject":"[PATCH 0/7] submodule: fallback to .gitmodules and multiple level module definition","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:30Z","receivedAt":"2008-04-16T14:19:30Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"This is a resend of the RFC patches some days ago, with only minor\ncode modification and log refinement. Also swap the order of the last\ntwo patches.\n\nSince there is less feedback these days, i don't know much what you\nguys think of this patch series. However, i have use this series for a\nlong time and think personally it is useful when having many submodules. \n\nSo i resend it, and look forward to its acceptance.\n\nThis patch series has following functional improvements for submodule\n\n - Fall back on .gitmodules if info not found in $GIT_DIR/config\n - multi-level module definition\n - Don't die when subcommand fails for one module\n\n Actually, they seems three independent improvements. But the first two\n improvements are both dependent on the first two refactoring patches\n and the 3rd improvement is dependent on the implementation of the\n first two improvements. So i have to send them in batch.\n\nPatches 1,2,4 is mainly code refactor but the second one also\nhas some semantic change.\n\nThe other patches do the real functional changes.\n\nPing Yin (7):\n      git-submodule: Extract functions module_info and module_url\n      git-submodule: Extract absolute_url & move absolute url logic to module_clone\n      git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config\n      git-submodule: Extract module_add from cmd_add\n      git-submodule: multi-level module definition\n      git-submodule: \"update --force\" to enforce cloning non-submodule\n      git-submodule: Don't die when command fails for one submodule\n\n git-submodule.sh           |  325 ++++++++++++++++++++++++++++++++------------\n t/t7400-submodule-basic.sh |   31 ++++-\n 2 files changed, 266 insertions(+), 90 deletions(-)\n\n\nFollowing is the diff with former RFC patch series\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 8bea97a..0ecc4ff 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -354,7 +354,7 @@ cmd_init()\n \t\texit_status=1 &&\n \t\tcontinue\n \t\t# Skip already registered paths\n-\t\tgit config submodule.$name.url && continue\n+\t\ttest -z \"$(git config submodule.$name.url)\" || continue\n \n \t\turl=$(absolute_url \"$url\")\n \t\tgit config submodule.\"$name\".url \"$url\" ||\n@@ -442,7 +442,6 @@ cmd_update()\n \t\t\t}\n \t\tfi\n \n-\n \t\tif test \"$subsha1\" != \"$sha1\"\n \t\tthen\n \t\t\t(unset GIT_DIR; cd \"$path\" && git-fetch &&\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex d9b48f7..8b35ff8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -187,7 +187,7 @@ test_expect_success 'status should be \"modified\" after submodule reset --hard HE\n \tgit-submodule status | grep \"^+$rev2\"\n '\n \n-test_expect_success 'update should checkout rev1 when fall back' '\n+test_expect_success 'update should checkout rev1 with falling back' '\n \tgit-config --unset submodule.example.url &&\n \tGIT_CONFIG=.gitmodules git config submodule.example.url .subrepo &&\n \tgit-submodule update init &&\n"},{"id":"74555","messageId":"1208355577-8734-2-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-1-git-send-email-pkufranky@gmail.com","subject":"[PATCH 1/7] git-submodule: Extract functions module_info and module_url","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:31Z","receivedAt":"2008-04-16T14:19:31Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"module_info is extracted to remove the logic redundance which acquires\nmodule names and urls by path filter in several places.\n\nmodule_url is also extracted to prepare for an alternative logic to get url by\nmodule name.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |   40 ++++++++++++++++++++++++++++------------\n 1 files changed, 28 insertions(+), 12 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex a745e42..0d82ec1 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -82,6 +82,25 @@ module_name()\n        echo \"$name\"\n }\n \n+module_url() {\n+\tgit config submodule.$1.url\n+}\n+\n+module_info() {\n+\tgit ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n+\twhile read mode sha1 stage path\n+\tdo\n+\t\tname=$(module_name \"$path\")\n+\t\tif test -n \"$name\"\n+\t\tthen\n+\t\t\turl=$(module_url \"$name\")\n+\t\t\techo \"$sha1\t$path\t$name\t$url\"\n+\t\telse\n+\t\t\techo \"$sha1\t$path\t\t\"\n+\t\tfi\n+\tdone\n+}\n+\n #\n # Clone a submodule\n #\n@@ -232,12 +251,11 @@ cmd_init()\n \t\tshift\n \tdone\n \n-\tgit ls-files --stage -- \"$@\" | grep '^160000 ' |\n-\twhile read mode sha1 stage path\n+\tmodule_info \"$@\" |\n+\twhile read sha1 path name url\n \tdo\n+\t\ttest -n \"$name\" || exit\n \t\t# Skip already registered paths\n-\t\tname=$(module_name \"$path\") || exit\n-\t\turl=$(git config submodule.\"$name\".url)\n \t\ttest -z \"$url\" || continue\n \n \t\turl=$(GIT_CONFIG=.gitmodules git config submodule.\"$name\".url)\n@@ -286,11 +304,10 @@ cmd_update()\n \t\tshift\n \tdone\n \n-\tgit ls-files --stage -- \"$@\" | grep '^160000 ' |\n-\twhile read mode sha1 stage path\n+\tmodule_info \"$@\" |\n+\twhile read sha1 path name url\n \tdo\n-\t\tname=$(module_name \"$path\") || exit\n-\t\turl=$(git config submodule.\"$name\".url)\n+\t\ttest -n \"$name\" || exit\n \t\tif test -z \"$url\"\n \t\tthen\n \t\t\t# Only mention uninitialized submodules when its\n@@ -538,11 +555,10 @@ cmd_status()\n \t\tshift\n \tdone\n \n-\tgit ls-files --stage -- \"$@\" | grep '^160000 ' |\n-\twhile read mode sha1 stage path\n+\tmodule_info \"$@\" |\n+\twhile read sha1 path name url\n \tdo\n-\t\tname=$(module_name \"$path\") || exit\n-\t\turl=$(git config submodule.\"$name\".url)\n+\t\ttest -n \"$name\" || exit\n \t\tif test -z \"$url\" || ! test -d \"$path\"/.git\n \t\tthen\n \t\t\tsay \"-$sha1 $path\"\n-- \n1.5.5.70.gd68a\n"},{"id":"74551","messageId":"1208355577-8734-3-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-2-git-send-email-pkufranky@gmail.com","subject":"[PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:32Z","receivedAt":"2008-04-16T14:19:32Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"Extract function absolute_url to remove code redundance and inconsistence in\ncmd_init and cmd_add when resolving relative url/path to absolute one.\n\nAlso move resolving absolute url logic from cmd_add to module_clone which\nresults in a litte behaviour change: cmd_update originally doesn't\nresolve absolute url but now it will.\n\nThis behaviour change breaks t7400 which uses relative url './.subrepo'.\nHowever, this test originally doesn't mean to test relative url with './',\nso fix the url as '.subrepo'.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh           |   41 ++++++++++++++++++-----------------------\n t/t7400-submodule-basic.sh |    2 +-\n 2 files changed, 19 insertions(+), 24 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 0d82ec1..d3ae1e4 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -65,6 +65,21 @@ resolve_relative_url ()\n \techo \"$remoteurl/$url\"\n }\n \n+# Resolve relative url/path to absolute one\n+absolute_url () {\n+\tcase \"$1\" in\n+\t./*|../*)\n+\t\t# dereference source url relative to parent's url\n+\t\turl=\"$(resolve_relative_url $1)\" ;;\n+\t*)\n+\t\t# Turn the source into an absolute path if it is local\n+\t\turl=$(get_repo_base \"$1\") ||\n+\t\turl=$1\n+\t\t;;\n+\tesac\n+\techo \"$url\"\n+}\n+\n #\n # Map submodule path to submodule name\n #\n@@ -112,7 +127,7 @@ module_info() {\n module_clone()\n {\n \tpath=$1\n-\turl=$2\n+\turl=$(absolute_url \"$2\")\n \n \t# If there already is a directory at the submodule path,\n \t# expect it to be empty (since that is the default checkout\n@@ -195,21 +210,7 @@ cmd_add()\n \t\t\tdie \"'$path' already exists and is not a valid git repo\"\n \t\tfi\n \telse\n-\t\tcase \"$repo\" in\n-\t\t./*|../*)\n-\t\t\t# dereference source url relative to parent's url\n-\t\t\trealrepo=\"$(resolve_relative_url $repo)\" ;;\n-\t\t*)\n-\t\t\t# Turn the source into an absolute path if\n-\t\t\t# it is local\n-\t\t\tif base=$(get_repo_base \"$repo\"); then\n-\t\t\t\trepo=\"$base\"\n-\t\t\tfi\n-\t\t\trealrepo=$repo\n-\t\t\t;;\n-\t\tesac\n-\n-\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n+\t\tmodule_clone \"$path\" \"$repo\" || exit\n \t\t(unset GIT_DIR; cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n \t\tdie \"Unable to checkout submodule '$path'\"\n \tfi\n@@ -262,13 +263,7 @@ cmd_init()\n \t\ttest -z \"$url\" &&\n \t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n \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\")\"\n-\t\t\t;;\n-\t\tesac\n-\n+\t\turl=$(absolute_url \"$url\")\n \t\tgit config submodule.\"$name\".url \"$url\" ||\n \t\tdie \"Failed to register url for submodule path '$path'\"\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 2ef85a8..e5d59b8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' '\n \tthen\n \t\techo \"[OOPS] init succeeded but submodule url is wrong\"\n \t\tfalse\n-\telif ! git config submodule.example.url ./.subrepo\n+\telif ! git config submodule.example.url .subrepo\n \tthen\n \t\techo \"[OOPS] init succeeded but update of url failed\"\n \t\tfalse\n-- \n1.5.5.70.gd68a\n"},{"id":"74552","messageId":"1208355577-8734-4-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-3-git-send-email-pkufranky@gmail.com","subject":"[PATCH 3/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:33Z","receivedAt":"2008-04-16T14:19:33Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"Originally, the submodule workflow enforces 'git init' in the beginning\nwhich copies submodule config info from .gitmodules to $GIT_DIR/config.\nThen all subcommands except 'init' and 'add' fetch submodule info from\n$GIT_DIR/config and .gitmodules can be discarded.\n\nHowever, there may be inconsistence between .git/config and .gitmodules\nwhen always using 'git init' at first. If upstream .gitmodules changes,\nit is not easy to sync the changes to $GIT_DIR/config.\n\nRunning 'git init' again may not help much in this case.  Since .git/config\nhas a whole copy of .gitmodules, the user has no easy way to know which\nentries should follow the upstream changes and which entires shouldn't.\n\nActually, .gitmodules which formly only acted as info hints can and should\nplay a more important and essential role.\n\nAs an analogy to .gitignore and .git/info/excludes which are for colleagues'\nand individual wishes separately, .gitmodules is for common requirements and\n$GIT_DIR/config is for special requirements.\n\nThis patch implements a fall back strategy to satisfy both common and\nspecial requirements as follows.\n\n$GIT_DIR/config only keeps submodule info different from .gitmodules.\nAnd the info from $GIT_DIR/config take higher precedence. The code first\nconsults $GIT_DIR/config and then fall back on in-tree .gitmodules file.\n\nWith this patch, init subcommand becomes not forcefull and less meaningful.\nAnd now it is just a tool to help users copy info to $GIT_DIR/config\n(and may modify it later) only when they need.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh           |    9 ++++-----\n t/t7400-submodule-basic.sh |   29 +++++++++++++++++++++++++++++\n 2 files changed, 33 insertions(+), 5 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex d3ae1e4..2276f6b 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -98,7 +98,8 @@ module_name()\n }\n \n module_url() {\n-\tgit config submodule.$1.url\n+\tgit config submodule.$1.url ||\n+\tGIT_CONFIG=.gitmodules git config submodule.$1.url\n }\n \n module_info() {\n@@ -256,12 +257,10 @@ cmd_init()\n \twhile read sha1 path name url\n \tdo\n \t\ttest -n \"$name\" || exit\n-\t\t# Skip already registered paths\n-\t\ttest -z \"$url\" || continue\n-\n-\t\turl=$(GIT_CONFIG=.gitmodules git config submodule.\"$name\".url)\n \t\ttest -z \"$url\" &&\n \t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n+\t\t# Skip already registered paths\n+\t\ttest -z \"$(git config submodule.$name.url)\" || continue\n \n \t\turl=$(absolute_url \"$url\")\n \t\tgit config submodule.\"$name\".url \"$url\" ||\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex e5d59b8..8b35ff8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -174,6 +174,35 @@ test_expect_success 'status should be \"up-to-date\" after update' '\n \tgit-submodule status | grep \"^ $rev1\"\n '\n \n+test_expect_success 'status should be \"modified\" after submodule reset --hard HEAD@{1}' '\n+\tcd init &&\n+\tgit reset --hard HEAD@{1}\n+\trev2=$(git rev-parse HEAD) &&\n+\tcd .. &&\n+\tif test -z \"$rev2\"\n+\tthen\n+\t\techo \"[OOPS] submodule git rev-parse returned nothing\"\n+\t\tfalse\n+\tfi &&\n+\tgit-submodule status | grep \"^+$rev2\"\n+'\n+\n+test_expect_success 'update should checkout rev1 with falling back' '\n+\tgit-config --unset submodule.example.url &&\n+\tGIT_CONFIG=.gitmodules git config submodule.example.url .subrepo &&\n+\tgit-submodule update init &&\n+\thead=$(cd init && git rev-parse HEAD) &&\n+\tif test -z \"$head\"\n+\tthen\n+\t\techo \"[OOPS] submodule git rev-parse returned nothing\"\n+\t\tfalse\n+\telif test \"$head\" != \"$rev1\"\n+\tthen\n+\t\techo \"[OOPS] init did not checkout correct head\"\n+\t\tfalse\n+\tfi\n+'\n+\n test_expect_success 'checkout superproject with subproject already present' '\n \tgit-checkout initial &&\n \tgit-checkout master\n-- \n1.5.5.70.gd68a\n"},{"id":"74554","messageId":"1208355577-8734-5-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-4-git-send-email-pkufranky@gmail.com","subject":"[PATCH 4/7] git-submodule: Extract module_add from cmd_add","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:34Z","receivedAt":"2008-04-16T14:19:34Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"cmd_add will later handle the case adding multiple modules, so extract\nmodule_add to add a single module.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |   67 +++++++++++++++++++++++++++++++----------------------\n 1 files changed, 39 insertions(+), 28 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 2276f6b..f3a1213 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -155,34 +155,7 @@ module_clone()\n #\n # optional branch is stored in global branch variable\n #\n-cmd_add()\n-{\n-\t# parse $args after \"submodule ... add\".\n-\twhile test $# -ne 0\n-\tdo\n-\t\tcase \"$1\" in\n-\t\t-b | --branch)\n-\t\t\tcase \"$2\" in '') usage ;; esac\n-\t\t\tbranch=$2\n-\t\t\tshift\n-\t\t\t;;\n-\t\t-q|--quiet)\n-\t\t\tquiet=1\n-\t\t\t;;\n-\t\t--)\n-\t\t\tshift\n-\t\t\tbreak\n-\t\t\t;;\n-\t\t-*)\n-\t\t\tusage\n-\t\t\t;;\n-\t\t*)\n-\t\t\tbreak\n-\t\t\t;;\n-\t\tesac\n-\t\tshift\n-\tdone\n-\n+module_add() {\n \trepo=$1\n \tpath=$2\n \n@@ -226,6 +199,44 @@ cmd_add()\n }\n \n #\n+# Add a new submodule to the working tree, .gitmodules and the index\n+#\n+# $@ = repo [path]\n+#\n+# optional branch is stored in global branch variable\n+#\n+cmd_add()\n+{\n+\t# parse $args after \"submodule ... add\".\n+\twhile test $# -ne 0\n+\tdo\n+\t\tcase \"$1\" in\n+\t\t-b | --branch)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tbranch=$2\n+\t\t\tshift\n+\t\t\t;;\n+\t\t-q|--quiet)\n+\t\t\tquiet=1\n+\t\t\t;;\n+\t\t--)\n+\t\t\tshift\n+\t\t\tbreak\n+\t\t\t;;\n+\t\t-*)\n+\t\t\tusage\n+\t\t\t;;\n+\t\t*)\n+\t\t\tbreak\n+\t\t\t;;\n+\t\tesac\n+\t\tshift\n+\tdone\n+\n+\tmodule_add \"$1\" \"$2\"\n+}\n+\n+#\n # Register submodules in .git/config\n #\n # $@ = requested paths (default to all)\n-- \n1.5.5.70.gd68a\n"},{"id":"74550","messageId":"1208355577-8734-6-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-5-git-send-email-pkufranky@gmail.com","subject":"[PATCH 5/7] git-submodule: multi-level module definition","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:35Z","receivedAt":"2008-04-16T14:19:35Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"This patch introduces multi-level module definition and '--module-name'\noption to designate submodules by logical names instead of path filters.\nThen the init/update/status/add subcommand is enhanced combined with\nthis option.\n\nThe multi-level module definition in .gitmodules was first suggested by\nLinus and etc. in mails \"Let .git/config specify the url for submodules\"\n(http://article.gmane.org/gmane.comp.version-control.git/48939).\n\nFollowing shows an example of such a .gitmodules which finally comes\nfrom the group notation of 'git remote' which is suggested by Johannes\nSchindelin.\n\n.gitmodules with multiple level of indirection\n------------------------------------------------------\n[submodules]\n\tservice = crawler search\n\tcrawler = util imcrawter\n\tsearch = util imsearch\n[submodule \"util\"]\n\turl = git://xyzzy/util.git\n[submodule \"imsearch\"]\n\tpath = search/imsearch\n\turl = git://xyzzy/imsearch.git\n[submodule \"imcrawler\"]\n\tpath = crawler/imcrawter\n\turl = git://xyzzy/imcrawter.git\n------------------------------------------------------\n\nBy adding the 'submodules' section, we can define multi-level modules\nin an infinite levels of indirection.\n\nThe \"-m|--module-name\" option is introduced with which submodules are\ndesignated by logical names instead of real paths as following shows.\n\nIdentical commands forms with/without \"--module-name\"\n---------------------------------------------------\n$ git submodule XXX util imcrawler              (1)\n$ git submodule XXX -m crawler                  (2)\n$ git submodule XXX util imcrawler imsearch     (3)\n$ git submodule XXX -m service                  (4)\n$ git submodule XXX -m crawler search           (5)\n---------------------------------------------------\n* XXX represents status, update or init, but not add\n* (1) and (2) are identical conditionally (explained below)\n* (3), (4) and (5) are identical conditionally\n\nThere are still minor difference between these two forms.\n\nIn the no \"--module-name\" form, the path parameter may be not the real\nsubmodule path, and it just acts as the filter for real submodule paths.\nWhile in the \"--module-name\" form, the name parameter must be the logical\nname, and the real paths corresponding to the logical name may be neither\na submodule path nor even existent.\n\nThis patch handles such a path for different subcommands as follows.\n\n - status: Output 0{40} as the sha1. Doing this can remind the user to\n   add the path as submodule or delete the path from .gitmodules.\n - update: Skip that path and issue a \"Not a submodule\" warning\n - init: Also init for that path\n\nSo in the example above, commands (1) and (2) are identical only when\nutil and imcrawler are already submodules.\n\nThe add subcommand is also enhanced.\n\nThe former workflow to add submodules is adding one by one with\n\"git submodule add url path\" which then modifies .gitmodules. However,\nsometimes it is more convenient to work in the reverse way: edit\n.gitmodules first and then add submodules in batch.\n\nNow \"git submodule add --module-name modulename\" can help us to do that.\nIt will find all submodules corresponding to the logical name and add them\nin batch by using the paths and urls from .gitmodules. Of course, it will\nskip the paths which have already been submodules.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |   86 ++++++++++++++++++++++++++++++++++++++++++++++++++---\n 1 files changed, 81 insertions(+), 5 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex f3a1213..87d84fa 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -4,7 +4,7 @@\n #\n # Copyright (c) 2007 Lars Hjemli\n \n-USAGE=\"[--quiet] [--cached] \\\n+USAGE=\"[--quiet] [--cached] [--module-name] \\\n [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] \\\n [--] [<path>...]\"\n OPTIONS_SPEC=\n@@ -15,6 +15,7 @@ command=\n branch=\n quiet=\n cached=\n+use_module_name=\n \n #\n # print stuff on stdout unless -q was specified\n@@ -97,12 +98,23 @@ module_name()\n        echo \"$name\"\n }\n \n+module_path() {\n+\tgit config submodule.$1.path ||\n+\tGIT_CONFIG=.gitmodules git config submodule.$1.path ||\n+\techo \"$1\"\n+}\n+\n module_url() {\n \tgit config submodule.$1.url ||\n \tGIT_CONFIG=.gitmodules git config submodule.$1.url\n }\n \n module_info() {\n+\tif test -n \"$use_module_name\"\n+\tthen\n+\t\tmodule_info_by_name \"$@\"\n+\t\treturn\n+\tfi\n \tgit ls-files --stage -- \"$@\" | grep -e '^160000 ' |\n \twhile read mode sha1 stage path\n \tdo\n@@ -118,6 +130,50 @@ module_info() {\n }\n \n #\n+# List all submodule info line by line by given names as follows\n+# sha1<tab>path<tab>name<tab>url\n+#\n+# Here we assume that module names and paths don't contain space\n+# characters\n+#\n+# $@ = module names\n+# When names is not given, list all module info\n+#\n+module_info_by_name() {\n+\tif test $# = 0\n+\tthen\n+\t\tnames=$(\n+\t\t{\n+\t\t\tgit config --get-regexp 'submodule.*.url'\n+\t\t\tgit config -f .gitmodules --get-regexp 'submodule.*.url'\n+\t\t} | sed 's/submodule.\\(.*\\).url .*$/\\1/' 2>/dev/null\n+\t\t)\n+\telse\n+\t\tnames=$(module_children_names \"$@\")\n+\tfi\n+\tfor name in $names\n+\tdo\n+\t\turl=$(module_url \"$name\") || continue\n+\t\tpath=$(module_path \"$name\")\n+\t\tsha1=$(git ls-files --stage \"$path\" |\n+\t\t\tgrep \"$path$\" | grep '^160000' | awk '{print $2}')\n+\t\ttest -z \"$sha1\" && sha1=0000000000000000000000000000000000000000\n+\t\techo \"$sha1\t$path\t$name\t$url\"\n+\tdone\n+}\n+\n+module_children_names() {\n+\tfor name\n+\tdo\n+\t\techo \"$name\"\n+\t\tmodule_children_names $(\n+\t\t\tgit config \"submodules.$name\"\n+\t\t\tgit config -f .gitmodules \"submodules.$name\"\n+\t\t)\n+\tdone | sort -u\n+}\n+\n+#\n # Clone a submodule\n #\n # Prior to calling, cmd_update checks that a possibly existing\n@@ -233,7 +289,17 @@ cmd_add()\n \t\tshift\n \tdone\n \n-\tmodule_add \"$1\" \"$2\"\n+\tif test -n \"$use_module_name\"\n+\tthen\n+\t\tmodule_info \"$@\" |\n+\t\twhile read sha1 path name url\n+\t\tdo\n+\t\t\tmodule_add \"$url\" \"$path\"\n+\t\tdone\n+\telse\n+\t\tmodule_add \"$1\" \"$2\"\n+\tfi\n+\n }\n \n #\n@@ -313,7 +379,11 @@ cmd_update()\n \twhile read sha1 path name url\n \tdo\n \t\ttest -n \"$name\" || exit\n-\t\tif test -z \"$url\"\n+\t\tif test $sha1 = 0000000000000000000000000000000000000000\n+\t\tthen\n+\t\t\tsay \"Not a submodule: $name @ $path\"\n+\t\t\tcontinue\n+\t\telif test -z \"$url\"\n \t\tthen\n \t\t\t# Only mention uninitialized submodules when its\n \t\t\t# path have been specified\n@@ -559,12 +629,15 @@ cmd_status()\n \t\tesac\n \t\tshift\n \tdone\n-\n \tmodule_info \"$@\" |\n \twhile read sha1 path name url\n \tdo\n \t\ttest -n \"$name\" || exit\n-\t\tif test -z \"$url\" || ! test -d \"$path\"/.git\n+\t\tif test $sha1 = 0000000000000000000000000000000000000000\n+\t\tthen\n+\t\t\tsay \"*$sha1 $path\"\n+\t\t\tcontinue\n+\t\telif test -z \"$url\" || ! test -d \"$path\"/.git\n \t\tthen\n \t\t\tsay \"-$sha1 $path\"\n \t\t\tcontinue;\n@@ -610,6 +683,9 @@ do\n \t--cached)\n \t\tcached=\"$1\"\n \t\t;;\n+\t-m|--module-name)\n+\t\tuse_module_name=1\n+\t\t;;\n \t--)\n \t\tbreak\n \t\t;;\n-- \n1.5.5.70.gd68a\n"},{"id":"74548","messageId":"1208355577-8734-7-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-6-git-send-email-pkufranky@gmail.com","subject":"[PATCH 6/7] git-submodule: \"update --force\" to enforce cloning non-submodule","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:36Z","receivedAt":"2008-04-16T14:19:36Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"If the update subcommand combines with --force, instead of\nissuing a \"Not a submodule\" warning for non-submodules, non-submodules\n(i.e. modules existing in .gitmodules or $GIT_DIR/config but not added\nto the super module) will also be cloned and the master branch will be\nchecked out.\n\nHowever, if a non-submodule has already been cloned before, the update\nwill be rejected since we don't know what the update means.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |   13 ++++++++++++-\n 1 files changed, 12 insertions(+), 1 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 87d84fa..ed6f698 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -361,6 +361,9 @@ cmd_update()\n \t\t-q|--quiet)\n \t\t\tquiet=1\n \t\t\t;;\n+\t\t-f | --force)\n+\t\t\tforce=\"$1\"\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -381,7 +384,8 @@ cmd_update()\n \t\ttest -n \"$name\" || exit\n \t\tif test $sha1 = 0000000000000000000000000000000000000000\n \t\tthen\n-\t\t\tsay \"Not a submodule: $name @ $path\"\n+\t\t\ttest -z \"$force\" &&\n+\t\t\tsay \"Not a submodule: $name @ $path\" &&\n \t\t\tcontinue\n \t\telif test -z \"$url\"\n \t\tthen\n@@ -395,8 +399,15 @@ cmd_update()\n \t\tif ! test -d \"$path\"/.git\n \t\tthen\n \t\t\tmodule_clone \"$path\" \"$url\" || exit\n+\t\t\ttest \"$sha1\" = 0000000000000000000000000000000000000000 &&\n+\t\t\t(unset GIT_DIR; cd \"$path\" && git checkout -q master) &&\n+\t\t\tsay \"non-submodule cloned and master checked out: $name @ $path\" &&\n+\t\t\tcontinue\n \t\t\tsubsha1=\n \t\telse\n+\t\t\ttest \"$sha1\" = 0000000000000000000000000000000000000000 &&\n+\t\t\tsay \"non-submodule already cloned: $name @ $path\" &&\n+\t\t\tcontinue\n \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n \t\t\tdie \"Unable to find current revision in submodule path '$path'\"\n-- \n1.5.5.70.gd68a\n"},{"id":"74553","messageId":"1208355577-8734-8-git-send-email-pkufranky@gmail.com","threadId":"13138","inReplyTo":"1208355577-8734-7-git-send-email-pkufranky@gmail.com","subject":"[PATCH 7/7] git-submodule: Don't die when command fails for one submodule","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-16T14:19:37Z","receivedAt":"2008-04-16T14:19:37Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"When handling multiple modules, init/update/status/add subcommand will\nexit when it fails for one submodule. This patch makes the subcommand\ncontinue bypassing the failure and keep right exit status.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh |   87 +++++++++++++++++++++++++++++++++++++++---------------\n 1 files changed, 63 insertions(+), 24 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex ed6f698..0ecc4ff 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -193,15 +193,19 @@ module_clone()\n \t# succeed but the rmdir will fail. We might want to fix this.\n \tif test -d \"$path\"\n \tthen\n-\t\trmdir \"$path\" 2>/dev/null ||\n-\t\tdie \"Directory '$path' exist, but is neither empty nor a git repository\"\n+\t\t! rmdir \"$path\" 2>/dev/null &&\n+\t\tsay \"Directory '$path' exist, but is neither empty nor a git repository\" &&\n+\t\treturn 1\n \tfi\n \n \ttest -e \"$path\" &&\n-\tdie \"A file already exist at path '$path'\"\n+\tsay \"A file already exist at path '$path'\" &&\n+\treturn 1\n \n-\tgit-clone -n \"$url\" \"$path\" ||\n-\tdie \"Clone of '$url' into submodule path '$path' failed\"\n+\t! git-clone -n \"$url\" \"$path\" &&\n+\tsay \"Clone of '$url' into submodule path '$path' failed\" &&\n+\treturn 1\n+\t:\n }\n \n #\n@@ -227,7 +231,8 @@ module_add() {\n \tfi\n \n \tgit ls-files --error-unmatch \"$path\" > /dev/null 2>&1 &&\n-\tdie \"'$path' already exists in the index\"\n+\tsay \"'$path' already exists in the index\" &&\n+\treturn 1\n \n \t# perhaps the path exists and is already a git repo, else clone it\n \tif test -e \"$path\"\n@@ -237,21 +242,26 @@ module_add() {\n \t\tthen\n \t\t\techo \"Adding existing repo at '$path' to the index\"\n \t\telse\n-\t\t\tdie \"'$path' already exists and is not a valid git repo\"\n+\t\t\tsay \"'$path' already exists and is not a valid git repo\"\n+\t\t\treturn 1\n \t\tfi\n \telse\n-\t\tmodule_clone \"$path\" \"$repo\" || exit\n-\t\t(unset GIT_DIR; cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n-\t\tdie \"Unable to checkout submodule '$path'\"\n+\t\tmodule_clone \"$path\" \"$repo\" || return 1\n+\t\t! (unset GIT_DIR; cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) &&\n+\t\tsay \"Unable to checkout submodule '$path'\" &&\n+\t\treturn 1\n \tfi\n \n-\tgit add \"$path\" ||\n-\tdie \"Failed to add submodule '$path'\"\n+\t! git add \"$path\" &&\n+\tsay \"Failed to add submodule '$path'\" &&\n+\treturn 1\n \n \tGIT_CONFIG=.gitmodules git config submodule.\"$path\".path \"$path\" &&\n \tGIT_CONFIG=.gitmodules git config submodule.\"$path\".url \"$repo\" &&\n-\tgit add .gitmodules ||\n-\tdie \"Failed to register submodule '$path'\"\n+\t! git add .gitmodules &&\n+\tsay \"Failed to register submodule '$path'\" &&\n+\treturn 1\n+\t:\n }\n \n #\n@@ -292,14 +302,17 @@ cmd_add()\n \tif test -n \"$use_module_name\"\n \tthen\n \t\tmodule_info \"$@\" |\n+\t\t{\n+\t\texit_status=0\n \t\twhile read sha1 path name url\n \t\tdo\n-\t\t\tmodule_add \"$url\" \"$path\"\n+\t\t\tmodule_add \"$url\" \"$path\" || exit_status=1\n \t\tdone\n+\t\ttest $exit_status = 0\n+\t\t}\n \telse\n \t\tmodule_add \"$1\" \"$2\"\n \tfi\n-\n }\n \n #\n@@ -331,20 +344,30 @@ cmd_init()\n \tdone\n \n \tmodule_info \"$@\" |\n+\t{\n+\texit_status=0\n \twhile read sha1 path name url\n \tdo\n-\t\ttest -n \"$name\" || exit\n+\t\ttest -z \"$name\" && exit_status=1 && continue\n \t\ttest -z \"$url\" &&\n-\t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n+\t\tsay \"No url found for submodule path '$path' in .gitmodules\" &&\n+\t\texit_status=1 &&\n+\t\tcontinue\n \t\t# Skip already registered paths\n \t\ttest -z \"$(git config submodule.$name.url)\" || continue\n \n \t\turl=$(absolute_url \"$url\")\n \t\tgit config submodule.\"$name\".url \"$url\" ||\n-\t\tdie \"Failed to register url for submodule path '$path'\"\n+\t\t{\n+\t\tsay \"Failed to register url for submodule path '$path'\"\n+\t\texit_status=1\n+\t\tcontinue\n+\t\t}\n \n \t\tsay \"Submodule '$name' ($url) registered for path '$path'\"\n \tdone\n+\texit $exit_status\n+\t}\n }\n \n #\n@@ -379,9 +402,11 @@ cmd_update()\n \tdone\n \n \tmodule_info \"$@\" |\n+\t{\n+\texit_status=0\n \twhile read sha1 path name url\n \tdo\n-\t\ttest -n \"$name\" || exit\n+\t\ttest -z \"$name\" && exit_status=1 && continue\n \t\tif test $sha1 = 0000000000000000000000000000000000000000\n \t\tthen\n \t\t\ttest -z \"$force\" &&\n@@ -398,7 +423,7 @@ cmd_update()\n \n \t\tif ! test -d \"$path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$path\" \"$url\" || exit\n+\t\t\t! module_clone \"$path\" \"$url\" && exit_status=1 && continue\n \t\t\ttest \"$sha1\" = 0000000000000000000000000000000000000000 &&\n \t\t\t(unset GIT_DIR; cd \"$path\" && git checkout -q master) &&\n \t\t\tsay \"non-submodule cloned and master checked out: $name @ $path\" &&\n@@ -410,18 +435,28 @@ cmd_update()\n \t\t\tcontinue\n \t\t\tsubsha1=$(unset GIT_DIR; cd \"$path\" &&\n \t\t\t\tgit rev-parse --verify HEAD) ||\n-\t\t\tdie \"Unable to find current revision in submodule path '$path'\"\n+\t\t\t{\n+\t\t\t\tsay \"Unable to find current revision in submodule path '$path'\"\n+\t\t\t\texit_status=1\n+\t\t\t\tcontinue\n+\t\t\t}\n \t\tfi\n \n \t\tif test \"$subsha1\" != \"$sha1\"\n \t\tthen\n \t\t\t(unset GIT_DIR; cd \"$path\" && git-fetch &&\n \t\t\t\tgit-checkout -q \"$sha1\") ||\n-\t\t\tdie \"Unable to checkout '$sha1' in submodule path '$path'\"\n+\t\t\t{\n+\t\t\t\tsay \"Unable to checkout '$sha1' in submodule path '$path'\"\n+\t\t\t\texit_status=1\n+\t\t\t\tcontinue\n+\t\t\t}\n \n \t\t\tsay \"Submodule path '$path': checked out '$sha1'\"\n \t\tfi\n \tdone\n+\texit $exit_status\n+\t}\n }\n \n set_name_rev () {\n@@ -641,9 +676,11 @@ cmd_status()\n \t\tshift\n \tdone\n \tmodule_info \"$@\" |\n+\t{\n+\texit_status=0\n \twhile read sha1 path name url\n \tdo\n-\t\ttest -n \"$name\" || exit\n+\t\ttest -z \"$name\" && exit_status=1 && continue\n \t\tif test $sha1 = 0000000000000000000000000000000000000000\n \t\tthen\n \t\t\tsay \"*$sha1 $path\"\n@@ -666,6 +703,8 @@ cmd_status()\n \t\t\tsay \"+$sha1 $path$revname\"\n \t\tfi\n \tdone\n+\texit $exit_status\n+\t}\n }\n \n # This loop parses the command line arguments to find the\n-- \n1.5.5.70.gd68a\n"},{"id":"74909","messageId":"7v3ape5sip.fsf@gitster.siamese.dyndns.org","threadId":"13138","inReplyTo":"1208355577-8734-3-git-send-email-pkufranky@gmail.com","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-04-22T06:10:38Z","receivedAt":"2008-04-22T06:10:38Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ping Yin <pkufranky@gmail.com> writes:\n\n> Extract function absolute_url to remove code redundance and inconsistence in\n> cmd_init and cmd_add when resolving relative url/path to absolute one.\n>\n> Also move resolving absolute url logic from cmd_add to module_clone which\n> results in a litte behaviour change: cmd_update originally doesn't\n> resolve absolute url but now it will.\n\nHmmm.  Somehow I find this unreadable and hard to parse.\n\n> This behaviour change breaks t7400 which uses relative url './.subrepo'.\n> However, this test originally doesn't mean to test relative url with './',\n> so fix the url as '.subrepo'.\n\nIsn't \".subrepo\" a relative URL that says \"subdirectory of the current\none, whose name is .subrepo\", exactly the same way as \"./.subrepo\" is?\nShouldn't they behave the same?\n\nIf the test found they do not behave the same, perhaps the new code is\nbroken in some way and isn't \"fixing\" the test simply hiding a bug?\n\nI dunno...\n\n> +# Resolve relative url/path to absolute one\n> +absolute_url () {\n> +\tcase \"$1\" in\n> +\t./*|../*)\n> +\t\t# dereference source url relative to parent's url\n> +\t\turl=\"$(resolve_relative_url $1)\" ;;\n> +\t*)\n> +\t\t# Turn the source into an absolute path if it is local\n> +\t\turl=$(get_repo_base \"$1\") ||\n> +\t\turl=$1\n> +\t\t;;\n> +\tesac\n> +\techo \"$url\"\n> +}\n> +\n>  #\n>  # Map submodule path to submodule name\n>  #\n> @@ -112,7 +127,7 @@ module_info() {\n>  module_clone()\n>  {\n>  \tpath=$1\n> -\turl=$2\n> +\turl=$(absolute_url \"$2\")\n>  \n>  \t# If there already is a directory at the submodule path,\n>  \t# expect it to be empty (since that is the default checkout\n\nWhy does this call-site matter?  The URL is given to \"git-clone\" which I\nthink does handle the relative URL just fine???\n\n> @@ -195,21 +210,7 @@ cmd_add()\n>  \t\t\tdie \"'$path' already exists and is not a valid git repo\"\n>  \t\tfi\n>  \telse\n> -\t\tcase \"$repo\" in\n> -\t\t./*|../*)\n> -\t\t\t# dereference source url relative to parent's url\n> -\t\t\trealrepo=\"$(resolve_relative_url $repo)\" ;;\n> -\t\t*)\n> -\t\t\t# Turn the source into an absolute path if\n> -\t\t\t# it is local\n> -\t\t\tif base=$(get_repo_base \"$repo\"); then\n> -\t\t\t\trepo=\"$base\"\n> -\t\t\tfi\n> -\t\t\trealrepo=$repo\n> -\t\t\t;;\n> -\t\tesac\n> -\n> -\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n> +\t\tmodule_clone \"$path\" \"$repo\" || exit\n>  \t\t(unset GIT_DIR; cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n>  \t\tdie \"Unable to checkout submodule '$path'\"\n>  \tfi\n\nOk.\n\n> @@ -262,13 +263,7 @@ cmd_init()\n>  \t\ttest -z \"$url\" &&\n>  \t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n>  \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\")\"\n> -\t\t\t;;\n> -\t\tesac\n> -\n> +\t\turl=$(absolute_url \"$url\")\n>  \t\tgit config submodule.\"$name\".url \"$url\" ||\n>  \t\tdie \"Failed to register url for submodule path '$path'\"\n\nOk.\n"},{"id":"74916","messageId":"46dff0320804212350t647492b2o649ddc40cfe43d6@mail.gmail.com","threadId":"13138","inReplyTo":"7v3ape5sip.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T06:50:22Z","receivedAt":"2008-04-22T06:50:22Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, Apr 22, 2008 at 2:10 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ping Yin <pkufranky@gmail.com> writes:\n>  > This behaviour change breaks t7400 which uses relative url './.subrepo'.\n>  > However, this test originally doesn't mean to test relative url with './',\n>  > so fix the url as '.subrepo'.\n>\n>  Isn't \".subrepo\" a relative URL that says \"subdirectory of the current\n>  one, whose name is .subrepo\", exactly the same way as \"./.subrepo\" is?\n>  Shouldn't they behave the same?\n>\n>  If the test found they do not behave the same, perhaps the new code is\n>  broken in some way and isn't \"fixing\" the test simply hiding a bug?\n>\n\nI just want to unify the behaviour of handling relative url.\n\n'git submodule add'  treats './foo' and 'foo' as different urls. The\n1st one is relative to remote.origin.url, while the 2nd one is\nrelative the current directory. I think this kind of behaviour is\nbetter for submodules, so i unify the handling of relative urls as\nthis.\n\nWith this kind of behaviour, i can set 'submodule.foo.url=./foo' in\n.gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i\nhave not to change submodule.foo.url if the super project and\nsubmodule foo are always located on the same central host.\n\n>\n>  > +# Resolve relative url/path to absolute one\n>  > +absolute_url () {\n>  > +     case \"$1\" in\n>  > +     ./*|../*)\n>  > +             # dereference source url relative to parent's url\n>  > +             url=\"$(resolve_relative_url $1)\" ;;\n>  > +     *)\n>  > +             # Turn the source into an absolute path if it is local\n>  > +             url=$(get_repo_base \"$1\") ||\n>  > +             url=$1\n>  > +             ;;\n>  > +     esac\n>  > +     echo \"$url\"\n>  > +}\n>  > +\n>  >  #\n>  >  # Map submodule path to submodule name\n>  >  #\n>  > @@ -112,7 +127,7 @@ module_info() {\n>  >  module_clone()\n>  >  {\n>  >       path=$1\n>  > -     url=$2\n>  > +     url=$(absolute_url \"$2\")\n>  >\n>  >       # If there already is a directory at the submodule path,\n>  >       # expect it to be empty (since that is the default checkout\n>\n>  Why does this call-site matter?  The URL is given to \"git-clone\" which I\n>  think does handle the relative URL just fine???\n>\n\nAs said above.\n\n\n\n-- \nPing Yin\n"},{"id":"74917","messageId":"46dff0320804220000l1872ebf1vde269953d89c755f@mail.gmail.com","threadId":"13138","inReplyTo":"7v3ape5sip.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T07:00:21Z","receivedAt":"2008-04-22T07:00:21Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, Apr 22, 2008 at 2:10 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Ping Yin <pkufranky@gmail.com> writes:\n>\n>  > Extract function absolute_url to remove code redundance and inconsistence in\n>  > cmd_init and cmd_add when resolving relative url/path to absolute one.\n>  >\n>  > Also move resolving absolute url logic from cmd_add to module_clone which\n>  > results in a litte behaviour change: cmd_update originally doesn't\n>  > resolve absolute url but now it will.\n>\n>  Hmmm.  Somehow I find this unreadable and hard to parse.\n>\n>\n>  > This behaviour change breaks t7400 which uses relative url './.subrepo'.\n>  > However, this test originally doesn't mean to test relative url with './',\n>  > so fix the url as '.subrepo'.\n>\n>  Isn't \".subrepo\" a relative URL that says \"subdirectory of the current\n>  one, whose name is .subrepo\", exactly the same way as \"./.subrepo\" is?\n>  Shouldn't they behave the same?\n>\n>  If the test found they do not behave the same, perhaps the new code is\n>  broken in some way and isn't \"fixing\" the test simply hiding a bug?\n>\n>  I dunno...\n>\n>\n>  > +# Resolve relative url/path to absolute one\n>  > +absolute_url () {\n>  > +     case \"$1\" in\n>  > +     ./*|../*)\n>  > +             # dereference source url relative to parent's url\n>  > +             url=\"$(resolve_relative_url $1)\" ;;\n>  > +     *)\n>  > +             # Turn the source into an absolute path if it is local\n>  > +             url=$(get_repo_base \"$1\") ||\n>  > +             url=$1\n>  > +             ;;\n>  > +     esac\n>  > +     echo \"$url\"\n>  > +}\n>  > +\n>  >  #\n>  >  # Map submodule path to submodule name\n>  >  #\n>  > @@ -112,7 +127,7 @@ module_info() {\n>  >  module_clone()\n>  >  {\n>  >       path=$1\n>  > -     url=$2\n>  > +     url=$(absolute_url \"$2\")\n>  >\n>  >       # If there already is a directory at the submodule path,\n>  >       # expect it to be empty (since that is the default checkout\n>\n>  Why does this call-site matter?  The URL is given to \"git-clone\" which I\n>  think does handle the relative URL just fine???\n>\n\n>  Hmmm.  Doesn't \"foo\" generally mean the same thing as \"./foo\" in the sense\n>  both are relative to the current directory?\n\nFollowing was my answer days ago\n\nThere is a little inconsistence in current logic\n\n1. git submodule add ./foo will expand foo with remote.origin.url and\n    init an entry in .gitmodules as \"submodule.foo.url=$remoteoriginurl/foo\"\n2. git submodule update will not expand ./foo if  there is an entry\n    \"submodule.foo.url=./foo\"  in $GIT_DIR/config\n\nI tend to add the url as is when \"git submodule add\", and then expand\nthe url when running \"git submodule update\". So this will result that\nthe second case expands './foo' as \"$remoteoriginurl/foo\" instead of\n\"foo\".\n\nAnd this is the reason i expand './foo' in module_clone.\n\n-- \nPing Yin\n"},{"id":"74923","messageId":"7v3ape2ufs.fsf@gitster.siamese.dyndns.org","threadId":"13138","inReplyTo":"46dff0320804212350t647492b2o649ddc40cfe43d6@mail.gmail.com","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-04-22T07:57:27Z","receivedAt":"2008-04-22T07:57:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Ping Yin\" <pkufranky@gmail.com> writes:\n\n> I just want to unify the behaviour of handling relative url.\n>\n> 'git submodule add'  treats './foo' and 'foo' as different urls. The\n> 1st one is relative to remote.origin.url, while the 2nd one is\n> relative the current directory. I think this kind of behaviour is\n> better for submodules, so i unify the handling of relative urls as\n> this.\n>\n> With this kind of behaviour, i can set 'submodule.foo.url=./foo' in\n> .gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i\n> have not to change submodule.foo.url if the super project and\n> submodule foo are always located on the same central host.\n\nPlease have that kind of justification in the proposed commit log message.\nWhen these changes are made into history, people cannot ask you questions\nlike I did and expect the history to produce such answer on demand ;-)\n"},{"id":"74929","messageId":"46dff0320804220209n590a0684x876270c7b1c0c2d@mail.gmail.com","threadId":"13138","inReplyTo":"7v3ape2ufs.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T09:09:10Z","receivedAt":"2008-04-22T09:09:10Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, Apr 22, 2008 at 3:57 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Ping Yin\" <pkufranky@gmail.com> writes:\n>\n>\n> > I just want to unify the behaviour of handling relative url.\n>  >\n>  > 'git submodule add'  treats './foo' and 'foo' as different urls. The\n>  > 1st one is relative to remote.origin.url, while the 2nd one is\n>  > relative the current directory. I think this kind of behaviour is\n>  > better for submodules, so i unify the handling of relative urls as\n>  > this.\n>  >\n>  > With this kind of behaviour, i can set 'submodule.foo.url=./foo' in\n>  > .gitmodules or $GIT_DIR/config. And when remote.origin.url changes, i\n>  > have not to change submodule.foo.url if the super project and\n>  > submodule foo are always located on the same central host.\n>\n>  Please have that kind of justification in the proposed commit log message.\n>  When these changes are made into history, people cannot ask you questions\n>  like I did and expect the history to produce such answer on demand ;-)\n>\n\nOK, i'll resend this patch tonight.\n\n-- \nPing Yin\n"},{"id":"74970","messageId":"46dff0320804220738u760a05f7q4ec9cbf144d78480@mail.gmail.com","threadId":"13138","inReplyTo":"46dff0320804220209n590a0684x876270c7b1c0c2d@mail.gmail.com","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T14:38:46Z","receivedAt":"2008-04-22T14:38:46Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":">  >  Please have that kind of justification in the proposed commit log message.\n>  >  When these changes are made into history, people cannot ask you questions\n>  >  like I did and expect the history to produce such answer on demand ;-)\n>  >\n>\n>  OK, i'll resend this patch tonight.\n\nSee attached patch\n\n\n-- \nPing Yin\n\n\nFrom f89b08edaa44f89a534dcb4fc17344ea49c5dadb Mon Sep 17 00:00:00 2001\nFrom: Ping Yin <pkufranky@gmail.com>\nDate: Thu, 13 Mar 2008 00:09:57 +0800\nSubject: [PATCH 2/7] git-submodule: Fix inconsistent handling of relative urls with './' prefix\n\nThere is a little inconsistence in current handling of relative url\nwith \"./\"\n\n- \"git submodule add ./foo\" will clone the submodule with url\n  \"${remote.origin.url}/foo\" and init an entry 'submodule.foo.url=./foo\"\n  in .gitmodules\n\n- \"git submodule init\" will init an entry in $GIT_DIR/config as\n  \"submodule.foo.url=${remote.origin.url}/foo\"\n\n- However, if there is an entry \"submodule.foo.url=./foo\" in\n  $GIT_DIR/config, \"git submodule update\" will not expand\n  \"./foo\" with remote.origin.url\n\nThis patch unifies the behaviour of handling relative urls with './'\nprefix. Now \"git submodule init\" copies urls from .gitmodules to\n$GIT_DIR/config as is without expanding. And the url expanding happens\nonly at runtime, say when \"git submodule add\" or \"git submodule update\".\n\nabsolute_url is extracted to remove code redundance and fix inconsistence\nin cmd_init and cmd_add when resolving relative url/path to absolute one.\n\nAlso move resolving absolute url logic from cmd_add to module_clone which\nresults in the expected behaviour change: cmd_update will resolve url\n'./foo' in $GIT_DIR/config as \"${remote.origin.url}/foo\" instead of\n\"$(pwd)/foo\".\n\nThis behaviour change breaks t7400 which uses relative url './.subrepo'.\nHowever, this test originally doesn't mean to test relative url with './'\nprefix, so fix the url as '.subrepo'.\n\nSigned-off-by: Ping Yin <pkufranky@gmail.com>\n---\n git-submodule.sh           |   41 ++++++++++++++++++-----------------------\n t/t7400-submodule-basic.sh |    2 +-\n 2 files changed, 19 insertions(+), 24 deletions(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex e71e1f0..198ea44 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -65,6 +65,21 @@ resolve_relative_url ()\n \techo \"$remoteurl/$url\"\n }\n \n+# Resolve relative url/path to absolute one\n+absolute_url () {\n+\tcase \"$1\" in\n+\t./*|../*)\n+\t\t# dereference source url relative to parent's url\n+\t\turl=\"$(resolve_relative_url $1)\" ;;\n+\t*)\n+\t\t# Turn the source into an absolute path if it is local\n+\t\turl=$(get_repo_base \"$1\") ||\n+\t\turl=$1\n+\t\t;;\n+\tesac\n+\techo \"$url\"\n+}\n+\n #\n # Map submodule path to submodule name\n #\n@@ -112,7 +127,7 @@ module_info() {\n module_clone()\n {\n \tpath=$1\n-\turl=$2\n+\turl=$(absolute_url \"$2\")\n \n \t# If there already is a directory at the submodule path,\n \t# expect it to be empty (since that is the default checkout\n@@ -195,21 +210,7 @@ cmd_add()\n \t\t\tdie \"'$path' already exists and is not a valid git repo\"\n \t\tfi\n \telse\n-\t\tcase \"$repo\" in\n-\t\t./*|../*)\n-\t\t\t# dereference source url relative to parent's url\n-\t\t\trealrepo=\"$(resolve_relative_url $repo)\" ;;\n-\t\t*)\n-\t\t\t# Turn the source into an absolute path if\n-\t\t\t# it is local\n-\t\t\tif base=$(get_repo_base \"$repo\"); then\n-\t\t\t\trepo=\"$base\"\n-\t\t\tfi\n-\t\t\trealrepo=$repo\n-\t\t\t;;\n-\t\tesac\n-\n-\t\tmodule_clone \"$path\" \"$realrepo\" || exit\n+\t\tmodule_clone \"$path\" \"$repo\" || exit\n \t\t(unset GIT_DIR; cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n \t\tdie \"Unable to checkout submodule '$path'\"\n \tfi\n@@ -262,13 +263,7 @@ cmd_init()\n \t\ttest -z \"$url\" &&\n \t\tdie \"No url found for submodule path '$path' in .gitmodules\"\n \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\")\"\n-\t\t\t;;\n-\t\tesac\n-\n+\t\turl=$(absolute_url \"$url\")\n \t\tgit config submodule.\"$name\".url \"$url\" ||\n \t\tdie \"Failed to register url for submodule path '$path'\"\n \ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 2ef85a8..e5d59b8 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' '\n \tthen\n \t\techo \"[OOPS] init succeeded but submodule url is wrong\"\n \t\tfalse\n-\telif ! git config submodule.example.url ./.subrepo\n+\telif ! git config submodule.example.url .subrepo\n \tthen\n \t\techo \"[OOPS] init succeeded but update of url failed\"\n \t\tfalse\n-- \n1.5.5.70.gd68a\n\n"},{"id":"74971","messageId":"46dff0320804220741p4d3f3080w493fb96dc4983a1c@mail.gmail.com","threadId":"13138","inReplyTo":"46dff0320804220738u760a05f7q4ec9cbf144d78480@mail.gmail.com","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T14:41:35Z","receivedAt":"2008-04-22T14:41:35Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, Apr 22, 2008 at 10:38 PM, Ping Yin <pkufranky@gmail.com> wrote:\n> >  >  Please have that kind of justification in the proposed commit log message.\n>  >  >  When these changes are made into history, people cannot ask you questions\n>  >  >  like I did and expect the history to produce such answer on demand ;-)\n>  >  >\n>  >\n>  >  OK, i'll resend this patch tonight.\n>\n>  See attached patch\n\nOnly the commit message changes.\n\n\ngit-submodule: Fix inconsistent handling of relative urls with './' prefix\n\nThere is a little inconsistence in current handling of relative url\nwith \"./\"\n\n- \"git submodule add ./foo\" will clone the submodule with url\n  \"${remote.origin.url}/foo\" and init an entry 'submodule.foo.url=./foo\"\n  in .gitmodules\n\n- \"git submodule init\" will init an entry in $GIT_DIR/config as\n  \"submodule.foo.url=${remote.origin.url}/foo\"\n\n- However, if there is an entry \"submodule.foo.url=./foo\" in\n  $GIT_DIR/config, \"git submodule update\" will not expand\n  \"./foo\" with remote.origin.url\n\nThis patch unifies the behaviour of handling relative urls with './'\nprefix. Now \"git submodule init\" copies urls from .gitmodules to\n$GIT_DIR/config as is without expanding. And the url expanding happens\nonly at runtime, say when \"git submodule add\" or \"git submodule update\".\n\nabsolute_url is extracted to remove code redundance and fix inconsistence\nin cmd_init and cmd_add when resolving relative url/path to absolute one.\n\nAlso move resolving absolute url logic from cmd_add to module_clone which\nresults in the expected behaviour change: cmd_update will resolve url\n'./foo' in $GIT_DIR/config as \"${remote.origin.url}/foo\" instead of\n\"$(pwd)/foo\".\n\nThis behaviour change breaks t7400 which uses relative url './.subrepo'.\nHowever, this test originally doesn't mean to test relative url with './'\nprefix, so fix the url as '.subrepo'.\n\n\n\n-- \nPing Yin\n"},{"id":"74982","messageId":"46dff0320804220954y171df9b6t199f4864a32d4195@mail.gmail.com","threadId":"13138","inReplyTo":"alpine.DEB.1.00.0804221609200.4460@eeepc-johanness","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T16:54:45Z","receivedAt":"2008-04-22T16:54:45Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin\n<Johannes.Schindelin@gmx.de> wrote:\n> Hi Ping,\n>\n>\n>  On Tue, 22 Apr 2008, Ping Yin wrote:\n>\n>  > On Tue, Apr 22, 2008 at 10:38 PM, Ping Yin <pkufranky@gmail.com> wrote:\n>  > > >  >  Please have that kind of justification in the proposed commit log message.\n>  > >  >  >  When these changes are made into history, people cannot ask you questions\n>  > >  >  >  like I did and expect the history to produce such answer on demand ;-)\n>  > >  >  >\n>  > >  >\n>  > >  >  OK, i'll resend this patch tonight.\n>  > >\n>  > >  See attached patch\n>  >\n>  > Only the commit message changes.\n>  >\n>  > [... only the commit message ...]\n>\n>  Do you realize how much work you make Junio do?  It would be definitely\n>  better if you tried to relieve him of as much burden as you can.\n\nI'm sorry about that. It's just because that i don't have a mail\nclient at hand. I use gmail which will wrap lines. And if i use\ngit-sendmail, i can't send this message as a reply to previous\nmessages.\n\nSo, any better way?\n\n-- \nPing Yin\n"},{"id":"74988","messageId":"m37ieprexc.fsf@localhost.localdomain","threadId":"13138","inReplyTo":"46dff0320804220954y171df9b6t199f4864a32d4195@mail.gmail.com","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2008-04-22T17:13:39Z","receivedAt":"2008-04-22T17:13:39Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"\"Ping Yin\" <pkufranky@gmail.com> writes:\n\n> On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin\n> <Johannes.Schindelin@gmx.de> wrote:\n>>  On Tue, 22 Apr 2008, Ping Yin wrote:\n[...]\n>>> Only the commit message changes.\n>>>\n>>> [... only the commit message ...]\n>>\n>>  Do you realize how much work you make Junio do?  It would be definitely\n>>  better if you tried to relieve him of as much burden as you can.\n> \n> I'm sorry about that. It's just because that i don't have a mail\n> client at hand. I use gmail which will wrap lines. And if i use\n> git-sendmail, i can't send this message as a reply to previous\n> messages.\n\nErrr, '--in-reply-to' option to git-send-email?\n\nOr find some mail client...\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"},{"id":"74991","messageId":"46dff0320804221020o40684b78i7140af9f56f27756@mail.gmail.com","threadId":"13138","inReplyTo":"m37ieprexc.fsf@localhost.localdomain","subject":"Re: [PATCH 2/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone","fromName":"Ping Yin","fromEmail":"pkufranky@gmail.com","sentAt":"2008-04-22T17:20:18Z","receivedAt":"2008-04-22T17:20:18Z","isPatch":true,"sender":{"key":"pkufranky@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5346?v=4"},"body":"On Wed, Apr 23, 2008 at 1:13 AM, Jakub Narebski <jnareb@gmail.com> wrote:\n> \"Ping Yin\" <pkufranky@gmail.com> writes:\n>\n>  > On Tue, Apr 22, 2008 at 11:10 PM, Johannes Schindelin\n>  > <Johannes.Schindelin@gmx.de> wrote:\n>\n> >>  On Tue, 22 Apr 2008, Ping Yin wrote:\n>  [...]\n>\n> >>> Only the commit message changes.\n>  >>>\n>  >>> [... only the commit message ...]\n>  >>\n>  >>  Do you realize how much work you make Junio do?  It would be definitely\n>  >>  better if you tried to relieve him of as much burden as you can.\n>  >\n>  > I'm sorry about that. It's just because that i don't have a mail\n>  > client at hand. I use gmail which will wrap lines. And if i use\n>  > git-sendmail, i can't send this message as a reply to previous\n>  > messages.\n>\n>  Errr, '--in-reply-to' option to git-send-email?\n>\n3x, i think this makes sense.\n\n\n-- \nPing Yin\n"}]}