Skip to content

Commit d627bf6

Browse files
committed
Merge branch 'pk/subsub-fetch-fix'
"git fetch" did not work correctly with nested submodules where the innermost submodule that is not of interest got updated in the upstream, which has been corrected. * pk/subsub-fetch-fix: submodules: fix of regression on fetching of non-init subsub-repo
2 parents fcf26ef + 1b7ac4e commit d627bf6

File tree

2 files changed

+67
-10
lines changed

2 files changed

+67
-10
lines changed

submodule.c

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,6 @@ void prepare_submodule_repo_env(struct strvec *out)
499499
DEFAULT_GIT_DIR_ENVIRONMENT);
500500
}
501501

502-
static void prepare_submodule_repo_env_in_gitdir(struct strvec *out)
503-
{
504-
prepare_submodule_repo_env_no_git_dir(out);
505-
strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT);
506-
}
507-
508502
/*
509503
* Initialize a repository struct for a submodule based on the provided 'path'.
510504
*
@@ -1455,8 +1449,8 @@ static int get_next_submodule(struct child_process *cp,
14551449
if (task->repo) {
14561450
struct strbuf submodule_prefix = STRBUF_INIT;
14571451
child_process_init(cp);
1458-
cp->dir = task->repo->gitdir;
1459-
prepare_submodule_repo_env_in_gitdir(&cp->env_array);
1452+
cp->dir = task->repo->worktree;
1453+
prepare_submodule_repo_env(&cp->env_array);
14601454
cp->git_cmd = 1;
14611455
if (!spf->quiet)
14621456
strbuf_addf(err, _("Fetching submodule %s%s\n"),
@@ -1505,9 +1499,9 @@ static int get_next_submodule(struct child_process *cp,
15051499
spf->prefix, task->sub->path);
15061500

15071501
child_process_init(cp);
1508-
prepare_submodule_repo_env_in_gitdir(&cp->env_array);
1502+
prepare_submodule_repo_env(&cp->env_array);
15091503
cp->git_cmd = 1;
1510-
cp->dir = task->repo->gitdir;
1504+
cp->dir = task->repo->worktree;
15111505

15121506
strvec_init(&cp->args);
15131507
strvec_pushv(&cp->args, spf->args.v);

t/t5526-fetch-submodules.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,4 +719,67 @@ test_expect_success 'fetch new submodule commit intermittently referenced by sup
719719
)
720720
'
721721

722+
add_commit_push () {
723+
dir="$1"
724+
msg="$2"
725+
shift 2
726+
git -C "$dir" add "$@" &&
727+
git -C "$dir" commit -a -m "$msg" &&
728+
git -C "$dir" push
729+
}
730+
731+
compare_refs_in_dir () {
732+
fail= &&
733+
if test "x$1" = 'x!'
734+
then
735+
fail='!' &&
736+
shift
737+
fi &&
738+
git -C "$1" rev-parse --verify "$2" >expect &&
739+
git -C "$3" rev-parse --verify "$4" >actual &&
740+
eval $fail test_cmp expect actual
741+
}
742+
743+
744+
test_expect_success 'setup nested submodule fetch test' '
745+
# does not depend on any previous test setups
746+
747+
for repo in outer middle inner
748+
do
749+
(
750+
git init --bare $repo &&
751+
git clone $repo ${repo}_content &&
752+
echo "$repo" >"${repo}_content/file" &&
753+
add_commit_push ${repo}_content "initial" file
754+
) || return 1
755+
done &&
756+
757+
git clone outer A &&
758+
git -C A submodule add "$pwd/middle" &&
759+
git -C A/middle/ submodule add "$pwd/inner" &&
760+
add_commit_push A/middle/ "adding inner sub" .gitmodules inner &&
761+
add_commit_push A/ "adding middle sub" .gitmodules middle &&
762+
763+
git clone outer B &&
764+
git -C B/ submodule update --init middle &&
765+
766+
compare_refs_in_dir A HEAD B HEAD &&
767+
compare_refs_in_dir A/middle HEAD B/middle HEAD &&
768+
test -f B/file &&
769+
test -f B/middle/file &&
770+
! test -f B/middle/inner/file &&
771+
772+
echo "change on inner repo of A" >"A/middle/inner/file" &&
773+
add_commit_push A/middle/inner "change on inner" file &&
774+
add_commit_push A/middle "change on inner" inner &&
775+
add_commit_push A "change on inner" middle
776+
'
777+
778+
test_expect_success 'fetching a superproject containing an uninitialized sub/sub project' '
779+
# depends on previous test for setup
780+
781+
git -C B/ fetch &&
782+
compare_refs_in_dir A origin/master B origin/master
783+
'
784+
722785
test_done

0 commit comments

Comments
 (0)