{"thread":{"id":"34320","subject":"[PATCH v3] [submodule] Add --depth to submodule update/add","startedAt":"2013-07-02T01:39:27Z","lastAt":"2013-07-03T17:36:58Z","messageCount":11,"participants":["Fredrik Gustafsson","Andreas Schwab","Jens Lehmann","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"222329","messageId":"1372729167-23200-1-git-send-email-iveqy@iveqy.com","threadId":"34320","inReplyTo":null,"subject":"[PATCH v3] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-07-02T01:39:27Z","receivedAt":"2013-07-02T01:39:27Z","isPatch":true,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"When a submodule is clone, clone it width the --depth flag. This is useful\nwhen the submodule(s) are huge and you're not really interested in anything\nbut the latest commit.\n\nTests are added and to make --depth work the path for test \"setup a submodule\ntree\" had to be modified. Also did some indent adjustments to conform to the\nrest of the testfile on \"submodule update can handle symbolic links in pwd\".\n\nSigned-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n---\n\nThe previous iteration can be found here:\nhttp://thread.gmane.org/gmane.comp.version-control.git/229196/\n\nThis was actually a bit tricky. When I changed\ngit clone $depth\nto\ngit clone \"$depth\"\n\ngit clone dies with the error \"too many arguments\". This was solved with changing\ndepth=$5\nto\ndepth=\"$5\"\n\nwhich I don't understand since variable assignment doesn't expand $5 and therefore\n\"\" should not be needed, AFAIK. Any comments on this?\n\nAn other note:\nfile:// accepts relative paths but don't handle them well at all. For example in the\ntest t7406-submodule-update.sh:\ngit clone file://cloned super3\nwill work, but submodules and push/fetch will be \"broken\", since the paths will\nbe wrong.\n\n Documentation/git-submodule.txt | 10 ++++++++--\n git-submodule.sh                | 24 +++++++++++++++++++++---\n t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n 4 files changed, 61 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex e576713..9876c7c 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -10,12 +10,12 @@ SYNOPSIS\n --------\n [verse]\n 'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n-\t      [--reference <repository>] [--] <repository> [<path>]\n+\t      [--reference <repository>] [--clone-depth <depth>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n-\t      [-f|--force] [--rebase] [--reference <repository>]\n+\t      [-f|--force] [--rebase] [--reference <repository>] [--clone-depth <depth>]\n \t      [--merge] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n@@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n \tonly in the submodules of the current repo, but also\n \tin any nested submodules inside those submodules (and so on).\n \n+--clone-depth::\n+\tThis option is valid for add and update commands. Create a 'shallow'\n+\tclone with a history truncated to the specified number of revisions.\n+\tSee linkgit:git-clone[1]\n+\n+\n <path>...::\n \tPaths to submodule(s). When specified this will restrict the command\n \tto only operate on the submodules found at the specified paths.\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 79bfaac..1cfe2bf 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -32,6 +32,7 @@ nofetch=\n update=\n prefix=\n custom_name=\n+depth=\n \n # The function takes at most 2 arguments. The first argument is the\n # URL that navigates to the submodule origin repo. When relative, this URL\n@@ -211,6 +212,7 @@ module_clone()\n \tname=$2\n \turl=$3\n \treference=\"$4\"\n+\tdepth=\"$5\"\n \tquiet=\n \tif test -n \"$GIT_QUIET\"\n \tthen\n@@ -233,7 +235,7 @@ module_clone()\n \t\tmkdir -p \"$gitdir_base\"\n \t\t(\n \t\t\tclear_local_git_env\n-\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n+\t\t\tgit clone $quiet $depth -n ${reference:+\"$reference\"} \\\n \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n \t\t) ||\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n@@ -309,6 +311,14 @@ cmd_add()\n \t\t\tcustom_name=$2\n \t\t\tshift\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n \t\t\tfi\n \t\tfi\n-\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n+\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n \t\t(\n \t\t\tclear_local_git_env\n \t\t\tcd \"$sm_path\" &&\n@@ -676,6 +686,14 @@ cmd_update()\n \t\t--checkout)\n \t\t\tupdate=\"checkout\"\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n \n \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n+\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n \t\t\tcloned_modules=\"$cloned_modules;$name\"\n \t\t\tsubsha1=\n \t\telse\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex f47cc7b..bfd1ce9 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n '\n \n+test_expect_success 'submodule add clone shallow submodule' '\n+\tmkdir super &&\n+\tpwd=$(pwd)\n+\t(\n+\t\tcd super &&\n+\t\tgit init &&\n+\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n+\t\t(\n+\t\t\tcd submodule &&\n+\t\t\ttest 1 = $(git log --oneline | wc -l)\n+\t\t)\n+\t)\n+'\n+\n+\n test_done\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex a4ffea0..e0a06e2 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n \tmkdir -p linked/dir &&\n \tln -s linked/dir linkto &&\n-\t(\n-\t\tcd linkto &&\n-\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n-\t\t(\n-\t\t\tcd super &&\n-\t\t\tgit submodule update --init --recursive\n-\t\t)\n+\t(cd linkto &&\n+\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n+\t (cd super &&\n+\t  git submodule update --init --recursive\n+\t )\n \t)\n '\n \n+test_expect_success 'submodule update clone shallow submodule' '\n+\tgit clone cloned super3 &&\n+\tpwd=$(pwd)\n+\t(cd super3 &&\n+\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n+\t mv -f .gitmodules.tmp .gitmodules &&\n+\t git submodule update --init --depth=3\n+\t (cd submodule &&\n+\t  test 1 = $(git log --oneline | wc -l)\n+\t )\n+\t)\n+'\n test_done\n-- \n1.8.3.1.490.g39d9b24.dirty\n"},{"id":"222376","messageId":"87fvvwga6f.fsf@igel.home","threadId":"34320","inReplyTo":"1372729167-23200-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v3] [submodule] Add --depth to submodule update/add","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2013-07-02T17:10:16Z","receivedAt":"2013-07-02T17:10:16Z","isPatch":true,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"Fredrik Gustafsson <iveqy@iveqy.com> writes:\n\n> This was actually a bit tricky. When I changed\n> git clone $depth\n> to\n> git clone \"$depth\"\n>\n> git clone dies with the error \"too many arguments\".\n\n... when $depth is empty.\n\nAndreas.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5\n\"And now for something completely different.\"\n"},{"id":"222383","messageId":"51D311F2.1030009@web.de","threadId":"34320","inReplyTo":"1372729167-23200-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v3] [submodule] Add --depth to submodule update/add","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2013-07-02T17:46:26Z","receivedAt":"2013-07-02T17:46:26Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Sending again because the first one bounced.\n\nAm 02.07.2013 03:39, schrieb Fredrik Gustafsson:\n> When a submodule is clone, clone it width the --depth flag. This is useful\n> when the submodule(s) are huge and you're not really interested in anything\n> but the latest commit.\n>\n> Tests are added and to make --depth work the path for test \"setup a submodule\n> tree\" had to be modified. Also did some indent adjustments to conform to the\n> rest of the testfile on \"submodule update can handle symbolic links in pwd\".\n> \n> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n> ---\n> \n> The previous iteration can be found here:\n> http://thread.gmane.org/gmane.comp.version-control.git/229196/\n\nThe first line of the commit message still sounds strange to me, please see\nmy answer in the thread you quoted.\n\nAlso the documentation still talks about --clone-depth.\n\n> This was actually a bit tricky. When I changed\n> git clone $depth\n> to\n> git clone \"$depth\"\n> \n> git clone dies with the error \"too many arguments\". This was solved with changing\n> depth=$5\n> to\n> depth=\"$5\"\n> \n> which I don't understand since variable assignment doesn't expand $5 and therefore\n> \"\" should not be needed, AFAIK. Any comments on this?\n\nThe assignment to reference right above that is quoted like that too. I wonder\nif we should also use ${depth:+\"$depth\"} as argument to clone.\n\n> An other note:\n> file:// accepts relative paths but don't handle them well at all. For example in the\n> test t7406-submodule-update.sh:\n> git clone file://cloned super3\n> will work, but submodules and push/fetch will be \"broken\", since the paths will\n> be wrong.\n> \n>  Documentation/git-submodule.txt | 10 ++++++++--\n>  git-submodule.sh                | 24 +++++++++++++++++++++---\n>  t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n>  t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n>  4 files changed, 61 insertions(+), 12 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index e576713..9876c7c 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -10,12 +10,12 @@ SYNOPSIS\n>  --------\n>  [verse]\n>  'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n> -\t      [--reference <repository>] [--] <repository> [<path>]\n> +\t      [--reference <repository>] [--clone-depth <depth>] [--] <repository> [<path>]\n>  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] init [--] [<path>...]\n>  'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n>  'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n> -\t      [-f|--force] [--rebase] [--reference <repository>]\n> +\t      [-f|--force] [--rebase] [--reference <repository>] [--clone-depth <depth>]\n>  \t      [--merge] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n>  \t      [commit] [--] [<path>...]\n> @@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n>  \tonly in the submodules of the current repo, but also\n>  \tin any nested submodules inside those submodules (and so on).\n>  \n> +--clone-depth::\n> +\tThis option is valid for add and update commands. Create a 'shallow'\n> +\tclone with a history truncated to the specified number of revisions.\n> +\tSee linkgit:git-clone[1]\n> +\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n>  \tto only operate on the submodules found at the specified paths.\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 79bfaac..1cfe2bf 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -32,6 +32,7 @@ nofetch=\n>  update=\n>  prefix=\n>  custom_name=\n> +depth=\n>  \n>  # The function takes at most 2 arguments. The first argument is the\n>  # URL that navigates to the submodule origin repo. When relative, this URL\n> @@ -211,6 +212,7 @@ module_clone()\n>  \tname=$2\n>  \turl=$3\n>  \treference=\"$4\"\n> +\tdepth=\"$5\"\n>  \tquiet=\n>  \tif test -n \"$GIT_QUIET\"\n>  \tthen\n> @@ -233,7 +235,7 @@ module_clone()\n>  \t\tmkdir -p \"$gitdir_base\"\n>  \t\t(\n>  \t\t\tclear_local_git_env\n> -\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> +\t\t\tgit clone $quiet $depth -n ${reference:+\"$reference\"} \\\n>  \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n>  \t\t) ||\n>  \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n> @@ -309,6 +311,14 @@ cmd_add()\n>  \t\t\tcustom_name=$2\n>  \t\t\tshift\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n>  \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n>  \t\t\tfi\n>  \t\tfi\n> -\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n> +\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n>  \t\t(\n>  \t\t\tclear_local_git_env\n>  \t\t\tcd \"$sm_path\" &&\n> @@ -676,6 +686,14 @@ cmd_update()\n>  \t\t--checkout)\n>  \t\t\tupdate=\"checkout\"\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n>  \n>  \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n>  \t\tthen\n> -\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n> +\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n>  \t\t\tcloned_modules=\"$cloned_modules;$name\"\n>  \t\t\tsubsha1=\n>  \t\telse\n> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\n> index f47cc7b..bfd1ce9 100755\n> --- a/t/t7400-submodule-basic.sh\n> +++ b/t/t7400-submodule-basic.sh\n> @@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n>  \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n>  '\n>  \n> +test_expect_success 'submodule add clone shallow submodule' '\n> +\tmkdir super &&\n> +\tpwd=$(pwd)\n> +\t(\n> +\t\tcd super &&\n> +\t\tgit init &&\n> +\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n> +\t\t(\n> +\t\t\tcd submodule &&\n> +\t\t\ttest 1 = $(git log --oneline | wc -l)\n> +\t\t)\n> +\t)\n> +'\n> +\n> +\n>  test_done\n> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\n> index a4ffea0..e0a06e2 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n>  test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n>  \tmkdir -p linked/dir &&\n>  \tln -s linked/dir linkto &&\n> -\t(\n> -\t\tcd linkto &&\n> -\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> -\t\t(\n> -\t\t\tcd super &&\n> -\t\t\tgit submodule update --init --recursive\n> -\t\t)\n> +\t(cd linkto &&\n> +\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> +\t (cd super &&\n> +\t  git submodule update --init --recursive\n> +\t )\n>  \t)\n>  '\n>  \n> +test_expect_success 'submodule update clone shallow submodule' '\n> +\tgit clone cloned super3 &&\n> +\tpwd=$(pwd)\n> +\t(cd super3 &&\n> +\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n> +\t mv -f .gitmodules.tmp .gitmodules &&\n> +\t git submodule update --init --depth=3\n> +\t (cd submodule &&\n> +\t  test 1 = $(git log --oneline | wc -l)\n> +\t )\n> +\t)\n> +'\n>  test_done\n> \n"},{"id":"222385","messageId":"1372788530-19760-1-git-send-email-iveqy@iveqy.com","threadId":"34320","inReplyTo":"51D311F2.1030009@web.de","subject":"[PATCH v4] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-07-02T18:08:50Z","receivedAt":"2013-07-02T18:08:50Z","isPatch":true,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"Add the --depth option to the add and update commands of \"git submodule\",\nwhich is then passed on to the clone command. This is useful when the\nsubmodule(s) are huge and you're not really interested in anything but\nthe latest commit.\n\nTests are added and to make --depth work the path for test \"setup a submodule\ntree\" had to be modified. Also did some indent adjustments to conform to the\nrest of the testfile on \"submodule update can handle symbolic links in pwd\".\n\nSigned-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n---\n\n> The first line of the commit message still sounds strange to me, please see\n> my answer in the thread you quoted.\n>\n> Also the documentation still talks about --clone-depth.\n\nSorry about that, it's fixed in this patch\n\n> The assignment to reference right above that is quoted like that too. I wonder\n> if we should also use ${depth:+\"$depth\"} as argument to clone.\n\nI don't have any opinion about this. I guess it works the way it is, I just don't\nunderstand it according to the shell-syntax I know.\n\nIf we should fix it, perhaps fix it in an other patch together with $reference?\n\n Documentation/git-submodule.txt | 10 ++++++++--\n git-submodule.sh                | 24 +++++++++++++++++++++---\n t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n 4 files changed, 61 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex e576713..77a052a 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -10,12 +10,12 @@ SYNOPSIS\n --------\n [verse]\n 'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n-\t      [--reference <repository>] [--] <repository> [<path>]\n+\t      [--reference <repository>] [--clone-depth <depth>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n-\t      [-f|--force] [--rebase] [--reference <repository>]\n+\t      [-f|--force] [--rebase] [--reference <repository>] [--clone-depth <depth>]\n \t      [--merge] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n@@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n \tonly in the submodules of the current repo, but also\n \tin any nested submodules inside those submodules (and so on).\n \n+--depth::\n+\tThis option is valid for add and update commands. Create a 'shallow'\n+\tclone with a history truncated to the specified number of revisions.\n+\tSee linkgit:git-clone[1]\n+\n+\n <path>...::\n \tPaths to submodule(s). When specified this will restrict the command\n \tto only operate on the submodules found at the specified paths.\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 79bfaac..1cfe2bf 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -32,6 +32,7 @@ nofetch=\n update=\n prefix=\n custom_name=\n+depth=\n \n # The function takes at most 2 arguments. The first argument is the\n # URL that navigates to the submodule origin repo. When relative, this URL\n@@ -211,6 +212,7 @@ module_clone()\n \tname=$2\n \turl=$3\n \treference=\"$4\"\n+\tdepth=\"$5\"\n \tquiet=\n \tif test -n \"$GIT_QUIET\"\n \tthen\n@@ -233,7 +235,7 @@ module_clone()\n \t\tmkdir -p \"$gitdir_base\"\n \t\t(\n \t\t\tclear_local_git_env\n-\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n+\t\t\tgit clone $quiet $depth -n ${reference:+\"$reference\"} \\\n \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n \t\t) ||\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n@@ -309,6 +311,14 @@ cmd_add()\n \t\t\tcustom_name=$2\n \t\t\tshift\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n \t\t\tfi\n \t\tfi\n-\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n+\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n \t\t(\n \t\t\tclear_local_git_env\n \t\t\tcd \"$sm_path\" &&\n@@ -676,6 +686,14 @@ cmd_update()\n \t\t--checkout)\n \t\t\tupdate=\"checkout\"\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n \n \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n+\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n \t\t\tcloned_modules=\"$cloned_modules;$name\"\n \t\t\tsubsha1=\n \t\telse\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex f47cc7b..bfd1ce9 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n '\n \n+test_expect_success 'submodule add clone shallow submodule' '\n+\tmkdir super &&\n+\tpwd=$(pwd)\n+\t(\n+\t\tcd super &&\n+\t\tgit init &&\n+\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n+\t\t(\n+\t\t\tcd submodule &&\n+\t\t\ttest 1 = $(git log --oneline | wc -l)\n+\t\t)\n+\t)\n+'\n+\n+\n test_done\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex a4ffea0..e0a06e2 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n \tmkdir -p linked/dir &&\n \tln -s linked/dir linkto &&\n-\t(\n-\t\tcd linkto &&\n-\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n-\t\t(\n-\t\t\tcd super &&\n-\t\t\tgit submodule update --init --recursive\n-\t\t)\n+\t(cd linkto &&\n+\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n+\t (cd super &&\n+\t  git submodule update --init --recursive\n+\t )\n \t)\n '\n \n+test_expect_success 'submodule update clone shallow submodule' '\n+\tgit clone cloned super3 &&\n+\tpwd=$(pwd)\n+\t(cd super3 &&\n+\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n+\t mv -f .gitmodules.tmp .gitmodules &&\n+\t git submodule update --init --depth=3\n+\t (cd submodule &&\n+\t  test 1 = $(git log --oneline | wc -l)\n+\t )\n+\t)\n+'\n test_done\n-- \n1.8.3.1.490.g39d9b24.dirty\n"},{"id":"222390","messageId":"7v7gh8947e.fsf@alter.siamese.dyndns.org","threadId":"34320","inReplyTo":"1372729167-23200-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v3] [submodule] Add --depth to submodule update/add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-02T19:01:09Z","receivedAt":"2013-07-02T19:01:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Fredrik Gustafsson <iveqy@iveqy.com> writes:\n\n> git clone dies with the error \"too many arguments\". This was solved with changing\n> depth=$5\n> to\n> depth=\"$5\"\n>\n> which I don't understand since variable assignment doesn't expand $5 and therefore\n> \"\" should not be needed, AFAIK. Any comments on this?\n\nA red herring?\n\n> @@ -211,6 +212,7 @@ module_clone()\n>  \tname=$2\n>  \turl=$3\n>  \treference=\"$4\"\n> +\tdepth=\"$5\"\n\nIf the caller gave you only 4 arguments, depth will become an empty\nstring with or without dq around $5 here.  And\n\n> -\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> +\t\t\tgit clone $quiet $depth -n ${reference:+\"$reference\"} \\\n>  \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n\n... you use $depth without dq around it, so when $depth is empty\nstring, \"git clone\" will not see it at all (not even an empty string\nas one of its arguments).\n\nWhich is probably fine, as long as the caller makes sure it will not\ncall this function as\n\n\tmodule_clone 1 2 3 4 \"depth argument as multi-word\"\n\nwhich will be split at $IFS.\n\nIf you know $depth must be passed as a single argument (or no\nargument when the caller did not give you any) to the underlying\n\"git clone\", you can write it like so:\n\n\t\t...\n\t\tdepth=$5\n\t\t...\n\n\t\tgit clone $quiet ${depth:+\"$depth\"} -n ...\n"},{"id":"222404","messageId":"51D342BB.8080907@web.de","threadId":"34320","inReplyTo":"1372788530-19760-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v4] [submodule] Add --depth to submodule update/add","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2013-07-02T21:14:35Z","receivedAt":"2013-07-02T21:14:35Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 02.07.2013 20:08, schrieb Fredrik Gustafsson:\n> Add the --depth option to the add and update commands of \"git submodule\",\n> which is then passed on to the clone command. This is useful when the\n> submodule(s) are huge and you're not really interested in anything but\n> the latest commit.\n> \n> Tests are added and to make --depth work the path for test \"setup a submodule\n> tree\" had to be modified. Also did some indent adjustments to conform to the\n> rest of the testfile on \"submodule update can handle symbolic links in pwd\".\n\nIf I see that correctly no test setup is modified anymore (which is good).\nI think this paragraph should read:\n\n  Tests are added and some indention adjustments were made to conform to the\n  rest of the testfile on \"submodule update can handle symbolic links in pwd\".\n\n> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n> ---\n> \n>> The first line of the commit message still sounds strange to me, please see\n>> my answer in the thread you quoted.\n>>\n>> Also the documentation still talks about --clone-depth.\n> \n> Sorry about that, it's fixed in this patch\n\nExcept for the synopsis ;-)\n\n>> The assignment to reference right above that is quoted like that too. I wonder\n>> if we should also use ${depth:+\"$depth\"} as argument to clone.\n> \n> I don't have any opinion about this. I guess it works the way it is, I just don't\n> understand it according to the shell-syntax I know.\n> \n> If we should fix it, perhaps fix it in an other patch together with $reference?\n\nLike Junio said in his email, let's just use this:\n\n\t\tdepth=$5\n\t\t...\n\n\t\tgit clone $quiet ${depth:+\"$depth\"} -n ...\n\n(But for me the reference example shows that quoting $5 should do no harm\nhere, and for consistency I would prefer using 'depth=\"$5\"' here too)\n\n>  Documentation/git-submodule.txt | 10 ++++++++--\n>  git-submodule.sh                | 24 +++++++++++++++++++++---\n>  t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n>  t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n>  4 files changed, 61 insertions(+), 12 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index e576713..77a052a 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -10,12 +10,12 @@ SYNOPSIS\n>  --------\n>  [verse]\n>  'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n> -\t      [--reference <repository>] [--] <repository> [<path>]\n> +\t      [--reference <repository>] [--clone-depth <depth>] [--] <repository> [<path>]\n\ns/--clone-depth/--depth/\n\n>  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] init [--] [<path>...]\n>  'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n>  'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n> -\t      [-f|--force] [--rebase] [--reference <repository>]\n> +\t      [-f|--force] [--rebase] [--reference <repository>] [--clone-depth <depth>]\n\ns/--clone-depth/--depth/\n\n>  \t      [--merge] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n>  \t      [commit] [--] [<path>...]\n> @@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n>  \tonly in the submodules of the current repo, but also\n>  \tin any nested submodules inside those submodules (and so on).\n>  \n> +--depth::\n> +\tThis option is valid for add and update commands. Create a 'shallow'\n> +\tclone with a history truncated to the specified number of revisions.\n> +\tSee linkgit:git-clone[1]\n> +\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n>  \tto only operate on the submodules found at the specified paths.\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 79bfaac..1cfe2bf 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -32,6 +32,7 @@ nofetch=\n>  update=\n>  prefix=\n>  custom_name=\n> +depth=\n>  \n>  # The function takes at most 2 arguments. The first argument is the\n>  # URL that navigates to the submodule origin repo. When relative, this URL\n> @@ -211,6 +212,7 @@ module_clone()\n>  \tname=$2\n>  \turl=$3\n>  \treference=\"$4\"\n> +\tdepth=\"$5\"\n>  \tquiet=\n>  \tif test -n \"$GIT_QUIET\"\n>  \tthen\n> @@ -233,7 +235,7 @@ module_clone()\n>  \t\tmkdir -p \"$gitdir_base\"\n>  \t\t(\n>  \t\t\tclear_local_git_env\n> -\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> +\t\t\tgit clone $quiet $depth -n ${reference:+\"$reference\"} \\\n>  \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n>  \t\t) ||\n>  \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n> @@ -309,6 +311,14 @@ cmd_add()\n>  \t\t\tcustom_name=$2\n>  \t\t\tshift\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n>  \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n>  \t\t\tfi\n>  \t\tfi\n> -\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n> +\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n>  \t\t(\n>  \t\t\tclear_local_git_env\n>  \t\t\tcd \"$sm_path\" &&\n> @@ -676,6 +686,14 @@ cmd_update()\n>  \t\t--checkout)\n>  \t\t\tupdate=\"checkout\"\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n>  \n>  \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n>  \t\tthen\n> -\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n> +\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n>  \t\t\tcloned_modules=\"$cloned_modules;$name\"\n>  \t\t\tsubsha1=\n>  \t\telse\n> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\n> index f47cc7b..bfd1ce9 100755\n> --- a/t/t7400-submodule-basic.sh\n> +++ b/t/t7400-submodule-basic.sh\n> @@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n>  \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n>  '\n>  \n> +test_expect_success 'submodule add clone shallow submodule' '\n> +\tmkdir super &&\n> +\tpwd=$(pwd)\n> +\t(\n> +\t\tcd super &&\n> +\t\tgit init &&\n> +\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n> +\t\t(\n> +\t\t\tcd submodule &&\n> +\t\t\ttest 1 = $(git log --oneline | wc -l)\n> +\t\t)\n> +\t)\n> +'\n> +\n> +\n>  test_done\n> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\n> index a4ffea0..e0a06e2 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n>  test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n>  \tmkdir -p linked/dir &&\n>  \tln -s linked/dir linkto &&\n> -\t(\n> -\t\tcd linkto &&\n> -\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> -\t\t(\n> -\t\t\tcd super &&\n> -\t\t\tgit submodule update --init --recursive\n> -\t\t)\n> +\t(cd linkto &&\n> +\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> +\t (cd super &&\n> +\t  git submodule update --init --recursive\n> +\t )\n>  \t)\n>  '\n>  \n> +test_expect_success 'submodule update clone shallow submodule' '\n> +\tgit clone cloned super3 &&\n> +\tpwd=$(pwd)\n> +\t(cd super3 &&\n> +\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n> +\t mv -f .gitmodules.tmp .gitmodules &&\n> +\t git submodule update --init --depth=3\n> +\t (cd submodule &&\n> +\t  test 1 = $(git log --oneline | wc -l)\n> +\t )\n> +\t)\n> +'\n>  test_done\n> \n"},{"id":"222407","messageId":"1372801376-32673-1-git-send-email-iveqy@iveqy.com","threadId":"34320","inReplyTo":"51D342BB.8080907@web.de","subject":"[PATCH v5] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-07-02T21:42:56Z","receivedAt":"2013-07-02T21:42:56Z","isPatch":true,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"Add the --depth option to the add and update commands of \"git submodule\",\nwhich is then passed on to the clone command. This is useful when the\nsubmodule(s) are huge and you're not really interested in anything but\nthe latest commit.\n\nTests are added and some indention adjustments were made to conform to the\nrest of the testfile on \"submodule update can handle symbolic links in pwd\".\n\nSigned-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n---\n\nAnd I finally thought I'd everything right. I appriciate your reviews.\n\nI left the \"\" on $5 for consistency as suggested.\n\n Documentation/git-submodule.txt | 10 ++++++++--\n git-submodule.sh                | 24 +++++++++++++++++++++---\n t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n 4 files changed, 61 insertions(+), 12 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex e576713..605419f 100644\n--- a/Documentation/git-submodule.txt\n+++ b/Documentation/git-submodule.txt\n@@ -10,12 +10,12 @@ SYNOPSIS\n --------\n [verse]\n 'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n-\t      [--reference <repository>] [--] <repository> [<path>]\n+\t      [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]\n 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] init [--] [<path>...]\n 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n-\t      [-f|--force] [--rebase] [--reference <repository>]\n+\t      [-f|--force] [--rebase] [--reference <repository>] [--depth <depth>]\n \t      [--merge] [--recursive] [--] [<path>...]\n 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n \t      [commit] [--] [<path>...]\n@@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n \tonly in the submodules of the current repo, but also\n \tin any nested submodules inside those submodules (and so on).\n \n+--depth::\n+\tThis option is valid for add and update commands. Create a 'shallow'\n+\tclone with a history truncated to the specified number of revisions.\n+\tSee linkgit:git-clone[1]\n+\n+\n <path>...::\n \tPaths to submodule(s). When specified this will restrict the command\n \tto only operate on the submodules found at the specified paths.\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 79bfaac..2458e1f 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -32,6 +32,7 @@ nofetch=\n update=\n prefix=\n custom_name=\n+depth=\n \n # The function takes at most 2 arguments. The first argument is the\n # URL that navigates to the submodule origin repo. When relative, this URL\n@@ -211,6 +212,7 @@ module_clone()\n \tname=$2\n \turl=$3\n \treference=\"$4\"\n+\tdepth=\"$5\"\n \tquiet=\n \tif test -n \"$GIT_QUIET\"\n \tthen\n@@ -233,7 +235,7 @@ module_clone()\n \t\tmkdir -p \"$gitdir_base\"\n \t\t(\n \t\t\tclear_local_git_env\n-\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n+\t\t\tgit clone $quiet ${depth:+\"$depth\"} -n ${reference:+\"$reference\"} \\\n \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n \t\t) ||\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n@@ -309,6 +311,14 @@ cmd_add()\n \t\t\tcustom_name=$2\n \t\t\tshift\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n \t\t\tfi\n \t\tfi\n-\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n+\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n \t\t(\n \t\t\tclear_local_git_env\n \t\t\tcd \"$sm_path\" &&\n@@ -676,6 +686,14 @@ cmd_update()\n \t\t--checkout)\n \t\t\tupdate=\"checkout\"\n \t\t\t;;\n+\t\t--depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tdepth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--depth=*)\n+\t\t\tdepth=$1\n+\t\t\t;;\n \t\t--)\n \t\t\tshift\n \t\t\tbreak\n@@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n \n \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n \t\tthen\n-\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n+\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n \t\t\tcloned_modules=\"$cloned_modules;$name\"\n \t\t\tsubsha1=\n \t\telse\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex f47cc7b..bfd1ce9 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n '\n \n+test_expect_success 'submodule add clone shallow submodule' '\n+\tmkdir super &&\n+\tpwd=$(pwd)\n+\t(\n+\t\tcd super &&\n+\t\tgit init &&\n+\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n+\t\t(\n+\t\t\tcd submodule &&\n+\t\t\ttest 1 = $(git log --oneline | wc -l)\n+\t\t)\n+\t)\n+'\n+\n+\n test_done\ndiff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\nindex a4ffea0..e0a06e2 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n \tmkdir -p linked/dir &&\n \tln -s linked/dir linkto &&\n-\t(\n-\t\tcd linkto &&\n-\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n-\t\t(\n-\t\t\tcd super &&\n-\t\t\tgit submodule update --init --recursive\n-\t\t)\n+\t(cd linkto &&\n+\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n+\t (cd super &&\n+\t  git submodule update --init --recursive\n+\t )\n \t)\n '\n \n+test_expect_success 'submodule update clone shallow submodule' '\n+\tgit clone cloned super3 &&\n+\tpwd=$(pwd)\n+\t(cd super3 &&\n+\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n+\t mv -f .gitmodules.tmp .gitmodules &&\n+\t git submodule update --init --depth=3\n+\t (cd submodule &&\n+\t  test 1 = $(git log --oneline | wc -l)\n+\t )\n+\t)\n+'\n test_done\n-- \n1.8.3.1.490.g39d9b24.dirty\n"},{"id":"222433","messageId":"51D3D20A.5000700@web.de","threadId":"34320","inReplyTo":"1372801376-32673-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v5] [submodule] Add --depth to submodule update/add","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2013-07-03T07:26:02Z","receivedAt":"2013-07-03T07:26:02Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 02.07.2013 23:42, schrieb Fredrik Gustafsson:\n> Add the --depth option to the add and update commands of \"git submodule\",\n> which is then passed on to the clone command. This is useful when the\n> submodule(s) are huge and you're not really interested in anything but\n> the latest commit.\n> \n> Tests are added and some indention adjustments were made to conform to the\n> rest of the testfile on \"submodule update can handle symbolic links in pwd\".\n> \n> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n> ---\n> \n> And I finally thought I'd everything right. I appriciate your reviews.\n> \n> I left the \"\" on $5 for consistency as suggested.\n\nThanks, looking good to me. Passes all tests and the new tests fail\nwhen the change in the submodule script is reverted.\n\nAcked-by: Jens Lehmann <Jens.Lehmann@web.de>\n\nThe only minor problem is that this patch still does not apply cleanly\nto master, next or pu (I wonder what you based this on ;-). I had to\nchange the hunk for t7400 to this to make it apply to master:\n\ndiff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\nindex 50e6ad7..a055b46 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -963,4 +963,19 @@ test_expect_success 'submodule with UTF-8 name' '\n        git submodule >&2 &&\n        test -n \"$(git submodule | grep \"$svname\")\"\n '\n+\n+test_expect_success 'submodule add clone shallow submodule' '\n+       mkdir super &&\n+       pwd=$(pwd)\n+       (\n+               cd super &&\n+               git init &&\n+               git submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n+               (\n+                       cd submodule &&\n+                       test 1 = $(git log --oneline | wc -l)\n+               )\n+       )\n+'\n+\n test_done\n\n\n>  Documentation/git-submodule.txt | 10 ++++++++--\n>  git-submodule.sh                | 24 +++++++++++++++++++++---\n>  t/t7400-submodule-basic.sh      | 15 +++++++++++++++\n>  t/t7406-submodule-update.sh     | 24 +++++++++++++++++-------\n>  4 files changed, 61 insertions(+), 12 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index e576713..605419f 100644\n> --- a/Documentation/git-submodule.txt\n> +++ b/Documentation/git-submodule.txt\n> @@ -10,12 +10,12 @@ SYNOPSIS\n>  --------\n>  [verse]\n>  'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]\n> -\t      [--reference <repository>] [--] <repository> [<path>]\n> +\t      [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]\n>  'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] init [--] [<path>...]\n>  'git submodule' [--quiet] deinit [-f|--force] [--] <path>...\n>  'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]\n> -\t      [-f|--force] [--rebase] [--reference <repository>]\n> +\t      [-f|--force] [--rebase] [--reference <repository>] [--depth <depth>]\n>  \t      [--merge] [--recursive] [--] [<path>...]\n>  'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]\n>  \t      [commit] [--] [<path>...]\n> @@ -328,6 +328,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.\n>  \tonly in the submodules of the current repo, but also\n>  \tin any nested submodules inside those submodules (and so on).\n>  \n> +--depth::\n> +\tThis option is valid for add and update commands. Create a 'shallow'\n> +\tclone with a history truncated to the specified number of revisions.\n> +\tSee linkgit:git-clone[1]\n> +\n> +\n>  <path>...::\n>  \tPaths to submodule(s). When specified this will restrict the command\n>  \tto only operate on the submodules found at the specified paths.\n> diff --git a/git-submodule.sh b/git-submodule.sh\n> index 79bfaac..2458e1f 100755\n> --- a/git-submodule.sh\n> +++ b/git-submodule.sh\n> @@ -32,6 +32,7 @@ nofetch=\n>  update=\n>  prefix=\n>  custom_name=\n> +depth=\n>  \n>  # The function takes at most 2 arguments. The first argument is the\n>  # URL that navigates to the submodule origin repo. When relative, this URL\n> @@ -211,6 +212,7 @@ module_clone()\n>  \tname=$2\n>  \turl=$3\n>  \treference=\"$4\"\n> +\tdepth=\"$5\"\n>  \tquiet=\n>  \tif test -n \"$GIT_QUIET\"\n>  \tthen\n> @@ -233,7 +235,7 @@ module_clone()\n>  \t\tmkdir -p \"$gitdir_base\"\n>  \t\t(\n>  \t\t\tclear_local_git_env\n> -\t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> +\t\t\tgit clone $quiet ${depth:+\"$depth\"} -n ${reference:+\"$reference\"} \\\n>  \t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n>  \t\t) ||\n>  \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n> @@ -309,6 +311,14 @@ cmd_add()\n>  \t\t\tcustom_name=$2\n>  \t\t\tshift\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -405,7 +415,7 @@ Use -f if you really want to add it.\" >&2\n>  \t\t\t\techo \"$(eval_gettext \"Reactivating local git directory for submodule '\\$sm_name'.\")\"\n>  \t\t\tfi\n>  \t\tfi\n> -\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" || exit\n> +\t\tmodule_clone \"$sm_path\" \"$sm_name\" \"$realrepo\" \"$reference\" \"$depth\" || exit\n>  \t\t(\n>  \t\t\tclear_local_git_env\n>  \t\t\tcd \"$sm_path\" &&\n> @@ -676,6 +686,14 @@ cmd_update()\n>  \t\t--checkout)\n>  \t\t\tupdate=\"checkout\"\n>  \t\t\t;;\n> +\t\t--depth)\n> +\t\t\tcase \"$2\" in '') usage ;; esac\n> +\t\t\tdepth=\"--depth=$2\"\n> +\t\t\tshift\n> +\t\t\t;;\n> +\t\t--depth=*)\n> +\t\t\tdepth=$1\n> +\t\t\t;;\n>  \t\t--)\n>  \t\t\tshift\n>  \t\t\tbreak\n> @@ -735,7 +753,7 @@ Maybe you want to use 'update --init'?\")\"\n>  \n>  \t\tif ! test -d \"$sm_path\"/.git -o -f \"$sm_path\"/.git\n>  \t\tthen\n> -\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" || exit\n> +\t\t\tmodule_clone \"$sm_path\" \"$name\" \"$url\" \"$reference\" \"$depth\" || exit\n>  \t\t\tcloned_modules=\"$cloned_modules;$name\"\n>  \t\t\tsubsha1=\n>  \t\telse\n> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh\n> index f47cc7b..bfd1ce9 100755\n> --- a/t/t7400-submodule-basic.sh\n> +++ b/t/t7400-submodule-basic.sh\n> @@ -868,4 +868,19 @@ test_expect_success 'submodule deinit fails when submodule has a .git directory\n>  \ttest -n \"$(git config --get-regexp \"submodule\\.example\\.\")\"\n>  '\n>  \n> +test_expect_success 'submodule add clone shallow submodule' '\n> +\tmkdir super &&\n> +\tpwd=$(pwd)\n> +\t(\n> +\t\tcd super &&\n> +\t\tgit init &&\n> +\t\tgit submodule add --depth=1 file://\"$pwd\"/example2 submodule &&\n> +\t\t(\n> +\t\t\tcd submodule &&\n> +\t\t\ttest 1 = $(git log --oneline | wc -l)\n> +\t\t)\n> +\t)\n> +'\n> +\n> +\n>  test_done\n> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\n> index a4ffea0..e0a06e2 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -685,14 +685,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '\n>  test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '\n>  \tmkdir -p linked/dir &&\n>  \tln -s linked/dir linkto &&\n> -\t(\n> -\t\tcd linkto &&\n> -\t\tgit clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> -\t\t(\n> -\t\t\tcd super &&\n> -\t\t\tgit submodule update --init --recursive\n> -\t\t)\n> +\t(cd linkto &&\n> +\t git clone \"$TRASH_DIRECTORY\"/super_update_r2 super &&\n> +\t (cd super &&\n> +\t  git submodule update --init --recursive\n> +\t )\n>  \t)\n>  '\n>  \n> +test_expect_success 'submodule update clone shallow submodule' '\n> +\tgit clone cloned super3 &&\n> +\tpwd=$(pwd)\n> +\t(cd super3 &&\n> +\t sed -e \"s#url = ../#url = file://$pwd/#\" <.gitmodules >.gitmodules.tmp &&\n> +\t mv -f .gitmodules.tmp .gitmodules &&\n> +\t git submodule update --init --depth=3\n> +\t (cd submodule &&\n> +\t  test 1 = $(git log --oneline | wc -l)\n> +\t )\n> +\t)\n> +'\n>  test_done\n> \n"},{"id":"222436","messageId":"7v4ncchxif.fsf@alter.siamese.dyndns.org","threadId":"34320","inReplyTo":"51D3D20A.5000700@web.de","subject":"Re: [PATCH v5] [submodule] Add --depth to submodule update/add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-03T08:13:12Z","receivedAt":"2013-07-03T08:13:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> Am 02.07.2013 23:42, schrieb Fredrik Gustafsson:\n>> Add the --depth option to the add and update commands of \"git submodule\",\n>> which is then passed on to the clone command. This is useful when the\n>> submodule(s) are huge and you're not really interested in anything but\n>> the latest commit.\n>> \n>> Tests are added and some indention adjustments were made to conform to the\n>> rest of the testfile on \"submodule update can handle symbolic links in pwd\".\n>> \n>> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n>> ---\n>> \n>> And I finally thought I'd everything right. I appriciate your reviews.\n>> \n>> I left the \"\" on $5 for consistency as suggested.\n>\n> Thanks, looking good to me. Passes all tests and the new tests fail\n> when the change in the submodule script is reverted.\n>\n> Acked-by: Jens Lehmann <Jens.Lehmann@web.de>\n\n> The only minor problem is that this patch still does not apply cleanly\n> to master, next or pu (I wonder what you based this on ;-).\n\nThanks; will replace what I queued on 'pu'.\n"},{"id":"222440","messageId":"20130703083800.GB22216@paksenarrion.iveqy.com","threadId":"34320","inReplyTo":"7v4ncchxif.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v5] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-07-03T08:38:00Z","receivedAt":"2013-07-03T08:38:00Z","isPatch":true,"sender":{"key":"iveqy@iveqy.com","avatar":"https://avatars.githubusercontent.com/u/761743?v=4"},"body":"On Wed, Jul 03, 2013 at 01:13:12AM -0700, Junio C Hamano wrote:\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n> > The only minor problem is that this patch still does not apply cleanly\n> > to master, next or pu (I wonder what you based this on ;-).\n> \n> Thanks; will replace what I queued on 'pu'.\n\nI based it on master, but have forgott to rebase since v2. This is based\non 3e7a5b489e45ae8a3a0b222893d58b172d883136.\n\nThe merge conflict is pretty clean, would you (Junio) stil like a\nrebased update of this patch?\n\n-- \nMed vänliga hälsningar\nFredrik Gustafsson\n\ntel: 0733-608274\ne-post: iveqy@iveqy.com\n"},{"id":"222473","messageId":"7vvc4rfsud.fsf@alter.siamese.dyndns.org","threadId":"34320","inReplyTo":"51D3D20A.5000700@web.de","subject":"Re: [PATCH v5] [submodule] Add --depth to submodule update/add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-07-03T17:36:58Z","receivedAt":"2013-07-03T17:36:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> The only minor problem is that this patch still does not apply cleanly\n> to master, next or pu (I wonder what you based this on ;-).\n\nOlder iteration of the topic has been queued directly on top of\nv1.8.3.  When I replace a topic with its new version, I try to\nrebuild on the same base.\n\nThis is primarily out of habit, but it makes comparison between the\ntwo versions easier, and also \"show-branch -g\" output looks sane.\n\nThe workflow goes like this:\n\n\t: quick-glance the old iteration\n\t$ git log --boundary --oneline master..fg/submodule-clone-depth\n\n        : can we rewind?  compare with the previous one for 'master'\n        $ git log --boundary --oneline next..fg/submodule-clone-depth\n        : if nothing has been merged to 'next', we can continue...\n\n\t: detach at the old base\n\t$ git checkout master...fg/submodule-clone-depth\n\n        : apply\n        $ git am -s3 ./+fg-submodule-clone-depth.mbox\n\n        : inspect\n        $ git show-branch @{-1} HEAD\n        $ git diff @{-1}\n\n\t: replace\n        $ git branch -f @{-1}\n"}]}