git-submodule: move cloning into a separate function

This is just a simple refactoring of modules_init() with no change in
functionality.

Signed-off-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Lars Hjemli 2007-06-06 11:13:01 +02:00 коммит произвёл Junio C Hamano
Родитель 6abd0fb396
Коммит 33aa6fff5d
1 изменённых файлов: 28 добавлений и 16 удалений

Просмотреть файл

@ -25,20 +25,14 @@ say()
fi
}
#
# Run clone + checkout on missing submodules
# Clone a submodule
#
# $@ = requested paths (default to all)
#
modules_init()
module_clone()
{
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
# Skip submodule paths that already contain a .git directory.
# This will also trigger if $path is a symlink to a git
# repository
test -d "$path"/.git && continue
path=$1
url=$2
# If there already is a directory at the submodule path,
# expect it to be empty (since that is the default checkout
@ -54,6 +48,25 @@ modules_init()
test -e "$path" &&
die "A file already exist at path '$path'"
git-clone -n "$url" "$path" ||
die "Clone of submodule '$path' failed"
}
#
# Run clone + checkout on missing submodules
#
# $@ = requested paths (default to all)
#
modules_init()
{
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
do
# Skip submodule paths that already contain a .git directory.
# This will also trigger if $path is a symlink to a git
# repository
test -d "$path"/.git && continue
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
@ -69,8 +82,7 @@ modules_init()
# logical modulename (if present) as key. But this would need
# another fallback mechanism if the module wasn't named.
git-clone -n "$url" "$path" ||
die "Clone of submodule '$path' failed"
module_clone "$path" "$url" || exit
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
die "Checkout of submodule '$path' failed"