Skip to content

Commit 33aa6ff

Browse files
hjemligitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6abd0fb commit 33aa6ff

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

git-submodule.sh

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ say()
2525
fi
2626
}
2727

28+
29+
#
30+
# Clone a submodule
31+
#
32+
module_clone()
33+
{
34+
path=$1
35+
url=$2
36+
37+
# If there already is a directory at the submodule path,
38+
# expect it to be empty (since that is the default checkout
39+
# action) and try to remove it.
40+
# Note: if $path is a symlink to a directory the test will
41+
# succeed but the rmdir will fail. We might want to fix this.
42+
if test -d "$path"
43+
then
44+
rmdir "$path" 2>/dev/null ||
45+
die "Directory '$path' exist, but is neither empty nor a git repository"
46+
fi
47+
48+
test -e "$path" &&
49+
die "A file already exist at path '$path'"
50+
51+
git-clone -n "$url" "$path" ||
52+
die "Clone of submodule '$path' failed"
53+
}
54+
2855
#
2956
# Run clone + checkout on missing submodules
3057
#
@@ -40,20 +67,6 @@ modules_init()
4067
# repository
4168
test -d "$path"/.git && continue
4269

43-
# If there already is a directory at the submodule path,
44-
# expect it to be empty (since that is the default checkout
45-
# action) and try to remove it.
46-
# Note: if $path is a symlink to a directory the test will
47-
# succeed but the rmdir will fail. We might want to fix this.
48-
if test -d "$path"
49-
then
50-
rmdir "$path" 2>/dev/null ||
51-
die "Directory '$path' exist, but is neither empty nor a git repository"
52-
fi
53-
54-
test -e "$path" &&
55-
die "A file already exist at path '$path'"
56-
5770
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
5871
test -z "$url" &&
5972
die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
6982
# logical modulename (if present) as key. But this would need
7083
# another fallback mechanism if the module wasn't named.
7184

72-
git-clone -n "$url" "$path" ||
73-
die "Clone of submodule '$path' failed"
85+
module_clone "$path" "$url" || exit
7486

7587
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
7688
die "Checkout of submodule '$path' failed"

0 commit comments

Comments
 (0)