Skip to content

Commit cc60190

Browse files
committed
Merge branch 'sb/submodule-path-misc-bugs' into maint
"git submodule" reports the paths of submodules the command recurses into, but this was incorrect when the command was not run from the root level of the superproject. * sb/submodule-path-misc-bugs: t7407: make expectation as clear as possible submodule update: test recursive path reporting from subdirectory submodule update: align reporting path for custom command execution submodule status: correct path handling in recursive submodules submodule update --init: correct path handling in recursive submodules submodule foreach: correct path display in recursive submodules
2 parents a0c9cf5 + 2ab5660 commit cc60190

File tree

3 files changed

+133
-11
lines changed

3 files changed

+133
-11
lines changed

git-submodule.sh

Lines changed: 7 additions & 6 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
}
@@ -473,7 +473,7 @@ cmd_init()
473473
die_if_unmatched "$mode"
474474
name=$(git submodule--helper name "$sm_path") || exit
475475

476-
displaypath=$(relative_path "$sm_path")
476+
displaypath=$(relative_path "$prefix$sm_path")
477477

478478
# Copy url setting when it is not set yet
479479
if test -z "$(git config "submodule.$name.url")"
@@ -802,8 +802,8 @@ Maybe you want to use 'update --init'?")"
802802
;;
803803
!*)
804804
command="${update_module#!}"
805-
die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$prefix\$sm_path'")"
806-
say_msg="$(eval_gettext "Submodule path '\$prefix\$sm_path': '\$command \$sha1'")"
805+
die_msg="$(eval_gettext "Execution of '\$command \$sha1' failed in submodule path '\$displaypath'")"
806+
say_msg="$(eval_gettext "Submodule path '\$displaypath': '\$command \$sha1'")"
807807
must_die_on_failure=yes
808808
;;
809809
*)
@@ -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/t7406-submodule-update.sh

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ test_expect_success 'setup a submodule tree' '
6363
git submodule add ../none none &&
6464
test_tick &&
6565
git commit -m "none"
66+
) &&
67+
git clone . recursivesuper &&
68+
( cd recursivesuper
69+
git submodule add ../super super
6670
)
6771
'
6872

@@ -95,6 +99,35 @@ test_expect_success 'submodule update from subdirectory' '
9599
)
96100
'
97101

102+
supersha1=$(git -C super rev-parse HEAD)
103+
mergingsha1=$(git -C super/merging rev-parse HEAD)
104+
nonesha1=$(git -C super/none rev-parse HEAD)
105+
rebasingsha1=$(git -C super/rebasing rev-parse HEAD)
106+
submodulesha1=$(git -C super/submodule rev-parse HEAD)
107+
pwd=$(pwd)
108+
109+
cat <<EOF >expect
110+
Submodule path '../super': checked out '$supersha1'
111+
Submodule 'merging' ($pwd/merging) registered for path '../super/merging'
112+
Submodule 'none' ($pwd/none) registered for path '../super/none'
113+
Submodule 'rebasing' ($pwd/rebasing) registered for path '../super/rebasing'
114+
Submodule 'submodule' ($pwd/submodule) registered for path '../super/submodule'
115+
Submodule path '../super/merging': checked out '$mergingsha1'
116+
Submodule path '../super/none': checked out '$nonesha1'
117+
Submodule path '../super/rebasing': checked out '$rebasingsha1'
118+
Submodule path '../super/submodule': checked out '$submodulesha1'
119+
EOF
120+
121+
test_expect_success 'submodule update --init --recursive from subdirectory' '
122+
git -C recursivesuper/super reset --hard HEAD^ &&
123+
(cd recursivesuper &&
124+
mkdir tmp &&
125+
cd tmp &&
126+
git submodule update --init --recursive ../super >../../actual
127+
) &&
128+
test_cmp expect actual
129+
'
130+
98131
apos="'";
99132
test_expect_success 'submodule update does not fetch already present commits' '
100133
(cd submodule &&
@@ -311,16 +344,59 @@ test_expect_success 'submodule update - command in .git/config' '
311344
)
312345
'
313346

347+
cat << EOF >expect
348+
Execution of 'false $submodulesha1' failed in submodule path 'submodule'
349+
EOF
350+
314351
test_expect_success 'submodule update - command in .git/config catches failure' '
315352
(cd super &&
316353
git config submodule.submodule.update "!false"
317354
) &&
318355
(cd super/submodule &&
319-
git reset --hard HEAD^
356+
git reset --hard $submodulesha1^
320357
) &&
321358
(cd super &&
322-
test_must_fail git submodule update submodule
323-
)
359+
test_must_fail git submodule update submodule 2>../actual
360+
) &&
361+
test_cmp actual expect
362+
'
363+
364+
cat << EOF >expect
365+
Execution of 'false $submodulesha1' failed in submodule path '../submodule'
366+
EOF
367+
368+
test_expect_success 'submodule update - command in .git/config catches failure -- subdirectory' '
369+
(cd super &&
370+
git config submodule.submodule.update "!false"
371+
) &&
372+
(cd super/submodule &&
373+
git reset --hard $submodulesha1^
374+
) &&
375+
(cd super &&
376+
mkdir tmp && cd tmp &&
377+
test_must_fail git submodule update ../submodule 2>../../actual
378+
) &&
379+
test_cmp actual expect
380+
'
381+
382+
cat << EOF >expect
383+
Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
384+
Failed to recurse into submodule path '../super'
385+
EOF
386+
387+
test_expect_success 'recursive submodule update - command in .git/config catches failure -- subdirectory' '
388+
(cd recursivesuper &&
389+
git submodule update --remote super &&
390+
git add super &&
391+
git commit -m "update to latest to have more than one commit in submodules"
392+
) &&
393+
git -C recursivesuper/super config submodule.submodule.update "!false" &&
394+
git -C recursivesuper/super/submodule reset --hard $submodulesha1^ &&
395+
(cd recursivesuper &&
396+
mkdir -p tmp && cd tmp &&
397+
test_must_fail git submodule update --recursive ../super 2>../../actual
398+
) &&
399+
test_cmp actual expect
324400
'
325401

326402
test_expect_success 'submodule init does not copy command into .git/config' '

t/t7407-submodule-foreach.sh

Lines changed: 47 additions & 2 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
@@ -242,8 +262,12 @@ test_expect_success 'test "status --recursive"' '
242262
test_cmp expect actual
243263
'
244264

245-
sed -e "/nested2 /s/.*/+$nested2sha1 nested1\/nested2 (file2~1)/;/sub[1-3]/d" < expect > expect2
246-
mv -f expect2 expect
265+
cat > expect <<EOF
266+
$nested1sha1 nested1 (heads/master)
267+
+$nested2sha1 nested1/nested2 (file2~1)
268+
$nested3sha1 nested1/nested2/nested3 (heads/master)
269+
$submodulesha1 nested1/nested2/nested3/submodule (heads/master)
270+
EOF
247271

248272
test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' '
249273
(
@@ -257,6 +281,27 @@ test_expect_success 'ensure "status --cached --recursive" preserves the --cached
257281
test_cmp expect actual
258282
'
259283

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

0 commit comments

Comments
 (0)