{"thread":{"id":"11519","subject":"[PATCH] Added initialize and update support for submodule in git clone","startedAt":"2008-01-08T03:22:18Z","lastAt":"2008-01-09T06:05:26Z","messageCount":3,"participants":["Imran M Yousuf","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"64695","messageId":"7bfdc29a0801071922h3656a576wbd87e84bfa663d5a@mail.gmail.com","threadId":"11519","inReplyTo":null,"subject":"[PATCH] Added initialize and update support for submodule in git clone","fromName":"Imran M Yousuf","fromEmail":"imyousuf@gmail.com","sentAt":"2008-01-08T03:22:18Z","receivedAt":"2008-01-08T03:22:18Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"This patch adds support for initializing and updating submodules when\na repo is cloned. The advantage it adds is, the user actually does not\nhave to know whether it has a module or not and if it does to what\ndepth and path. For this I added a option -w or --with-submodule for\ninitializing and updating during clone stage.\n\nI am working on project that has multiple maven modules and some of\nthe modules have separate GIT repo and needs to be linked with the\nmain project after maturity; we wanted that when developers clone the\nmain repo it should fetch all the submodules at once.\n\nFollowing is the diff with git-clone 1.5.3.7; I also attached the diff\nand modified file in the attachment. I would like to add that I am not\nfully sure about unsetting the GIT_DIR, GIT_CONFIG and GIT_WORK_TREE\nand resetting them and thus added them to the comment. If there is a\nbetter way to achieve it I would gratefully incorporate it.\n\ndiff --git a/git-clone b/git-clone\nindex 204a769..63510c4 100755\n--- a/git-clone\n+++ b/git-clone\n@@ -14,7 +14,7 @@ die() {\n }\n\n usage() {\n-\tdie \"Usage: $0 [--template=<template_directory>] [--reference\n<reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin\n<name>] [--depth <n>] [-n] <repo> [<dir>]\"\n+\tdie \"Usage: $0 [--template=<template_directory>] [--reference\n<reference-repo>] [--bare] [-l [-s]] [-q] [-w|--with-submodule] [-u\n<upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]\"\n }\n\n get_repo_base() {\n@@ -90,6 +90,29 @@ Perhaps git-update-server-info needs to be run there?\"\n \tfi\n }\n\n+initializeSubModule() {\n+\tif [ ! -d \"$1\"/.git ]; then\n+\t\tgit-submodule-test init \"$1\"; git-submodule-test update \"$1\"\n+\tfi\n+}\n+\n+initSubModules() {\n+\tcurrent_dir=`pwd`\n+\tdir_path=\"$current_dir:$dir_path\"\n+\tinitializeSubModule \"$1\"\n+        cd \"$1\"\n+\tif [ -f .gitmodules ]; then\n+                for sub_mod_path in `grep \"path =\" .gitmodules | awk\n'{print $3}'`; do\n+\t\t\tinitSubModules \"$sub_mod_path\"\n+                done\n+        fi\n+\told_dir=$(echo $dir_path | cut -d':' -f1-1)\n+\tlength_old_dir=`expr \"$old_dir\" : '.*'`\n+\tcd $old_dir\n+\tindex=$(echo \"$length_old_dir+2\" | bc)\n+\tdir_path=`echo $dir_path $index | awk '{print substr($1, $2)}'`\n+}\n+\n quiet=\n local=no\n use_local_hardlink=yes\n@@ -106,6 +129,7 @@ depth=\n no_progress=\n local_explicitly_asked_for=\n test -t 1 || no_progress=--no-progress\n+with_submodule=0\n while\n \tcase \"$#,$1\" in\n \t0,*) break ;;\n@@ -156,6 +180,7 @@ while\n \t\tupload_pack=\"--upload-pack=$1\" ;;\n \t*,--upload-pack=*)\n \t\tupload_pack=--upload-pack=$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n+\t*,-w|*,--w|*,--wi|*,--wit|*,--with|*,--with-s|*,--with-su|*,--with-sub|*,--with-subm|*,--with-submo|*,--with-submod|*,--with-submodu|*,--with-submodul|*,--with-submodule)\nwith_submodule=1 ;;\n \t1,--depth) usage;;\n \t*,--depth)\n \t\tshift\n@@ -465,4 +490,38 @@ then\n fi\n rm -f \"$GIT_DIR/CLONE_HEAD\" \"$GIT_DIR/REMOTE_HEAD\"\n\n+# The following section initializes the submodules of the repo\n+if [ $with_submodule -eq 1  ]; then\n+\tif [ -f .gitmodules ]; then\n+\n+\t\t# Need to know either what is the alternate\n+\t\t# or what else to backup and unset\n+\t\t# If this is not done in that case recursion\n+\t\t# in a subdirectory of the top level fails\n+\t\t# Thus the old values are backed up and restored\n+\t\t# after recursion\n+\t\tOLD_GIT_DIR=\"$GIT_DIR\"\n+\t\tOLD_GIT_CONFIG=\"$GIT_CONFIG\"\n+\t\tOLD_GIT_WORK_TREE=\"$GIT_WORK_TREE\"\n+\t\tunset GIT_DIR\n+\t\tunset GIT_CONFIG\n+\t\tunset GIT_WORK_TREE\n+\n+\t\t# The following loop iterates over the submodules\n+\t\t# visible from he top of the module\n+\t        for mod_path in `grep \"path =\" .gitmodules | awk '{print $3}'`; do\n+                        initSubModules \"$mod_path\"\n+                done\n+\n+\t\tGIT_DIR=\"$OLD_GIT_DIR\"\n+\t\tGIT_CONFIG=\"$OLD_GIT_CONFIG\"\n+\t\tGIT_WORK_TREE=\"$OLD_GIT_WORK_TREE\"\n+\n+\t\t# The following export is probably not required\n+\t\texport GIT_DIR\n+\t\texport GIT_CONFIG\n+\t\texport GIT_WORK_TREE\n+\tfi\n+fi\n+\n trap - 0\n\n-- \nImran M Yousuf\n\n\ndiff --git a/git-clone b/git-clone\nindex 204a769..63510c4 100755\n--- a/git-clone\n+++ b/git-clone\n@@ -14,7 +14,7 @@ die() {\n }\n \n usage() {\n-\tdie \"Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]\"\n+\tdie \"Usage: $0 [--template=<template_directory>] [--reference <reference-repo>] [--bare] [-l [-s]] [-q] [-w|--with-submodule] [-u <upload-pack>] [--origin <name>] [--depth <n>] [-n] <repo> [<dir>]\"\n }\n \n get_repo_base() {\n@@ -90,6 +90,29 @@ Perhaps git-update-server-info needs to be run there?\"\n \tfi\n }\n \n+initializeSubModule() {\n+\tif [ ! -d \"$1\"/.git ]; then\n+\t\tgit-submodule-test init \"$1\"; git-submodule-test update \"$1\"\n+\tfi\n+}\n+\n+initSubModules() {\n+\tcurrent_dir=`pwd`\n+\tdir_path=\"$current_dir:$dir_path\"\n+\tinitializeSubModule \"$1\"\n+        cd \"$1\"\n+\tif [ -f .gitmodules ]; then\n+                for sub_mod_path in `grep \"path =\" .gitmodules | awk '{print $3}'`; do\n+\t\t\tinitSubModules \"$sub_mod_path\"\n+                done\n+        fi\n+\told_dir=$(echo $dir_path | cut -d':' -f1-1)\n+\tlength_old_dir=`expr \"$old_dir\" : '.*'`\n+\tcd $old_dir\n+\tindex=$(echo \"$length_old_dir+2\" | bc)\n+\tdir_path=`echo $dir_path $index | awk '{print substr($1, $2)}'`\n+}\n+\n quiet=\n local=no\n use_local_hardlink=yes\n@@ -106,6 +129,7 @@ depth=\n no_progress=\n local_explicitly_asked_for=\n test -t 1 || no_progress=--no-progress\n+with_submodule=0\n while\n \tcase \"$#,$1\" in\n \t0,*) break ;;\n@@ -156,6 +180,7 @@ while\n \t\tupload_pack=\"--upload-pack=$1\" ;;\n \t*,--upload-pack=*)\n \t\tupload_pack=--upload-pack=$(expr \"z$1\" : 'z-[^=]*=\\(.*\\)') ;;\n+\t*,-w|*,--w|*,--wi|*,--wit|*,--with|*,--with-s|*,--with-su|*,--with-sub|*,--with-subm|*,--with-submo|*,--with-submod|*,--with-submodu|*,--with-submodul|*,--with-submodule) with_submodule=1 ;;\n \t1,--depth) usage;;\n \t*,--depth)\n \t\tshift\n@@ -465,4 +490,38 @@ then\n fi\n rm -f \"$GIT_DIR/CLONE_HEAD\" \"$GIT_DIR/REMOTE_HEAD\"\n \n+# The following section initializes the submodules of the repo\n+if [ $with_submodule -eq 1  ]; then\n+\tif [ -f .gitmodules ]; then\n+\n+\t\t# Need to know either what is the alternate \n+\t\t# or what else to backup and unset\n+\t\t# If this is not done in that case recursion \n+\t\t# in a subdirectory of the top level fails\n+\t\t# Thus the old values are backed up and restored\n+\t\t# after recursion\n+\t\tOLD_GIT_DIR=\"$GIT_DIR\"\n+\t\tOLD_GIT_CONFIG=\"$GIT_CONFIG\"\n+\t\tOLD_GIT_WORK_TREE=\"$GIT_WORK_TREE\"\n+\t\tunset GIT_DIR\n+\t\tunset GIT_CONFIG\n+\t\tunset GIT_WORK_TREE\n+\n+\t\t# The following loop iterates over the submodules\n+\t\t# visible from he top of the module\n+\t        for mod_path in `grep \"path =\" .gitmodules | awk '{print $3}'`; do\n+                        initSubModules \"$mod_path\"\n+                done\n+\n+\t\tGIT_DIR=\"$OLD_GIT_DIR\"\n+\t\tGIT_CONFIG=\"$OLD_GIT_CONFIG\"\n+\t\tGIT_WORK_TREE=\"$OLD_GIT_WORK_TREE\"\n+\n+\t\t# The following export is probably not required\n+\t\texport GIT_DIR\n+\t\texport GIT_CONFIG\n+\t\texport GIT_WORK_TREE\n+\tfi\n+fi\n+\n trap - 0\n"},{"id":"64701","messageId":"7vr6gsx2j5.fsf@gitster.siamese.dyndns.org","threadId":"11519","inReplyTo":"7bfdc29a0801071922h3656a576wbd87e84bfa663d5a@mail.gmail.com","subject":"Re: [PATCH] Added initialize and update support for submodule in git clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-01-08T06:19:26Z","receivedAt":"2008-01-08T06:19:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Imran M Yousuf\" <imyousuf@gmail.com> writes:\n\n> This patch adds support for initializing and updating submodules when\n> a repo is cloned. The advantage it adds is, the user actually does not\n> have to know whether it has a module or not and if it does to what\n> depth and path. For this I added a option -w or --with-submodule for\n> initializing and updating during clone stage.\n\nFor everything else, I strongly agree [*1*] that the notion that\nall subprojects are populated is a bug.  I am not convinced the\nall-or-nothing approach you implemented in \"git clone\" is useful\noutside small toy projects where all of your users are almost\nalways interested in everything (which inevitably invites a very\nvalid question: why use submodule at all then?), but in the very\nnarrow special case of \"clone\", all-or-nothing is the best you\ncan do without giving additional hints somewhere in-tree\n(perhaps enhanced .gitmodules entries), and it certainly is\nbetter than \"you do not have any choice --- you only get the\ntoplevel\".\n\n> Following is the diff with git-clone 1.5.3.7; I also attached the diff\n> and modified file in the attachment.\n\nThe same comment as diff plus attachment applies to this patch\nas the other message.  Also please do not base new development\non 4-digit maintenance releases, which are meant to contain only\nbugfixes and no new features.  A patch like this, primarily for\ndiscussion and not for immediate inclusion, is Ok, but it is\nbetter to get into the habit of producing applicable patches\nearlier rather than later.\n\nI'll step aside and let others discuss code and design of the\npatch.\n\n[Reference]\n\n*1* http://thread.gmane.org/gmane.comp.version-control.git/44106/focus=44308\n"},{"id":"64815","messageId":"7bfdc29a0801082205m383dc32bm19af0032efb1637a@mail.gmail.com","threadId":"11519","inReplyTo":"7vr6gsx2j5.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] Added initialize and update support for submodule in git clone","fromName":"Imran M Yousuf","fromEmail":"imyousuf@gmail.com","sentAt":"2008-01-09T06:05:26Z","receivedAt":"2008-01-09T06:05:26Z","isPatch":true,"sender":{"key":"imyousuf@gmail.com","avatar":"https://gravatar.com/avatar/fda3c870262849d03c7b9c4d288842e128d6d80769fa7bc2d22731b7597928be?d=mp&s=160"},"body":"Thanks again Junio.\n\nI will resend the patch with the latest code base. After implementing\nI also felt that it is not logical to go all way down, so I was\nthinking of adding -l | --level with -w or use --depth already in use;\nthat will add some flexibility; what do you thing about this? I will\nmake the similar changes you mentioned in the earlier email in this as\nwell.\n\nI was actually concerned about unsetting and re-setting the\nenvironment variables. Is there a alternate to it?\n\nThank you,\n\nImran\n\nOn Jan 8, 2008 12:19 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> \"Imran M Yousuf\" <imyousuf@gmail.com> writes:\n>\n> > This patch adds support for initializing and updating submodules when\n> > a repo is cloned. The advantage it adds is, the user actually does not\n> > have to know whether it has a module or not and if it does to what\n> > depth and path. For this I added a option -w or --with-submodule for\n> > initializing and updating during clone stage.\n>\n> For everything else, I strongly agree [*1*] that the notion that\n> all subprojects are populated is a bug.  I am not convinced the\n> all-or-nothing approach you implemented in \"git clone\" is useful\n> outside small toy projects where all of your users are almost\n> always interested in everything (which inevitably invites a very\n> valid question: why use submodule at all then?), but in the very\n> narrow special case of \"clone\", all-or-nothing is the best you\n> can do without giving additional hints somewhere in-tree\n> (perhaps enhanced .gitmodules entries), and it certainly is\n> better than \"you do not have any choice --- you only get the\n> toplevel\".\n>\n> > Following is the diff with git-clone 1.5.3.7; I also attached the diff\n> > and modified file in the attachment.\n>\n> The same comment as diff plus attachment applies to this patch\n> as the other message.  Also please do not base new development\n> on 4-digit maintenance releases, which are meant to contain only\n> bugfixes and no new features.  A patch like this, primarily for\n> discussion and not for immediate inclusion, is Ok, but it is\n> better to get into the habit of producing applicable patches\n> earlier rather than later.\n>\n> I'll step aside and let others discuss code and design of the\n> patch.\n>\n> [Reference]\n>\n> *1* http://thread.gmane.org/gmane.comp.version-control.git/44106/focus=44308\n>\n\n\n\n-- \nImran M Yousuf\nEntrepreneur & Software Engineer\nSmart IT Engineering\nDhaka, Bangladesh\nEmail: imran@smartitengineering.com\nMobile: +880-1711402557\n"}]}