{"thread":{"id":"8672","subject":"[PATCH][RESEND] git-submodule: provide easy way of adding new submodules","startedAt":"2007-06-21T09:53:00Z","lastAt":"2007-07-04T05:10:33Z","messageCount":10,"participants":["Sven Verdoolaege","Lars Hjemli","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"45483","messageId":"20070621095300.GA27071MdfPADPa@greensroom.kotnet.org","threadId":"8672","inReplyTo":null,"subject":"[PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-06-21T09:53:00Z","receivedAt":"2007-06-21T09:53:00Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"To make a submodule effectively usable, the path and\na URL where the submodule can be cloned need to be stored\nin .gitmodules.  This subcommand takes care of setting\nthis information after cloning the new submodule.\nOnly the index is updated, so, if needed, the user may still\nchange the URL or switch to a different branch of the submodule\nbefore committing.\n\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\nI didn't get any reaction (negative or positive) to this patch.\nThe only difference with the previous version is that I know\ncheck for the existence of the destination path before calling\nmodule_clone.\n\nskimo\n\n Documentation/git-submodule.txt |    8 ++++\n git-submodule.sh                |   68 +++++++++++++++++++++++++++++++++++---\n 2 files changed, 70 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex f8fb80f..bf9cbf9 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -8,11 +8,19 @@ git-submodule - Initialize, update or inspect submodules\n \n SYNOPSIS\n --------\n+'git-submodule' [--quiet] add <repository> [<path>]\n 'git-submodule' [--quiet] [--cached] [status|init|update] [--] [<path>...]\n \n \n COMMANDS\n --------\n+add::\n+\tAdd the given repository as a submodule at the given path\n+\tto the changeset to be committed next.  In particular, the\n+\trepository is cloned at the specified path, added to the\n+\tchangeset and registered in .gitmodules.   If no path is\n+\tspecified, the path is deduced from the repository specification.\n+\n status::\n \tShow the status of the submodules. This will print the SHA-1 of the\n \tcurrently checked out commit for each submodule, along with the\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 89a3885..3df7121 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -1,13 +1,14 @@\n #!/bin/sh\n #\n-# git-submodules.sh: init, update or list git submodules\n+# git-submodules.sh: add, init, update or list git submodules\n #\n # Copyright (c) 2007 Lars Hjemli\n \n-USAGE='[--quiet] [--cached] [status|init|update] [--] [<path>...]'\n+USAGE='[--quiet] [--cached] [add <repo>|status|init|update] [--] [<path>...]'\n . git-sh-setup\n require_work_tree\n \n+add=\n init=\n update=\n status=\n@@ -25,6 +26,17 @@ say()\n \tfi\n }\n \n+get_repo_base() {\n+\t(\n+\t\tcd \"`/bin/pwd`\" &&\n+\t\tcd \"$1\" || cd \"$1.git\" &&\n+\t\t{\n+\t\t\tcd .git\n+\t\t\tpwd\n+\t\t}\n+\t) 2>/dev/null\n+}\n+\n #\n # Map submodule path to submodule name\n #\n@@ -66,6 +78,44 @@ module_clone()\n }\n \n #\n+# Add a new submodule to the working tree, .gitmodules and the index\n+#\n+# $@ = repo [path]\n+#\n+module_add()\n+{\n+\trepo=$1\n+\tpath=$2\n+\n+\t# Turn the source into an absolute path if\n+\t# it is local\n+\tif base=$(get_repo_base \"$repo\"); then\n+\t\trepo=\"$base\"\n+\tfi\n+\n+\t# Guess path from repo if not specified or strip trailing slashes\n+\tif test -z \"$path\"; then\n+\t\tpath=$(echo \"$repo\" | sed -e 's|/*$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n+\telse\n+\t\tpath=$(echo \"$path\" | sed -e 's|/*$||')\n+\tfi\n+\n+\ttest -e \"$path\" &&\n+\tdie \"'$path' already exists\"\n+\n+\tmodule_clone \"$path\" \"$repo\" || exit\n+\t(unset GIT_DIR && cd \"$path\" && git checkout -q) ||\n+\tdie \"Unable to checkout submodule '$path'\"\n+\tgit add \"$path\" ||\n+\tdie \"Failed to add submodule '$path'\"\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+}\n+\n+#\n # Register submodules in .git/config\n #\n # $@ = requested paths (default to all)\n@@ -173,6 +223,9 @@ modules_list()\n while case \"$#\" in 0) break ;; esac\n do\n \tcase \"$1\" in\n+\tadd)\n+\t\tadd=1\n+\t\t;;\n \tinit)\n \t\tinit=1\n \t\t;;\n@@ -201,14 +254,17 @@ do\n \tshift\n done\n \n-case \"$init,$update,$status,$cached\" in\n-1,,,)\n+case \"$add,$init,$update,$status,$cached\" in\n+1,,,,)\n+\tmodule_add \"$@\"\n+\t;;\n+,1,,,)\n \tmodules_init \"$@\"\n \t;;\n-,1,,)\n+,,1,,)\n \tmodules_update \"$@\"\n \t;;\n-,,*,*)\n+,,,*,*)\n \tmodules_list \"$@\"\n \t;;\n *)\n-- \n1.5.2.2.250.g1cd90-dirty\n"},{"id":"45617","messageId":"8c5c35580706231226lc887320ubce71d90dda8e9d3@mail.gmail.com","threadId":"8672","inReplyTo":"20070621095300.GA27071MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Lars Hjemli","fromEmail":"hjemli@gmail.com","sentAt":"2007-06-23T19:26:56Z","receivedAt":"2007-06-23T19:26:56Z","isPatch":true,"sender":{"key":"hjemli@gmail.com","avatar":null},"body":"On 6/21/07, Sven Verdoolaege <skimo@kotnet.org> wrote:\n> I didn't get any reaction (negative or positive) to this patch.\n\nSorry for the late reply, I've been buried in day-job stuff lately\n(and still is).\n\nThe patch looks sane to me. I'll try to play around with it tomorrow\nand give some more feedback.\n\n--\nlarsh\n"},{"id":"45620","messageId":"7v8xaa4f5g.fsf@assigned-by-dhcp.pobox.com","threadId":"8672","inReplyTo":"20070621095300.GA27071MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-23T19:58:03Z","receivedAt":"2007-06-23T19:58:03Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sven Verdoolaege <skimo@kotnet.org> writes:\n\n>  COMMANDS\n>  --------\n> +add::\n> +\tAdd the given repository as a submodule at the given path\n> +\tto the changeset to be committed next.  In particular, the\n> +\trepository is cloned at the specified path, added to the\n> +\tchangeset and registered in .gitmodules.   If no path is\n> +\tspecified, the path is deduced from the repository specification.\n> +\n\nSomehow \"git submodule add $URL $my_subdirectory\" feels\nunnatural, although it certainly is simpler to write the command\nusage string.  Wouldn't a commit on the maintenance branch of\ncgit.git want to say \"Add the 'maint' branch of git.git as my\nsubmodule\", for example?\n\nThe alternatives I can come up with do not feel right either, though.\n\n\tgit submodule $my_subdirectory $URL [$branch]\n\tgit submodule $URL [--branch $branch] $my_subdirectory\n\nHmmm...\n\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 89a3885..3df7121 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -1,13 +1,14 @@\n>  #!/bin/sh\n>  #\n> -# git-submodules.sh: init, update or list git submodules\n> +# git-submodules.sh: add, init, update or list git submodules\n>  #\n>  # Copyright (c) 2007 Lars Hjemli\n>  \n> -USAGE='[--quiet] [--cached] [status|init|update] [--] [<path>...]'\n> +USAGE='[--quiet] [--cached] [add <repo>|status|init|update] [--] [<path>...]'\n\nCan a single repo added at more than one path with this syntax?\nI do not see that in the code, but this implies such.\n\n>  . git-sh-setup\n>  require_work_tree\n>  \n> +add=\n>  init=\n>  update=\n>  status=\n> @@ -25,6 +26,17 @@ say()\n>  \tfi\n>  }\n>  \n> +get_repo_base() {\n> +\t(\n> +\t\tcd \"`/bin/pwd`\" &&\n> +\t\tcd \"$1\" || cd \"$1.git\" &&\n> +\t\t{\n> +\t\t\tcd .git\n> +\t\t\tpwd\n> +\t\t}\n> +\t) 2>/dev/null\n> +}\n> +\n\nI've seen this code before elsewhere.  We do not need to\nrefactor right now with this patch, but please mark this copy\nwith something like:\n\n\t# NEEDSWORK: identical function exists in get_repo_base\n        # in clone.sh\n\tget_repo_base () {\n        \t...\n\nas a reminder.\n\n> @@ -66,6 +78,44 @@ module_clone()\n>  }\n>  \n>  #\n> +# Add a new submodule to the working tree, .gitmodules and the index\n> +#\n> +# $@ = repo [path]\n> +#\n> +module_add()\n> +{\n> +\trepo=$1\n> +\tpath=$2\n> +\n> +\t# Turn the source into an absolute path if\n> +\t# it is local\n> +\tif base=$(get_repo_base \"$repo\"); then\n> +\t\trepo=\"$base\"\n> +\tfi\n> +\n> +\t# Guess path from repo if not specified or strip trailing slashes\n> +\tif test -z \"$path\"; then\n> +\t\tpath=$(echo \"$repo\" | sed -e 's|/*$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n> +\telse\n> +\t\tpath=$(echo \"$path\" | sed -e 's|/*$||')\n> +\tfi\n> +\n> +\ttest -e \"$path\" &&\n> +\tdie \"'$path' already exists\"\n> +\n> +\tmodule_clone \"$path\" \"$repo\" || exit\n\n - module_clone catches the \"$path already exists\" case; but the\n   test is done differently.  One particular case of \"an empty\n   directory exists\" is allowed there, but you are dying early\n   to forbid it.  Is that warranted?  My gut feeling is that\n   they should share the same check, iow, don't check yourself\n   but have module_clone take care of the error case.\n\n - If $path does not exist in the worktree (because it hasn't\n   been checked out), but does exist in the index, what should\n   happen?  Should it be flagged as an error (in module_clone,\n   not here)?\n"},{"id":"45622","messageId":"7vlkea2zr7.fsf@assigned-by-dhcp.pobox.com","threadId":"8672","inReplyTo":"8c5c35580706231226lc887320ubce71d90dda8e9d3@mail.gmail.com","subject":"Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-23T20:15:56Z","receivedAt":"2007-06-23T20:15:56Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Lars Hjemli\" <hjemli@gmail.com> writes:\n\n> On 6/21/07, Sven Verdoolaege <skimo@kotnet.org> wrote:\n>> I didn't get any reaction (negative or positive) to this patch.\n>\n> Sorry for the late reply, I've been buried in day-job stuff lately\n> (and still is).\n>\n> The patch looks sane to me. I'll try to play around with it tomorrow\n> and give some more feedback.\n\nThanks.\n"},{"id":"45671","messageId":"20070624151750.GA997MdfPADPa@greensroom.kotnet.org","threadId":"8672","inReplyTo":"7v8xaa4f5g.fsf@assigned-by-dhcp.pobox.com","subject":"Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-06-24T15:17:50Z","receivedAt":"2007-06-24T15:17:50Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Sat, Jun 23, 2007 at 12:58:03PM -0700, Junio C Hamano wrote:\n> Somehow \"git submodule add $URL $my_subdirectory\" feels\n> unnatural, although it certainly is simpler to write the command\n\nThe order of the arguments is the same as those of git-clone and\nyou can read it as \"git: add submodule $URL (at) $my_subdirectory\"\n\n> usage string.  Wouldn't a commit on the maintenance branch of\n> cgit.git want to say \"Add the 'maint' branch of git.git as my\n> submodule\", for example?\n\nSounds plausible\n\n> The alternatives I can come up with do not feel right either, though.\n> \n> \tgit submodule $my_subdirectory $URL [$branch]\n> \tgit submodule $URL [--branch $branch] $my_subdirectory\n\nI'll add the latter, although it's not clear if you actually\nwant me to.\n\n> > diff --git a/git-submodule.sh b/git-submodule.sh\n> > index 89a3885..3df7121 100755\n> > --- a/git-submodule.sh\n> > +++ b/git-submodule.sh\n> > @@ -1,13 +1,14 @@\n> >  #!/bin/sh\n> >  #\n> > -# git-submodules.sh: init, update or list git submodules\n> > +# git-submodules.sh: add, init, update or list git submodules\n> >  #\n> >  # Copyright (c) 2007 Lars Hjemli\n> >  \n> > -USAGE='[--quiet] [--cached] [status|init|update] [--] [<path>...]'\n> > +USAGE='[--quiet] [--cached] [add <repo>|status|init|update] [--] [<path>...]'\n> \n> Can a single repo added at more than one path with this syntax?\n\nNo.  I was trying to be brief.  The more correct syntax would be the one\nin the documentation, but I thought that would be a bit lengthy for\nUSAGE.\n\n> I've seen this code before elsewhere.  We do not need to\n> refactor right now with this patch, but please mark this copy\n> with something like:\n> \n> \t# NEEDSWORK: identical function exists in get_repo_base\n>         # in clone.sh\n> \tget_repo_base () {\n>         \t...\n\nOK\n\n> > +\ttest -e \"$path\" &&\n> > +\tdie \"'$path' already exists\"\n> > +\n> > +\tmodule_clone \"$path\" \"$repo\" || exit\n> \n>  - module_clone catches the \"$path already exists\" case; but the\n>    test is done differently.  One particular case of \"an empty\n>    directory exists\" is allowed there, but you are dying early\n>    to forbid it.  Is that warranted?  My gut feeling is that\n>    they should share the same check, iow, don't check yourself\n>    but have module_clone take care of the error case.\n\nThey're different because submodule update (which also calls module_clone)\nis performed on a module that already exists in the repo and\nwas therefore checked out by git as an empty directory.  If you\nadd a new submodule, then there is no reason for the subdirectory\nto exist already.\n\n>  - If $path does not exist in the worktree (because it hasn't\n>    been checked out), but does exist in the index, what should\n>    happen?  Should it be flagged as an error (in module_clone,\n>    not here)?\n\nGood question.  It should fail.  However, I think this new check\ndoes belong here, because when module_clone is called from\nmodules_update, the path _should_ exist in the index.\n\nskimo\n"},{"id":"45680","messageId":"7vir9dtf5z.fsf@assigned-by-dhcp.cox.net","threadId":"8672","inReplyTo":"20070624151750.GA997MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH][RESEND] git-submodule: provide easy way of adding new submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-24T17:50:48Z","receivedAt":"2007-06-24T17:50:48Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sven Verdoolaege <skimo@kotnet.org> writes:\n\n> They're different because submodule update (which also calls module_clone)\n> is performed on a module that already exists in the repo and\n> was therefore checked out by git as an empty directory.  If you\n> add a new submodule, then there is no reason for the subdirectory\n> to exist already.\n\nAh, you are absolutely right.  Thanks for the clarification.\n\nBy the way, when I have to say \"thanks for the clarification\", I\nthink it is an indication that the relevant parts of the code\nneed a bit of commenting ;-).\n"},{"id":"45693","messageId":"20070624210607.GC997MdfPADPa@greensroom.kotnet.org","threadId":"8672","inReplyTo":"7vir9dtf5z.fsf@assigned-by-dhcp.cox.net","subject":"[PATCH] git-submodule: provide easy way of adding new submodules","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-06-24T21:06:07Z","receivedAt":"2007-06-24T21:06:07Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"To make a submodule effectively usable, the path and\na URL where the submodule can be cloned need to be stored\nin .gitmodules.  This subcommand takes care of setting\nthis information after cloning the new submodule.\nOnly the index is updated, so, if needed, the user may still\nchange the URL or switch to a different branch of the submodule\nbefore committing.\n\nSigned-off-by: Sven Verdoolaege <skimo@kotnet.org>\n---\nOn Sun, Jun 24, 2007 at 10:50:48AM -0700, Junio C Hamano wrote:\n> Sven Verdoolaege <skimo@kotnet.org> writes:\n> \n> > They're different because submodule update (which also calls module_clone)\n> > is performed on a module that already exists in the repo and\n> > was therefore checked out by git as an empty directory.  If you\n> > add a new submodule, then there is no reason for the subdirectory\n> > to exist already.\n> \n> Ah, you are absolutely right.  Thanks for the clarification.\n> \n> By the way, when I have to say \"thanks for the clarification\", I\n> think it is an indication that the relevant parts of the code\n> need a bit of commenting ;-).\n\nHow's this ?\n\nskimo\n\n Documentation/git-submodule.txt |   11 ++++\n git-submodule.sh                |  102 ++++++++++++++++++++++++++++++++++++--\n 2 files changed, 107 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex f8fb80f..7f0904e 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -8,11 +8,19 @@ git-submodule - Initialize, update or inspect submodules\n \n SYNOPSIS\n --------\n+'git-submodule' [--quiet] [-b branch] add <repository> [<path>]\n 'git-submodule' [--quiet] [--cached] [status|init|update] [--] [<path>...]\n \n \n COMMANDS\n --------\n+add::\n+\tAdd the given repository as a submodule at the given path\n+\tto the changeset to be committed next.  In particular, the\n+\trepository is cloned at the specified path, added to the\n+\tchangeset and registered in .gitmodules.   If no path is\n+\tspecified, the path is deduced from the repository specification.\n+\n status::\n \tShow the status of the submodules. This will print the SHA-1 of the\n \tcurrently checked out commit for each submodule, along with the\n@@ -39,6 +47,9 @@ OPTIONS\n -q, --quiet::\n \tOnly print error messages.\n \n+-b, --branch::\n+\tBranch of repository to add as submodule.\n+\n --cached::\n \tDisplay the SHA-1 stored in the index, not the SHA-1 of the currently\n \tchecked out submodule commit. This option is only valid for the\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 89a3885..67c78f2 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -1,13 +1,15 @@\n #!/bin/sh\n #\n-# git-submodules.sh: init, update or list git submodules\n+# git-submodules.sh: add, init, update or list git submodules\n #\n # Copyright (c) 2007 Lars Hjemli\n \n-USAGE='[--quiet] [--cached] [status|init|update] [--] [<path>...]'\n+USAGE='[--quiet] [--cached] [add <repo> [-b branch]|status|init|update] [--] [<path>...]'\n . git-sh-setup\n require_work_tree\n \n+add=\n+branch=\n init=\n update=\n status=\n@@ -25,6 +27,18 @@ say()\n \tfi\n }\n \n+# NEEDSWORK: identical function exists in get_repo_base in clone.sh\n+get_repo_base() {\n+\t(\n+\t\tcd \"`/bin/pwd`\" &&\n+\t\tcd \"$1\" || cd \"$1.git\" &&\n+\t\t{\n+\t\t\tcd .git\n+\t\t\tpwd\n+\t\t}\n+\t) 2>/dev/null\n+}\n+\n #\n # Map submodule path to submodule name\n #\n@@ -42,6 +56,11 @@ module_name()\n #\n # Clone a submodule\n #\n+# Prior to calling, modules_update checks that a possibly existing\n+# path is not a git repository.\n+# Likewise, module_add checks that path does not exist at all,\n+# since it is the location of a new submodule.\n+#\n module_clone()\n {\n \tpath=$1\n@@ -66,6 +85,53 @@ module_clone()\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+module_add()\n+{\n+\trepo=$1\n+\tpath=$2\n+\n+\tif test -z \"$repo\"; then\n+\t\tusage\n+\tfi\n+\n+\t# Turn the source into an absolute path if\n+\t# it is local\n+\tif base=$(get_repo_base \"$repo\"); then\n+\t\trepo=\"$base\"\n+\tfi\n+\n+\t# Guess path from repo if not specified or strip trailing slashes\n+\tif test -z \"$path\"; then\n+\t\tpath=$(echo \"$repo\" | sed -e 's|/*$||' -e 's|:*/*\\.git$||' -e 's|.*[/:]||g')\n+\telse\n+\t\tpath=$(echo \"$path\" | sed -e 's|/*$||')\n+\tfi\n+\n+\ttest -e \"$path\" &&\n+\tdie \"'$path' already exists\"\n+\n+\tgit-ls-files --error-unmatch \"$path\" > /dev/null 2>&1 &&\n+\tdie \"'$path' already exists in the index\"\n+\n+\tmodule_clone \"$path\" \"$repo\" || exit\n+\t(unset GIT_DIR && cd \"$path\" && git checkout -q ${branch:+-b \"$branch\" \"origin/$branch\"}) ||\n+\tdie \"Unable to checkout submodule '$path'\"\n+\tgit add \"$path\" ||\n+\tdie \"Failed to add submodule '$path'\"\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+}\n+\n+#\n # Register submodules in .git/config\n #\n # $@ = requested paths (default to all)\n@@ -173,6 +239,9 @@ modules_list()\n while case \"$#\" in 0) break ;; esac\n do\n \tcase \"$1\" in\n+\tadd)\n+\t\tadd=1\n+\t\t;;\n \tinit)\n \t\tinit=1\n \t\t;;\n@@ -185,6 +254,14 @@ do\n \t-q|--quiet)\n \t\tquiet=1\n \t\t;;\n+\t-b|--branch)\n+\t\tcase \"$2\" in\n+\t\t'')\n+\t\t\tusage\n+\t\t\t;;\n+\t\tesac\n+\t\tbranch=\"$2\"; shift\n+\t\t;;\n \t--cached)\n \t\tcached=1\n \t\t;;\n@@ -201,14 +278,27 @@ do\n \tshift\n done\n \n-case \"$init,$update,$status,$cached\" in\n-1,,,)\n+case \"$add,$branch\" in\n+1,*)\n+\t;;\n+,)\n+\t;;\n+,*)\n+\tusage\n+\t;;\n+esac\n+\n+case \"$add,$init,$update,$status,$cached\" in\n+1,,,,)\n+\tmodule_add \"$@\"\n+\t;;\n+,1,,,)\n \tmodules_init \"$@\"\n \t;;\n-,1,,)\n+,,1,,)\n \tmodules_update \"$@\"\n \t;;\n-,,*,*)\n+,,,1,*)\n \tmodules_list \"$@\"\n \t;;\n *)\n-- \n1.5.2.2.1064.g59b4\n"},{"id":"45739","messageId":"7vps3k33ze.fsf@assigned-by-dhcp.pobox.com","threadId":"8672","inReplyTo":"20070624210607.GC997MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH] git-submodule: provide easy way of adding new submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-06-25T07:09:09Z","receivedAt":"2007-06-25T07:09:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sven Verdoolaege <skimo@kotnet.org> writes:\n\n> To make a submodule effectively usable, the path and\n> a URL where the submodule can be cloned need to be stored\n> in .gitmodules.  This subcommand takes care of setting\n> this information after cloning the new submodule.\n> Only the index is updated, so, if needed, the user may still\n> change the URL or switch to a different branch of the submodule\n> before committing.\n>\n> Signed-off-by: Sven Verdoolaege <skimo@kotnet.org>\n> ---\n> On Sun, Jun 24, 2007 at 10:50:48AM -0700, Junio C Hamano wrote:\n>> Sven Verdoolaege <skimo@kotnet.org> writes:\n>> \n>> > They're different because submodule update (which also calls module_clone)\n>> > is performed on a module that already exists in the repo and\n>> > was therefore checked out by git as an empty directory.  If you\n>> > add a new submodule, then there is no reason for the subdirectory\n>> > to exist already.\n>> \n>> Ah, you are absolutely right.  Thanks for the clarification.\n>> \n>> By the way, when I have to say \"thanks for the clarification\", I\n>> think it is an indication that the relevant parts of the code\n>> need a bit of commenting ;-).\n>\n> How's this ?\n\nI am not sure about the usefulness of \"-b branch\" thing myself,\nbut other than that, looks very sane to me.\n\nLars?\n"},{"id":"46380","messageId":"20070703154732.GO7969MdfPADPa@greensroom.kotnet.org","threadId":"8672","inReplyTo":"7vps3k33ze.fsf@assigned-by-dhcp.pobox.com","subject":"Re: [PATCH] git-submodule: provide easy way of adding new submodules","fromName":"Sven Verdoolaege","fromEmail":"skimo@kotnet.org","sentAt":"2007-07-03T15:47:32Z","receivedAt":"2007-07-03T15:47:32Z","isPatch":true,"sender":{"key":"skimo@kotnet.org","avatar":null},"body":"On Mon, Jun 25, 2007 at 12:09:09AM -0700, Junio C Hamano wrote:\n> I am not sure about the usefulness of \"-b branch\" thing myself,\n> but other than that, looks very sane to me.\n\nSo, do you want me to send it in again, without the branch thing?\n\nskimo\n"},{"id":"46433","messageId":"7vabucn48m.fsf@assigned-by-dhcp.cox.net","threadId":"8672","inReplyTo":"20070703154732.GO7969MdfPADPa@greensroom.kotnet.org","subject":"Re: [PATCH] git-submodule: provide easy way of adding new submodules","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-07-04T05:10:33Z","receivedAt":"2007-07-04T05:10:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Sven Verdoolaege <skimo@kotnet.org> writes:\n\n> On Mon, Jun 25, 2007 at 12:09:09AM -0700, Junio C Hamano wrote:\n>> I am not sure about the usefulness of \"-b branch\" thing myself,\n>> but other than that, looks very sane to me.\n>\n> So, do you want me to send it in again, without the branch thing?\n\nIt is already scheduled for 1.5.3 and is part of 'master'.\n"}]}