Skip to content

Commit e7b37ca

Browse files
stefanbellergitster
authored andcommitted
submodule update: run custom update script for initial populating as well
In 1b4735d (submodule: no [--merge|--rebase] when newly cloned, 2011-02-17), all actions were defaulted to checkout for populating a submodule initially, because merging or rebasing makes no sense in that situation. Other commands however do make sense, such as the custom command that was added later (6cb5728, submodule update: allow custom command to update submodule working tree, 2013-07-03). I am unsure about the "none" command, as I can see an initial checkout there as a useful thing. On the other hand going strictly by our own documentation, we should do nothing in case of "none" as well, because the user asked for it. Reported-by: Han-Wen Nienhuys <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c3808ca commit e7b37ca

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

git-submodule.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,10 @@ cmd_update()
605605
if test $just_cloned -eq 1
606606
then
607607
subsha1=
608-
update_module=checkout
608+
case "$update_module" in
609+
merge | rebase | none)
610+
update_module=checkout ;;
611+
esac
609612
else
610613
subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
611614
git rev-parse --verify HEAD) ||

t/t7406-submodule-update.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,16 @@ test_expect_success 'submodule update - command in .git/config catches failure -
424424
test_i18ncmp actual expect
425425
'
426426

427+
test_expect_success 'submodule update - command run for initial population of submodule' '
428+
cat <<-\ EOF >expect
429+
Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
430+
EOF &&
431+
rm -rf super/submodule &&
432+
test_must_fail git -C super submodule update >../actual &&
433+
test_cmp expect actual &&
434+
git -C super submodule update --checkout
435+
'
436+
427437
cat << EOF >expect
428438
Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
429439
Failed to recurse into submodule path '../super'
@@ -476,6 +486,7 @@ test_expect_success 'submodule init picks up merge' '
476486
'
477487

478488
test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
489+
test_config -C super submodule.submodule.update checkout &&
479490
(cd super &&
480491
rm -rf submodule &&
481492
git submodule update submodule &&
@@ -488,6 +499,7 @@ test_expect_success 'submodule update --merge - ignores --merge for new submod
488499
'
489500

490501
test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
502+
test_config -C super submodule.submodule.update checkout &&
491503
(cd super &&
492504
rm -rf submodule &&
493505
git submodule update submodule &&

0 commit comments

Comments
 (0)