Skip to content

Commit 10450cf

Browse files
stefanbellergitster
authored andcommitted
submodule status: correct path handling in recursive submodules
The new test which is a replica of the previous test except that it executes from a sub directory. Prior to this patch the test failed by having too many '../' prefixed: --- expect 2016-03-29 19:02:33.087336115 +0000 +++ actual 2016-03-29 19:02:33.359343311 +0000 @@ -1,7 +1,7 @@ b23f134787d96fae589a6b76da41f4db112fc8db ../nested1 (heads/master) -+25d56d1ddfb35c3e91ff7d8f12331c2e53147dcc ../nested1/nested2 (file2) - 5ec83512b76a0b8170b899f8e643913c3e9b72d9 ../nested1/nested2/nested3 (heads/master) - 509f622a4f36a3e472affcf28fa959174f3dd5b5 ../nested1/nested2/nested3/submodule (heads/master) ++25d56d1ddfb35c3e91ff7d8f12331c2e53147dcc ../../nested1/nested2 (file2) + 5ec83512b76a0b8170b899f8e643913c3e9b72d9 ../../../nested1/nested2/nested3 (heads/master) + 509f622a4f36a3e472affcf28fa959174f3dd5b5 ../../../../nested1/nested2/nested3/submodule (heads/master) 0c90624ab7f1aaa301d3bb79f60dcfed1ec4897f ../sub1 (0c90624) 0c90624ab7f1aaa301d3bb79f60dcfed1ec4897f ../sub2 (0c90624) 509f622a4f36a3e472affcf28fa959174f3dd5b5 ../sub3 (heads/master) The path code in question: displaypath=$(relative_path "$prefix$sm_path") prefix=$displaypath if recursive: eval cmd_status That way we change `prefix` each iteration to contain another '../', because of the the relative_path computation is done on an already computed relative path. We must call relative_path exactly once with `wt_prefix` non empty. Further calls in recursive instances to to calculate the displaypath already incorporate the correct prefix from before. Fix the issue by clearing `wt_prefix` in recursive calls. Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c1ab00f commit 10450cf

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

git-submodule.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,7 @@ cmd_status()
11591159
(
11601160
prefix="$displaypath/"
11611161
clear_local_git_env
1162+
wt_prefix=
11621163
cd "$sm_path" &&
11631164
eval cmd_status
11641165
) ||

t/t7407-submodule-foreach.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,27 @@ test_expect_success 'ensure "status --cached --recursive" preserves the --cached
277277
test_cmp expect actual
278278
'
279279

280+
nested2sha1=$(git -C clone3/nested1/nested2 rev-parse HEAD)
281+
282+
cat > expect <<EOF
283+
$nested1sha1 ../nested1 (heads/master)
284+
+$nested2sha1 ../nested1/nested2 (file2)
285+
$nested3sha1 ../nested1/nested2/nested3 (heads/master)
286+
$submodulesha1 ../nested1/nested2/nested3/submodule (heads/master)
287+
$sub1sha1 ../sub1 ($sub1sha1_short)
288+
$sub2sha1 ../sub2 ($sub2sha1_short)
289+
$sub3sha1 ../sub3 (heads/master)
290+
EOF
291+
292+
test_expect_success 'test "status --recursive" from sub directory' '
293+
(
294+
cd clone3 &&
295+
mkdir tmp && cd tmp &&
296+
git submodule status --recursive > ../../actual
297+
) &&
298+
test_cmp expect actual
299+
'
300+
280301
test_expect_success 'use "git clone --recursive" to checkout all submodules' '
281302
git clone --recursive super clone4 &&
282303
(

0 commit comments

Comments
 (0)