Skip to content

Commit ea2fa10

Browse files
stefanbellergitster
authored andcommitted
submodule foreach: correct path display in recursive submodules
The `prefix` was put in front of the display path unconditionally. This is wrong as any relative path computation would need to be at the front, so include the prefix into the display path. The new test replicates the previous test with the difference of executing from a sub directory. By executing from a sub directory all we would expect all displayed paths to be prefixed by '../'. Prior to this patch the test would report Entering 'nested1/nested2/../nested3' instead of the expected Entering '../nested1/nested2/nested3' Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 90f7b16 commit ea2fa10

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

git-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ cmd_foreach()
413413
die_if_unmatched "$mode"
414414
if test -e "$sm_path"/.git
415415
then
416-
displaypath=$(relative_path "$sm_path")
417-
say "$(eval_gettext "Entering '\$prefix\$displaypath'")"
416+
displaypath=$(relative_path "$prefix$sm_path")
417+
say "$(eval_gettext "Entering '\$displaypath'")"
418418
name=$(git submodule--helper name "$sm_path")
419419
(
420420
prefix="$prefix$sm_path/"
@@ -434,7 +434,7 @@ cmd_foreach()
434434
cmd_foreach "--recursive" "$@"
435435
fi
436436
) <&3 3<&- ||
437-
die "$(eval_gettext "Stopping at '\$prefix\$displaypath'; script returned non-zero status.")"
437+
die "$(eval_gettext "Stopping at '\$displaypath'; script returned non-zero status.")"
438438
fi
439439
done
440440
}

t/t7407-submodule-foreach.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,26 @@ test_expect_success 'test messages from "foreach --recursive"' '
177177
test_i18ncmp expect actual
178178
'
179179

180+
cat > expect <<EOF
181+
Entering '../nested1'
182+
Entering '../nested1/nested2'
183+
Entering '../nested1/nested2/nested3'
184+
Entering '../nested1/nested2/nested3/submodule'
185+
Entering '../sub1'
186+
Entering '../sub2'
187+
Entering '../sub3'
188+
EOF
189+
190+
test_expect_success 'test messages from "foreach --recursive" from subdirectory' '
191+
(
192+
cd clone2 &&
193+
mkdir untracked &&
194+
cd untracked &&
195+
git submodule foreach --recursive >../../actual
196+
) &&
197+
test_i18ncmp expect actual
198+
'
199+
180200
cat > expect <<EOF
181201
nested1-nested1
182202
nested2-nested2

0 commit comments

Comments
 (0)