3 test_description='pull can handle submodules'
6 . "$TEST_DIRECTORY"/lib-submodule-update.sh
8 reset_branch_to_HEAD () {
10 git checkout -b "$1" HEAD &&
11 git branch --set-upstream-to="origin/$1" "$1"
15 reset_branch_to_HEAD "$1" &&
16 may_only_be_test_must_fail "$2" &&
20 # pulls without conflicts
21 test_submodule_switch_func "git_pull"
24 reset_branch_to_HEAD "$1" &&
25 may_only_be_test_must_fail "$2" &&
29 test_submodule_switch_func "git_pull_ff"
32 reset_branch_to_HEAD "$1" &&
33 may_only_be_test_must_fail "$2" &&
37 test_submodule_switch_func "git_pull_ff_only"
40 reset_branch_to_HEAD "$1" &&
41 may_only_be_test_must_fail "$2" &&
45 if test "$GIT_TEST_MERGE_ALGORITHM" != ort
47 KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
48 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
50 test_submodule_switch_func "git_pull_noff"
52 test_expect_success 'pull --recurse-submodule setup' '
53 test_create_repo child &&
54 test_commit -C child bar &&
56 test_create_repo parent &&
57 test_commit -C child foo &&
59 git -C parent submodule add ../child sub &&
60 git -C parent commit -m "add submodule" &&
62 git clone --recurse-submodules parent super
65 test_expect_success 'recursive pull updates working tree' '
66 test_commit -C child merge_strategy &&
67 git -C parent submodule update --remote &&
68 git -C parent add sub &&
69 git -C parent commit -m "update submodule" &&
71 git -C super pull --no-rebase --recurse-submodules &&
72 test_path_is_file super/sub/merge_strategy.t
75 test_expect_success "submodule.recurse option triggers recursive pull" '
76 test_commit -C child merge_strategy_2 &&
77 git -C parent submodule update --remote &&
78 git -C parent add sub &&
79 git -C parent commit -m "update submodule" &&
81 git -C super -c submodule.recurse pull --no-rebase &&
82 test_path_is_file super/sub/merge_strategy_2.t
85 test_expect_success " --[no-]recurse-submodule and submodule.recurse" '
86 test_commit -C child merge_strategy_3 &&
87 git -C parent submodule update --remote &&
88 git -C parent add sub &&
89 git -C parent commit -m "update submodule" &&
91 git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase &&
92 test_path_is_missing super/sub/merge_strategy_3.t &&
93 git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase &&
94 test_path_is_file super/sub/merge_strategy_3.t &&
96 test_commit -C child merge_strategy_4 &&
97 git -C parent submodule update --remote &&
98 git -C parent add sub &&
99 git -C parent commit -m "update submodule" &&
101 git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase &&
102 test_path_is_missing super/sub/merge_strategy_4.t &&
103 git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase &&
104 test_path_is_file super/sub/merge_strategy_4.t
107 test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
108 # This tests the following scenario :
109 # - local submodule has new commits
110 # - local superproject does not have new commits
111 # - upstream superproject has new commits that change the submodule pointer
114 test_commit -C child rebase_strategy &&
115 git -C parent submodule update --remote &&
116 git -C parent add sub &&
117 git -C parent commit -m "update submodule" &&
119 # also have local commits
120 test_commit -C super/sub local_stuff &&
122 git -C super pull --rebase --recurse-submodules &&
123 test_path_is_file super/sub/rebase_strategy.t &&
124 test_path_is_file super/sub/local_stuff.t
127 test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' '
128 # This tests the following scenario :
129 # - local superproject has new commits that change the submodule pointer
130 # - upstream superproject has new commits that change the submodule pointer
132 # local changes in submodule recorded in superproject:
133 test_commit -C super/sub local_stuff_2 &&
134 git -C super add sub &&
135 git -C super commit -m "local update submodule" &&
137 # and in the remote as well:
138 test_commit -C child important_upstream_work &&
139 git -C parent submodule update --remote &&
140 git -C parent add sub &&
141 git -C parent commit -m "remote update submodule" &&
143 # Unfortunately we fail here, despite no conflict in the
144 # submodule itself, but the merge strategy in submodules
145 # does not support rebase:
146 test_must_fail git -C super pull --rebase --recurse-submodules 2>err &&
147 test_i18ngrep "locally recorded submodule modifications" err
150 test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
151 # This tests the following scenario :
152 # - local submodule does not have new commits
153 # - local superproject has new commits that *do not* change the submodule pointer
154 # - upstream superproject has new commits that *do not* change the submodule pointer
155 # - local superproject branch has no fork-point with its remote-tracking counter-part
157 # create upstream superproject
158 test_create_repo submodule &&
159 test_commit -C submodule first_in_sub &&
161 test_create_repo superprojet &&
162 test_commit -C superprojet first_in_super &&
163 git -C superprojet submodule add ../submodule &&
164 git -C superprojet commit -m "add submodule" &&
165 test_commit -C superprojet third_in_super &&
168 git clone --recurse-submodules superprojet superclone &&
170 # add commits upstream
171 test_commit -C superprojet fourth_in_super &&
173 # create topic branch in clone, not based on any remote-tracking branch
174 git -C superclone checkout -b feat HEAD~1 &&
175 test_commit -C superclone first_on_feat &&
176 git -C superclone pull --rebase --recurse-submodules origin HEAD
181 # This test is particular because there is only a single commit in the upstream superproject
182 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
183 # ('child') hard-resets its branch to a new root commit with the same tree as the one
184 # from the upstream superproject, so that its branch has no merge-base with its
185 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
186 # The result is that the local branch is reset to the remote-tracking branch (as it was
187 # originally before the hard-reset).
189 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
190 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
191 # which adds the submodule.
192 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
193 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
194 test_expect_success 'branch has no merge base with remote-tracking counterpart' '
195 rm -rf parent child &&
197 test_create_repo a-submodule &&
198 test_commit -C a-submodule foo &&
200 test_create_repo parent &&
201 git -C parent submodule add "$(pwd)/a-submodule" &&
202 git -C parent commit -m foo &&
204 git clone parent child &&
206 # Reset the current branch so that it has no merge base with
207 # the remote-tracking branch.
208 OTHER=$(git -C child commit-tree -m bar \
209 $(git -C child rev-parse HEAD^{tree})) &&
210 git -C child reset --hard "$OTHER" &&
212 git -C child pull --recurse-submodules --rebase