Merge branch 'fg/submodule-clone-depth'

Allow shallow-cloning of submodules with "git submodule update".

* fg/submodule-clone-depth:
  Add --depth to submodule update/add
This commit is contained in:
Junio C Hamano 2013-07-15 10:28:48 -07:00
commit 2bb7aface6
4 changed files with 62 additions and 12 deletions

View File

@ -10,12 +10,12 @@ SYNOPSIS
-------- --------
[verse] [verse]
'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>] 'git submodule' [--quiet] add [-b <branch>] [-f|--force] [--name <name>]
[--reference <repository>] [--] <repository> [<path>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...] 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
'git submodule' [--quiet] init [--] [<path>...] 'git submodule' [--quiet] init [--] [<path>...]
'git submodule' [--quiet] deinit [-f|--force] [--] <path>... 'git submodule' [--quiet] deinit [-f|--force] [--] <path>...
'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch] 'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
[-f|--force] [--rebase] [--reference <repository>] [-f|--force] [--rebase] [--reference <repository>] [--depth <depth>]
[--merge] [--recursive] [--] [<path>...] [--merge] [--recursive] [--] [<path>...]
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>] 'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
[commit] [--] [<path>...] [commit] [--] [<path>...]
@ -330,6 +330,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
only in the submodules of the current repo, but also only in the submodules of the current repo, but also
in any nested submodules inside those submodules (and so on). in any nested submodules inside those submodules (and so on).
--depth::
This option is valid for add and update commands. Create a 'shallow'
clone with a history truncated to the specified number of revisions.
See linkgit:git-clone[1]
<path>...:: <path>...::
Paths to submodule(s). When specified this will restrict the command Paths to submodule(s). When specified this will restrict the command
to only operate on the submodules found at the specified paths. to only operate on the submodules found at the specified paths.

View File

@ -35,6 +35,7 @@ nofetch=
update= update=
prefix= prefix=
custom_name= custom_name=
depth=
# The function takes at most 2 arguments. The first argument is the # The function takes at most 2 arguments. The first argument is the
# URL that navigates to the submodule origin repo. When relative, this URL # URL that navigates to the submodule origin repo. When relative, this URL
@ -251,6 +252,7 @@ module_clone()
name=$2 name=$2
url=$3 url=$3
reference="$4" reference="$4"
depth="$5"
quiet= quiet=
if test -n "$GIT_QUIET" if test -n "$GIT_QUIET"
then then
@ -273,7 +275,7 @@ module_clone()
mkdir -p "$gitdir_base" mkdir -p "$gitdir_base"
( (
clear_local_git_env clear_local_git_env
git clone $quiet -n ${reference:+"$reference"} \ git clone $quiet ${depth:+"$depth"} -n ${reference:+"$reference"} \
--separate-git-dir "$gitdir" "$url" "$sm_path" --separate-git-dir "$gitdir" "$url" "$sm_path"
) || ) ||
die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")" die "$(eval_gettext "Clone of '\$url' into submodule path '\$sm_path' failed")"
@ -350,6 +352,14 @@ cmd_add()
custom_name=$2 custom_name=$2
shift shift
;; ;;
--depth)
case "$2" in '') usage ;; esac
depth="--depth=$2"
shift
;;
--depth=*)
depth=$1
;;
--) --)
shift shift
break break
@ -459,7 +469,7 @@ Use -f if you really want to add it." >&2
echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")" echo "$(eval_gettext "Reactivating local git directory for submodule '\$sm_name'.")"
fi fi
fi fi
module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" || exit module_clone "$sm_path" "$sm_name" "$realrepo" "$reference" "$depth" || exit
( (
clear_local_git_env clear_local_git_env
cd "$sm_path" && cd "$sm_path" &&
@ -736,6 +746,14 @@ cmd_update()
--checkout) --checkout)
update="checkout" update="checkout"
;; ;;
--depth)
case "$2" in '') usage ;; esac
depth="--depth=$2"
shift
;;
--depth=*)
depth=$1
;;
--) --)
shift shift
break break
@ -797,7 +815,7 @@ Maybe you want to use 'update --init'?")"
if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git if ! test -d "$sm_path"/.git -o -f "$sm_path"/.git
then then
module_clone "$sm_path" "$name" "$url" "$reference" || exit module_clone "$sm_path" "$name" "$url" "$reference" "$depth" || exit
cloned_modules="$cloned_modules;$name" cloned_modules="$cloned_modules;$name"
subsha1= subsha1=
else else

View File

@ -963,4 +963,20 @@ test_expect_success 'submodule with UTF-8 name' '
git submodule >&2 && git submodule >&2 &&
test -n "$(git submodule | grep "$svname")" test -n "$(git submodule | grep "$svname")"
' '
test_expect_success 'submodule add clone shallow submodule' '
mkdir super &&
pwd=$(pwd)
(
cd super &&
git init &&
git submodule add --depth=1 file://"$pwd"/example2 submodule &&
(
cd submodule &&
test 1 = $(git log --oneline | wc -l)
)
)
'
test_done test_done

View File

@ -729,14 +729,24 @@ test_expect_success 'submodule update properly revives a moved submodule' '
test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' ' test_expect_success SYMLINKS 'submodule update can handle symbolic links in pwd' '
mkdir -p linked/dir && mkdir -p linked/dir &&
ln -s linked/dir linkto && ln -s linked/dir linkto &&
( (cd linkto &&
cd linkto &&
git clone "$TRASH_DIRECTORY"/super_update_r2 super && git clone "$TRASH_DIRECTORY"/super_update_r2 super &&
( (cd super &&
cd super &&
git submodule update --init --recursive git submodule update --init --recursive
) )
) )
' '
test_expect_success 'submodule update clone shallow submodule' '
git clone cloned super3 &&
pwd=$(pwd)
(cd super3 &&
sed -e "s#url = ../#url = file://$pwd/#" <.gitmodules >.gitmodules.tmp &&
mv -f .gitmodules.tmp .gitmodules &&
git submodule update --init --depth=3
(cd submodule &&
test 1 = $(git log --oneline | wc -l)
)
)
'
test_done test_done