git-submodule: give submodules proper names
This changes the way git-submodule uses .gitmodules: Subsections no longer specify the submodule path, they now specify the submodule name. The submodule path is found under the new key "submodule.<name>.path", which is a required key. With this change a submodule can be moved between different 'checkout paths' without upsetting git-submodule. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Lars Hjemli committed
Jun 11, 2007 at 21:12 UTC
941987a554812b982094e09c5c817f18be953365
2 files changed
+47
-18
git-submodule.sh
+31
-14
@@ -25,6 +25,19 @@ say()
25
fi
26
}
27
28
+#
29
+# Map submodule path to submodule name
30
+#
31
+# $1 = path
32
+#
33
+module_name()
34
+{
35
+ name=$(GIT_CONFIG=.gitmodules git-config --get-regexp '^submodule\..*\.path$' "$1" |
36
+ sed -nre 's/^submodule\.(.+)\.path .+$/\1/p')
37
+ test -z "$name" &&
38
+ die "No submodule mapping found in .gitmodules for path '$path'"
39
+ echo "$name"
40
+}
41
42
#
43
# Clone a submodule
@@ -49,7 +62,7 @@ module_clone()
62
die "A file already exist at path '$path'"
63
64
git-clone -n "$url" "$path" ||
52
- die "Clone of submodule '$path' failed"
65
+ die "Clone of '$url' into submodule path '$path' failed"
66
}
67
68
#
@@ -63,17 +76,18 @@ modules_init()
76
while read mode sha1 stage path
77
do
78
# Skip already registered paths
66
- url=$(git-config submodule."$path".url)
79
+ name=$(module_name "$path") || exit
80
+ url=$(git-config submodule."$name".url)
81
test -z "$url" || continue
82
69
- url=$(GIT_CONFIG=.gitmodules git-config submodule."$path".url)
83
+ url=$(GIT_CONFIG=.gitmodules git-config submodule."$name".url)
84
test -z "$url" &&
71
- die "No url found for submodule '$path' in .gitmodules"
85
+ die "No url found for submodule path '$path' in .gitmodules"
86
73
- git-config submodule."$path".url "$url" ||
74
- die "Failed to register url for submodule '$path'"
87
+ git-config submodule."$name".url "$url" ||
88
+ die "Failed to register url for submodule path '$path'"
89
76
- say "Submodule '$path' registered with url '$url'"
90
+ say "Submodule '$name' ($url) registered for path '$path'"
91
done
92
}
93
@@ -87,13 +101,14 @@ modules_update()
101
git ls-files --stage -- "$@" | grep -e '^160000 ' |
102
while read mode sha1 stage path
103
do
90
- url=$(git-config submodule."$path".url)
104
+ name=$(module_name "$path") || exit
105
+ url=$(git-config submodule."$name".url)
106
if test -z "$url"
107
then
108
# Only mention uninitialized submodules when its
109
# path have been specified
110
test "$#" != "0" &&
96
- say "Submodule '$path' not initialized"
111
+ say "Submodule path '$path' not initialized"
112
continue
113
fi
114
@@ -104,22 +119,22 @@ modules_update()
119
else
120
subsha1=$(unset GIT_DIR && cd "$path" &&
121
git-rev-parse --verify HEAD) ||
107
- die "Unable to find current revision of submodule '$path'"
122
+ die "Unable to find current revision in submodule path '$path'"
123
fi
124
125
if test "$subsha1" != "$sha1"
126
then
127
(unset GIT_DIR && cd "$path" && git-fetch &&
128
git-checkout -q "$sha1") ||
114
- die "Unable to checkout '$sha1' in submodule '$path'"
129
+ die "Unable to checkout '$sha1' in submodule path '$path'"
130
116
- say "Submodule '$path': checked out '$sha1'"
131
+ say "Submodule path '$path': checked out '$sha1'"
132
fi
133
done
134
}
135
136
#
122
-# List all registered submodules, prefixed with:
137
+# List all submodules, prefixed with:
138
# - submodule not initialized
139
# + different revision checked out
140
#
@@ -133,7 +148,9 @@ modules_list()
148
git ls-files --stage -- "$@" | grep -e '^160000 ' |
149
while read mode sha1 stage path
150
do
136
- if ! test -d "$path"/.git
151
+ name=$(module_name "$path") || exit
152
+ url=$(git-config submodule."$name".url)
153
+ if test -z "url" || ! test -d "$path"/.git
154
then
155
say "-$sha1 $path"
156
continue;
t/t7400-submodule-basic.sh
+16
-4
@@ -18,7 +18,7 @@ subcommands of git-submodule.
18
# -add directory lib to 'superproject', this creates a DIRLINK entry
19
# -add a couple of regular files to enable testing of submodule filtering
20
# -mv lib subrepo
21
-# -add an entry to .gitmodules for path 'lib'
21
+# -add an entry to .gitmodules for submodule 'example'
22
#
23
test_expect_success 'Prepare submodule testing' '
24
mkdir lib &&
@@ -40,7 +40,19 @@ test_expect_success 'Prepare submodule testing' '
40
git-add a lib z &&
41
git-commit -m "super commit 1" &&
42
mv lib .subrepo &&
43
- GIT_CONFIG=.gitmodules git-config submodule.lib.url git://example.com/lib.git
43
+ GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git
44
+'
45
+
46
+test_expect_success 'status should fail for unmapped paths' '
47
+ if git-submodule status
48
+ then
49
+ echo "[OOPS] submodule status succeeded"
50
+ false
51
+ elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib
52
+ then
53
+ echo "[OOPS] git-config failed to update .gitmodules"
54
+ false
55
+ fi
56
'
57
58
test_expect_success 'status should only print one line' '
@@ -54,12 +66,12 @@ test_expect_success 'status should initially be "missing"' '
66
67
test_expect_success 'init should register submodule url in .git/config' '
68
git-submodule init &&
57
- url=$(git-config submodule.lib.url) &&
69
+ url=$(git-config submodule.example.url) &&
70
if test "$url" != "git://example.com/lib.git"
71
then
72
echo "[OOPS] init succeeded but submodule url is wrong"
73
false
62
- elif ! git-config submodule.lib.url ./.subrepo
74
+ elif ! git-config submodule.example.url ./.subrepo
75
then
76
echo "[OOPS] init succeeded but update of url failed"
77
false