{"thread":{"id":"34296","subject":"[PATCH v2] [submodule] Add --depth to submodule update/add","startedAt":"2013-06-28T13:22:26Z","lastAt":"2013-06-28T21:41:24Z","messageCount":3,"participants":["Fredrik Gustafsson","Junio C Hamano","Jens Lehmann"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"222172","messageId":"1372425746-11513-1-git-send-email-iveqy@iveqy.com","threadId":"34296","inReplyTo":null,"subject":"[PATCH v2] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-06-28T13:22:26Z","receivedAt":"2013-06-28T13:22:26Z","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 Documentation/git-submodule.txt | 13 +++++++++++--\n git-submodule.sh                | 24 +++++++++++++++++++++---\n t/t7400-submodule-basic.sh      | 18 ++++++++++++++++++\n t/t7406-submodule-update.sh     | 28 ++++++++++++++++++++--------\n 4 files changed, 70 insertions(+), 13 deletions(-)\n\ndiff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\nindex e576713..b17001a 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,15 @@ 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+\tA shallow repository has a number of limitations (you cannot clone\n+\tor fetch from it, nor push from nor into it), but is adequate if\n+\tyou are only interested in the recent history of a large project\n+\twith a long history.\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..c99bc7c 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@@ -234,7 +236,7 @@ module_clone()\n \t\t(\n \t\t\tclear_local_git_env\n \t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n-\t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n+\t\t\t\t--separate-git-dir \"$gitdir\" $depth \"$url\" \"$sm_path\"\n \t\t) ||\n \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n \tfi\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..4502320 100755\n--- a/t/t7400-submodule-basic.sh\n+++ b/t/t7400-submodule-basic.sh\n@@ -868,4 +868,22 @@ 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\tif test $(git log --oneline | wc -l) != 1\n+\t\t\tthen\n+\t\t\t\texit 1\n+\t\t\tfi\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..b2d0f0e 100755\n--- a/t/t7406-submodule-update.sh\n+++ b/t/t7406-submodule-update.sh\n@@ -31,8 +31,9 @@ test_expect_success 'setup a submodule tree' '\n \tgit clone super rebasing &&\n \tgit clone super merging &&\n \tgit clone super none &&\n+\tpwd=$(pwd)\n \t(cd super &&\n-\t git submodule add ../submodule submodule &&\n+\t git submodule add file:///\"$pwd\"/submodule submodule &&\n \t test_tick &&\n \t git commit -m \"submodule\" &&\n \t git submodule init submodule\n@@ -685,14 +686,25 @@ 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+\t(cd super3 &&\n+\t git submodule init &&\n+\t git submodule update --depth=3 &&\n+\t (cd submodule &&\n+\t  if test $(git log --oneline | wc -l) != 1\n+\t  then\n+\t   exit 1\n+\t  fi\n+\t )\n+\t)\n+'\n test_done\n-- \n1.8.3.1.489.gbc4ad7e.dirty\n"},{"id":"222218","messageId":"7vd2r5ncao.fsf@alter.siamese.dyndns.org","threadId":"34296","inReplyTo":"1372425746-11513-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v2] [submodule] Add --depth to submodule update/add","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-28T21:41:19Z","receivedAt":"2013-06-28T21:41:19Z","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> diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh\n> index a4ffea0..b2d0f0e 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -31,8 +31,9 @@ test_expect_success 'setup a submodule tree' '\n>  \tgit clone super rebasing &&\n>  \tgit clone super merging &&\n>  \tgit clone super none &&\n> +\tpwd=$(pwd)\n\nBroken &&-chain (will locally amend later but not today).\n\nThanks.\n"},{"id":"222219","messageId":"51CE0304.60504@web.de","threadId":"34296","inReplyTo":"1372425746-11513-1-git-send-email-iveqy@iveqy.com","subject":"Re: [PATCH v2] [submodule] Add --depth to submodule update/add","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2013-06-28T21:41:24Z","receivedAt":"2013-06-28T21:41:24Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Apparently due to a newly added test at the end of t7400 this patch doesn't\napply cleanly to neither pu, next nor master for me. But it addresses all\nissues raised in the first round.\n\nAm 28.06.2013 15:22, schrieb Fredrik Gustafsson:\n> When a submodule is clone, clone it width the --depth flag. This is useful\n\nMaybe rephrase this as:\nAdd the --depth option to the add and update commands of \"git submodule\",\nwhich is then passed on to the clone command. This is useful e.g.\n\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\nHaving to change existing tests is looking a bit fishy to me. Maybe just\nsed the URLs into the file:// form requested by \"clone --depth\" right after\ncloning the superproject in t7406?\n\n> Signed-off-by: Fredrik Gustafsson <iveqy@iveqy.com>\n> ---\n>  Documentation/git-submodule.txt | 13 +++++++++++--\n>  git-submodule.sh                | 24 +++++++++++++++++++++---\n>  t/t7400-submodule-basic.sh      | 18 ++++++++++++++++++\n>  t/t7406-submodule-update.sh     | 28 ++++++++++++++++++++--------\n>  4 files changed, 70 insertions(+), 13 deletions(-)\n> \n> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt\n> index e576713..b17001a 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,15 @@ 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> +\tA shallow repository has a number of limitations (you cannot clone\n> +\tor fetch from it, nor push from nor into it), but is adequate if\n> +\tyou are only interested in the recent history of a large project\n> +\twith a long history.\n\nNice description, only a \"linkgit:git-clone[1]\" would be nice here.\n\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..c99bc7c 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> @@ -234,7 +236,7 @@ module_clone()\n>  \t\t(\n>  \t\t\tclear_local_git_env\n>  \t\t\tgit clone $quiet -n ${reference:+\"$reference\"} \\\n> -\t\t\t\t--separate-git-dir \"$gitdir\" \"$url\" \"$sm_path\"\n> +\t\t\t\t--separate-git-dir \"$gitdir\" $depth \"$url\" \"$sm_path\"\n\nMaybe also quote $depth here (even though that shouldn't be necessary\nbecause it never should contain spaces, I'd prefer being consistent here).\n\n>  \t\t) ||\n>  \t\tdie \"$(eval_gettext \"Clone of '\\$url' into submodule path '\\$sm_path' failed\")\"\n>  \tfi\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..4502320 100755\n> --- a/t/t7400-submodule-basic.sh\n> +++ b/t/t7400-submodule-basic.sh\n> @@ -868,4 +868,22 @@ 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\tif test $(git log --oneline | wc -l) != 1\n> +\t\t\tthen\n> +\t\t\t\texit 1\n> +\t\t\tfi\n\n>From looking at other tests the following would be preferable (and shorter):\n\n    test 1 = $(git log --oneline | wc -l)\n\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..b2d0f0e 100755\n> --- a/t/t7406-submodule-update.sh\n> +++ b/t/t7406-submodule-update.sh\n> @@ -31,8 +31,9 @@ test_expect_success 'setup a submodule tree' '\n>  \tgit clone super rebasing &&\n>  \tgit clone super merging &&\n>  \tgit clone super none &&\n> +\tpwd=$(pwd)\n>  \t(cd super &&\n> -\t git submodule add ../submodule submodule &&\n> +\t git submodule add file:///\"$pwd\"/submodule submodule &&\n>  \t test_tick &&\n>  \t git commit -m \"submodule\" &&\n>  \t git submodule init submodule\n> @@ -685,14 +686,25 @@ 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> +\t(cd super3 &&\n> +\t git submodule init &&\n> +\t git submodule update --depth=3 &&\n> +\t (cd submodule &&\n> +\t  if test $(git log --oneline | wc -l) != 1\n> +\t  then\n> +\t   exit 1\n> +\t  fi\n\nSee above.\n\n> +\t )\n> +\t)\n> +'\n>  test_done\n> \n"}]}