Skip to content

Commit 5bceab4

Browse files
committed
Merge branch 'bw/submodule-with-bs-path'
"git submodule" script does not work well with strange pathnames. Protect it from a path with slashes in them, at least. * bw/submodule-with-bs-path: submodule: prevent backslash expantion in submodule names
2 parents cdfe138 + cf9e55f commit 5bceab4

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

git-submodule.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ cmd_foreach()
332332
git submodule--helper list --prefix "$wt_prefix" ||
333333
echo "#unmatched" $?
334334
} |
335-
while read mode sha1 stage sm_path
335+
while read -r mode sha1 stage sm_path
336336
do
337337
die_if_unmatched "$mode" "$sha1"
338338
if test -e "$sm_path"/.git
@@ -441,7 +441,7 @@ cmd_deinit()
441441
git submodule--helper list --prefix "$wt_prefix" "$@" ||
442442
echo "#unmatched" $?
443443
} |
444-
while read mode sha1 stage sm_path
444+
while read -r mode sha1 stage sm_path
445445
do
446446
die_if_unmatched "$mode" "$sha1"
447447
name=$(git submodule--helper name "$sm_path") || exit
@@ -605,7 +605,7 @@ cmd_update()
605605
"$@" || echo "#unmatched" $?
606606
} | {
607607
err=
608-
while read mode sha1 stage just_cloned sm_path
608+
while read -r mode sha1 stage just_cloned sm_path
609609
do
610610
die_if_unmatched "$mode" "$sha1"
611611

@@ -847,7 +847,7 @@ cmd_summary() {
847847
# Get modified modules cared by user
848848
modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" |
849849
sane_egrep '^:([0-7]* )?160000' |
850-
while read mod_src mod_dst sha1_src sha1_dst status sm_path
850+
while read -r mod_src mod_dst sha1_src sha1_dst status sm_path
851851
do
852852
# Always show modules deleted or type-changed (blob<->module)
853853
if test "$status" = D || test "$status" = T
@@ -873,7 +873,7 @@ cmd_summary() {
873873
git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- $modules |
874874
sane_egrep '^:([0-7]* )?160000' |
875875
cut -c2- |
876-
while read mod_src mod_dst sha1_src sha1_dst status name
876+
while read -r mod_src mod_dst sha1_src sha1_dst status name
877877
do
878878
if test -z "$cached" &&
879879
test $sha1_dst = 0000000000000000000000000000000000000000
@@ -1020,7 +1020,7 @@ cmd_status()
10201020
git submodule--helper list --prefix "$wt_prefix" "$@" ||
10211021
echo "#unmatched" $?
10221022
} |
1023-
while read mode sha1 stage sm_path
1023+
while read -r mode sha1 stage sm_path
10241024
do
10251025
die_if_unmatched "$mode" "$sha1"
10261026
name=$(git submodule--helper name "$sm_path") || exit
@@ -1100,7 +1100,7 @@ cmd_sync()
11001100
git submodule--helper list --prefix "$wt_prefix" "$@" ||
11011101
echo "#unmatched" $?
11021102
} |
1103-
while read mode sha1 stage sm_path
1103+
while read -r mode sha1 stage sm_path
11041104
do
11051105
die_if_unmatched "$mode" "$sha1"
11061106

t/t7400-submodule-basic.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,20 @@ test_expect_success 'submodule add with ./, /.. and // in path' '
273273
test_cmp empty untracked
274274
'
275275

276+
test_expect_success 'submodule add with \\ in path' '
277+
test_when_finished "rm -rf parent sub\\with\\backslash" &&
278+
279+
# Initialize a repo with a backslash in its name
280+
git init sub\\with\\backslash &&
281+
touch sub\\with\\backslash/empty.file &&
282+
git -C sub\\with\\backslash add empty.file &&
283+
git -C sub\\with\\backslash commit -m "Added empty.file" &&
284+
285+
# Add that repository as a submodule
286+
git init parent &&
287+
git -C parent submodule add ../sub\\with\\backslash
288+
'
289+
276290
test_expect_success 'submodule add in subdirectory' '
277291
echo "refs/heads/master" >expect &&
278292
>empty &&

0 commit comments

Comments
 (0)