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>
Lars Hjemli committed
Jun 6, 2007 at 11:13 UTC
33aa6fff5d502d8e2806d31bb0916006993c1f24
1 file changed
+28
-16
git-submodule.sh
+28
-16
@@ -25,6 +25,33 @@ say()
25
fi
26
}
27
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
+
55
#
56
# Run clone + checkout on missing submodules
57
#
@@ -40,20 +67,6 @@ modules_init()
67
# repository
68
test -d "$path"/.git && continue
69
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
-
70
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
71
test -z "$url" &&
72
die "No url found for submodule '$path' in .gitmodules"
@@ -69,8 +82,7 @@ modules_init()
82
# logical modulename (if present) as key. But this would need
83
# another fallback mechanism if the module wasn't named.
84
72
- git-clone -n "$url" "$path" ||
73
- die "Clone of submodule '$path' failed"
85
+ module_clone "$path" "$url" || exit
86
87
(unset GIT_DIR && cd "$path" && git-checkout -q "$sha1") ||
88
die "Checkout of submodule '$path' failed"