git submodule: Fix adding of submodules at paths with ./, .. and //
Make 'git submodule add' normalize the submodule path in the same way as 'git ls-files' does, so that 'git submodule init' looks up the information in .gitmodules with the same key under which 'git submodule add' stores it. This fixes 4 known breakages. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael J Gruber committed
Mar 3, 2009 at 16:08 UTC
db75ada559dd4de99fedd1fc4f62a9273f032dd3
2 files changed
+16
-7
git-submodule.sh
+12
-3
@@ -166,9 +166,18 @@ cmd_add()
166
;;
167
esac
168
169
- # strip trailing slashes from path
170
- path=$(echo "$path" | sed -e 's|/*$||')
171
-
169
+ # normalize path:
170
+ # multiple //; leading ./; /./; /../; trailing /
171
+ path=$(printf '%s/\n' "$path" |
172
+ sed -e '
173
+ s|//*|/|g
174
+ s|^\(\./\)*||
175
+ s|/\./|/|g
176
+ :start
177
+ s|\([^/]*\)/\.\./||
178
+ tstart
179
+ s|/*$||
180
+ ')
181
git ls-files --error-unmatch "$path" > /dev/null 2>&1 &&
182
die "'$path' already exists in the index"
183
t/t7400-submodule-basic.sh
+4
-4
@@ -64,7 +64,7 @@ test_expect_success 'submodule add' '
64
)
65
'
66
67
-test_expect_failure 'submodule add with ./ in path' '
67
+test_expect_success 'submodule add with ./ in path' '
68
(
69
cd addtest &&
70
git submodule add "$submodurl" ././dotsubmod/./frotz/./ &&
@@ -72,7 +72,7 @@ test_expect_failure 'submodule add with ./ in path' '
72
)
73
'
74
75
-test_expect_failure 'submodule add with // in path' '
75
+test_expect_success 'submodule add with // in path' '
76
(
77
cd addtest &&
78
git submodule add "$submodurl" slashslashsubmod///frotz// &&
@@ -80,7 +80,7 @@ test_expect_failure 'submodule add with // in path' '
80
)
81
'
82
83
-test_expect_failure 'submodule add with /.. in path' '
83
+test_expect_success 'submodule add with /.. in path' '
84
(
85
cd addtest &&
86
git submodule add "$submodurl" dotdotsubmod/../realsubmod/frotz/.. &&
@@ -88,7 +88,7 @@ test_expect_failure 'submodule add with /.. in path' '
88
)
89
'
90
91
-test_expect_failure 'submodule add with ./, /.. and // in path' '
91
+test_expect_success 'submodule add with ./, /.. and // in path' '
92
(
93
cd addtest &&
94
git submodule add "$submodurl" dot/dotslashsubmod/./../..////realsubmod2/a/b/c/d/../../../../frotz//.. &&