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 <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Mar 29, 2016 at 18:27 UTC
ea2fa1040d14f1b7aab8fd78cc3ff4d41abc57a1
2 files changed
+23
-3
git-submodule.sh
+3
-3
@@ -413,8 +413,8 @@ cmd_foreach()
413
die_if_unmatched "$mode"
414
if test -e "$sm_path"/.git
415
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'")"
418
name=$(git submodule--helper name "$sm_path")
419
(
420
prefix="$prefix$sm_path/"
@@ -434,7 +434,7 @@ cmd_foreach()
434
cmd_foreach "--recursive" "$@"
435
fi
436
) <&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.")"
438
fi
439
done
440
}
t/t7407-submodule-foreach.sh
+20
@@ -177,6 +177,26 @@ test_expect_success 'test messages from "foreach --recursive"' '
177
test_i18ncmp expect actual
178
'
179
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
+
200
cat > expect <<EOF
201
nested1-nested1
202
nested2-nested2