@ -53,7 +53,7 @@ module_clone()
}
}
#
#
# Run clone + checkout on missing submodules
# Register submodules in .git/config
#
#
# $@ = requested paths (default to all)
# $@ = requested paths (default to all)
#
#
@ -62,37 +62,23 @@ modules_init()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
while read mode sha1 stage path
do
do
# Skip submodule paths that already contain a .git directory.
# Skip already registered paths
# This will also trigger if $path is a symlink to a git
url=$(git-config submodule."$path".url)
# repository
test -z "$url" || continue
test -d "$path"/.git && continue
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
test -z "$url" &&
test -z "$url" &&
die "No url found for submodule '$path' in .gitmodules"
die "No url found for submodule '$path' in .gitmodules"
# MAYBE FIXME: this would be the place to check GIT_CONFIG
git-config submodule."$path".url "$url" ||
# for a preferred url for this submodule, possibly like this:
die "Failed to register url for submodule '$path'"
#
# modname=$(GIT_CONFIG=.gitmodules git-config module."$path".name)
# alturl=$(git-config module."$modname".url)
#
# This would let the versioned .gitmodules file use the submodule
# path as key, while the unversioned GIT_CONFIG would use the
# logical modulename (if present) as key. But this would need
# another fallback mechanism if the module wasn't named.
module_clone "$path" "$url" || exit
say "Submodule '$path' registered with url '$url'"
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
die "Checkout of submodule '$path' failed"
say "Submodule '$path' initialized"
done
done
}
}
#
#
# Checkout correct revision of each initialized submodule
# Update each submodule path to correct revision, using clone and checkout as needed
#
#
# $@ = requested paths (default to all)
# $@ = requested paths (default to all)
#
#
@ -101,14 +87,21 @@ modules_update()
git ls-files --stage -- "$@" | grep -e '^160000 ' |
git ls-files --stage -- "$@" | grep -e '^160000 ' |
while read mode sha1 stage path
while read mode sha1 stage path
do
do
if ! test -d "$path"/.git
url=$(git-config submodule."$path".url)
if test -z "$url"
then
then
# Only mention uninitialized submodules when its
# Only mention uninitialized submodules when its
# path have been specified
# path have been specified
test "$#" != "0" &&
test "$#" != "0" &&
say "Submodule '$path' not initialized"
say "Submodule '$path' not initialized"
continue;
continue
fi
fi
if ! test -d "$path"/.git
then
module_clone "$path" "$url" || exit
fi
subsha1=$(unset GIT_DIR && cd "$path" &&
subsha1=$(unset GIT_DIR && cd "$path" &&
git-rev-parse --verify HEAD) ||
git-rev-parse --verify HEAD) ||
die "Unable to find current revision of submodule '$path'"
die "Unable to find current revision of submodule '$path'"