|
|
@ -25,20 +25,14 @@ say() |
|
|
|
fi |
|
|
|
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 ' | |
|
|
|
path=$1 |
|
|
|
while read mode sha1 stage path |
|
|
|
url=$2 |
|
|
|
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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# If there already is a directory at the submodule path, |
|
|
|
# If there already is a directory at the submodule path, |
|
|
|
# expect it to be empty (since that is the default checkout |
|
|
|
# expect it to be empty (since that is the default checkout |
|
|
@ -54,33 +48,37 @@ modules_init() |
|
|
|
test -e "$path" && |
|
|
|
test -e "$path" && |
|
|
|
die "A file already exist at path '$path'" |
|
|
|
die "A file already exist at path '$path'" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
git-clone -n "$url" "$path" || |
|
|
|
|
|
|
|
die "Clone of submodule '$path' failed" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# Register submodules in .git/config |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
# $@ = requested paths (default to all) |
|
|
|
|
|
|
|
# |
|
|
|
|
|
|
|
modules_init() |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
git ls-files --stage -- "$@" | grep -e '^160000 ' | |
|
|
|
|
|
|
|
while read mode sha1 stage path |
|
|
|
|
|
|
|
do |
|
|
|
|
|
|
|
# Skip already registered paths |
|
|
|
|
|
|
|
url=$(git-config submodule."$path".url) |
|
|
|
|
|
|
|
test -z "$url" || 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. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
git-clone -n "$url" "$path" || |
|
|
|
|
|
|
|
die "Clone of submodule '$path' failed" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") || |
|
|
|
|
|
|
|
die "Checkout of submodule '$path' failed" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
say "Submodule '$path' initialized" |
|
|
|
say "Submodule '$path' registered with url '$url'" |
|
|
|
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) |
|
|
|
# |
|
|
|
# |
|
|
@ -89,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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ! test -d "$path"/.git |
|
|
|
|
|
|
|
then |
|
|
|
|
|
|
|
module_clone "$path" "$url" || exit |
|
|
|
fi |
|
|
|
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'" |
|
|
|