{"thread":{"id":"34304","subject":"[PATCH --clone-depth version] [submodule] Add --depth to submodule update/add","startedAt":"2013-06-28T21:45:24Z","lastAt":"2013-06-28T21:45:24Z","messageCount":1,"participants":["Fredrik Gustafsson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"222220","messageId":"1372455924-17420-1-git-send-email-iveqy@iveqy.com","threadId":"34304","inReplyTo":null,"subject":"[PATCH --clone-depth version] [submodule] Add --depth to submodule update/add","fromName":"Fredrik Gustafsson","fromEmail":"iveqy@iveqy.com","sentAt":"2013-06-28T21:45:24Z","receivedAt":"2013-06-28T21:45:24Z","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\nI neither have an opinion about what word to use. --depth is more\nconsistent and easier to code. But also eaiser to be confused about.\n\nHere is a --clone-depth version of the patch. Nothing else is changed.\nPlease take the one thats most suited.\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..41b9610 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,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+--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+\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..0a949d1 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+clone_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+\tclone_depth=$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\" $clone_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--clone-depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tclone_depth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--clone-depth=*)\n+\t\t\tclone_depth=\"$(echo $1 | sed -e 's/^--clone/-/')\"\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\" \"$clone_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--clone-depth)\n+\t\t\tcase \"$2\" in '') usage ;; esac\n+\t\t\tclone_depth=\"--depth=$2\"\n+\t\t\tshift\n+\t\t\t;;\n+\t\t--clone-depth=*)\n+\t\t\tclone_depth=\"$(echo $1 | sed -e 's/^--clone/-/')\"\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\" \"$clone_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..7a44059 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 --clone-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..d52df37 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 --clone-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"}]}