diff options
author | Lars Hjemli <hjemli@gmail.com> | 2007-06-06 11:13:01 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2007-06-06 02:49:08 -0700 |
commit | 33aa6fff5d502d8e2806d31bb0916006993c1f24 (patch) | |
tree | f14f30135cdd8e292487691682a21dcbfc370ed8 /git-submodule.sh | |
parent | 6abd0fb396a0c575dafd4e1021d37d178740396c (diff) | |
download | git-33aa6fff5d502d8e2806d31bb0916006993c1f24.tar.gz |
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>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-x | git-submodule.sh | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/git-submodule.sh b/git-submodule.sh index 6ed5a6ced2..486d3b2124 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -25,6 +25,33 @@ say() fi } + +# +# Clone a submodule +# +module_clone() +{ + 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 + # action) and try to remove it. + # Note: if $path is a symlink to a directory the test will + # succeed but the rmdir will fail. We might want to fix this. + if test -d "$path" + then + rmdir "$path" 2>/dev/null || + die "Directory '$path' exist, but is neither empty nor a git repository" + fi + + 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 # @@ -40,20 +67,6 @@ modules_init() # repository test -d "$path"/.git && continue - # If there already is a directory at the submodule path, - # expect it to be empty (since that is the default checkout - # action) and try to remove it. - # Note: if $path is a symlink to a directory the test will - # succeed but the rmdir will fail. We might want to fix this. - if test -d "$path" - then - rmdir "$path" 2>/dev/null || - die "Directory '$path' exist, but is neither empty nor a git repository" - fi - - test -e "$path" && - die "A file already exist at path '$path'" - 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" |