Skip to content

Commit 4ba6bb2

Browse files
committed
Merge branch 'sb/submodule-update-initial-runs-custom-script'
The user can specify a custom update method that is run when "submodule update" updates an already checked out submodule. This was ignored when checking the submodule out for the first time and we instead always just checked out the commit that is bound to the path in the superproject's index. * sb/submodule-update-initial-runs-custom-script: submodule update: run custom update script for initial populating as well
2 parents 5348021 + e7b37ca commit 4ba6bb2

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
@@ -613,7 +613,10 @@ cmd_update()
613613
if test $just_cloned -eq 1
614614
then
615615
subsha1=
616-
update_module=checkout
616+
case "$update_module" in
617+
merge | rebase | none)
618+
update_module=checkout ;;
619+
esac
617620
else
618621
subsha1=$(sanitize_submodule_env; cd "$sm_path" &&
619622
git rev-parse --verify HEAD) ||

t/t7406-submodule-update.sh

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

444+
test_expect_success 'submodule update - command run for initial population of submodule' '
445+
cat <<-\ EOF >expect
446+
Execution of '\''false $submodulesha1'\'' failed in submodule path '\''submodule'\''
447+
EOF &&
448+
rm -rf super/submodule &&
449+
test_must_fail git -C super submodule update >../actual &&
450+
test_cmp expect actual &&
451+
git -C super submodule update --checkout
452+
'
453+
444454
cat << EOF >expect
445455
Execution of 'false $submodulesha1' failed in submodule path '../super/submodule'
446456
Failed to recurse into submodule path '../super'
@@ -493,6 +503,7 @@ test_expect_success 'submodule init picks up merge' '
493503
'
494504

495505
test_expect_success 'submodule update --merge - ignores --merge for new submodules' '
506+
test_config -C super submodule.submodule.update checkout &&
496507
(cd super &&
497508
rm -rf submodule &&
498509
git submodule update submodule &&
@@ -505,6 +516,7 @@ test_expect_success 'submodule update --merge - ignores --merge for new submod
505516
'
506517

507518
test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' '
519+
test_config -C super submodule.submodule.update checkout &&
508520
(cd super &&
509521
rm -rf submodule &&
510522
git submodule update submodule &&

0 commit comments

Comments
 (0)