Skip to content

Commit 42df89b

Browse files
committed
Merge branch 'pk/subsub-fetch-fix-take-2' into maint
"git fetch --recurse-submodules" fix (second attempt). * pk/subsub-fetch-fix-take-2: submodules: fix of regression on fetching of non-init subsub-repo
2 parents 71ca53e + 505a276 commit 42df89b

File tree

2 files changed

+123
-1
lines changed

2 files changed

+123
-1
lines changed

submodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,7 @@ static int get_next_submodule(struct child_process *cp,
14771477
strbuf_release(&submodule_prefix);
14781478
return 1;
14791479
} else {
1480+
struct strbuf empty_submodule_path = STRBUF_INIT;
14801481

14811482
fetch_task_release(task);
14821483
free(task);
@@ -1485,13 +1486,17 @@ static int get_next_submodule(struct child_process *cp,
14851486
* An empty directory is normal,
14861487
* the submodule is not initialized
14871488
*/
1489+
strbuf_addf(&empty_submodule_path, "%s/%s/",
1490+
spf->r->worktree,
1491+
ce->name);
14881492
if (S_ISGITLINK(ce->ce_mode) &&
1489-
!is_empty_dir(ce->name)) {
1493+
!is_empty_dir(empty_submodule_path.buf)) {
14901494
spf->result = 1;
14911495
strbuf_addf(err,
14921496
_("Could not access submodule '%s'\n"),
14931497
ce->name);
14941498
}
1499+
strbuf_release(&empty_submodule_path);
14951500
}
14961501
}
14971502

t/t5526-fetch-submodules.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,121 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup
722722
)
723723
'
724724

725+
add_commit_push () {
726+
dir="$1" &&
727+
msg="$2" &&
728+
shift 2 &&
729+
git -C "$dir" add "$@" &&
730+
git -C "$dir" commit -a -m "$msg" &&
731+
git -C "$dir" push
732+
}
733+
734+
compare_refs_in_dir () {
735+
fail= &&
736+
if test "x$1" = 'x!'
737+
then
738+
fail='!' &&
739+
shift
740+
fi &&
741+
git -C "$1" rev-parse --verify "$2" >expect &&
742+
git -C "$3" rev-parse --verify "$4" >actual &&
743+
eval $fail test_cmp expect actual
744+
}
745+
746+
747+
test_expect_success 'setup nested submodule fetch test' '
748+
# does not depend on any previous test setups
749+
750+
for repo in outer middle inner
751+
do
752+
git init --bare $repo &&
753+
git clone $repo ${repo}_content &&
754+
echo "$repo" >"${repo}_content/file" &&
755+
add_commit_push ${repo}_content "initial" file ||
756+
return 1
757+
done &&
758+
759+
git clone outer A &&
760+
git -C A submodule add "$pwd/middle" &&
761+
git -C A/middle/ submodule add "$pwd/inner" &&
762+
add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
763+
add_commit_push A/ "adding middle sub" .gitmodules middle &&
764+
765+
git clone outer B &&
766+
git -C B/ submodule update --init middle &&
767+
768+
compare_refs_in_dir A HEAD B HEAD &&
769+
compare_refs_in_dir A/middle HEAD B/middle HEAD &&
770+
test_path_is_file B/file &&
771+
test_path_is_file B/middle/file &&
772+
test_path_is_missing B/middle/inner/file &&
773+
774+
echo "change on inner repo of A" >"A/middle/inner/file" &&
775+
add_commit_push A/middle/inner "change on inner" file &&
776+
add_commit_push A/middle "change on inner" inner &&
777+
add_commit_push A "change on inner" middle
778+
'
779+
780+
test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
781+
# depends on previous test for setup
782+
783+
git -C B/ fetch &&
784+
compare_refs_in_dir A origin/HEAD B origin/HEAD
785+
'
786+
787+
fetch_with_recursion_abort () {
788+
# In a regression the following git call will run into infinite recursion.
789+
# To handle that, we connect the sed command to the git call by a pipe
790+
# so that sed can kill the infinite recursion when detected.
791+
# The recursion creates git output like:
792+
# Fetching submodule sub
793+
# Fetching submodule sub/sub <-- [1]
794+
# Fetching submodule sub/sub/sub
795+
# ...
796+
# [1] sed will stop reading and cause git to eventually stop and die
797+
798+
git -C "$1" fetch --recurse-submodules 2>&1 |
799+
sed "/Fetching submodule $2[^$]/q" >out &&
800+
! grep "Fetching submodule $2[^$]" out
801+
}
802+
803+
test_expect_success 'setup recursive fetch with uninit submodule' '
804+
# does not depend on any previous test setups
805+
806+
test_create_repo super &&
807+
test_commit -C super initial &&
808+
test_create_repo sub &&
809+
test_commit -C sub initial &&
810+
git -C sub rev-parse HEAD >expect &&
811+
812+
git -C super submodule add ../sub &&
813+
git -C super commit -m "add sub" &&
814+
815+
git clone super superclone &&
816+
git -C superclone submodule status >out &&
817+
sed -e "s/^-//" -e "s/ sub.*$//" out >actual &&
818+
test_cmp expect actual
819+
'
820+
821+
test_expect_success 'recursive fetch with uninit submodule' '
822+
# depends on previous test for setup
823+
824+
fetch_with_recursion_abort superclone sub &&
825+
git -C superclone submodule status >out &&
826+
sed -e "s/^-//" -e "s/ sub$//" out >actual &&
827+
test_cmp expect actual
828+
'
829+
830+
test_expect_success 'recursive fetch after deinit a submodule' '
831+
# depends on previous test for setup
832+
833+
git -C superclone submodule update --init sub &&
834+
git -C superclone submodule deinit -f sub &&
835+
836+
fetch_with_recursion_abort superclone sub &&
837+
git -C superclone submodule status >out &&
838+
sed -e "s/^-//" -e "s/ sub$//" out >actual &&
839+
test_cmp expect actual
840+
'
841+
725842
test_done

0 commit comments

Comments
 (0)