3 test_description
='pull can handle submodules'
5 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
=1
6 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
9 .
"$TEST_DIRECTORY"/lib-submodule-update.sh
11 reset_branch_to_HEAD
() {
13 git checkout
-b "$1" HEAD
&&
14 git branch
--set-upstream-to="origin/$1" "$1"
18 reset_branch_to_HEAD
"$1" &&
19 may_only_be_test_must_fail
"$2" &&
23 # pulls without conflicts
24 test_submodule_switch_func
"git_pull"
27 reset_branch_to_HEAD
"$1" &&
28 may_only_be_test_must_fail
"$2" &&
32 test_submodule_switch_func
"git_pull_ff"
35 reset_branch_to_HEAD
"$1" &&
36 may_only_be_test_must_fail
"$2" &&
40 test_submodule_switch_func
"git_pull_ff_only"
43 reset_branch_to_HEAD
"$1" &&
44 may_only_be_test_must_fail
"$2" &&
48 if test "$GIT_TEST_MERGE_ALGORITHM" != ort
50 KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR
=1
51 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES
=1
53 test_submodule_switch_func
"git_pull_noff"
55 test_expect_success
'setup' '
56 git config --global protocol.file.allow always
59 test_expect_success
'pull --recurse-submodule setup' '
60 test_create_repo child &&
61 test_commit -C child bar &&
63 test_create_repo parent &&
64 test_commit -C child foo &&
66 git -C parent submodule add ../child sub &&
67 git -C parent commit -m "add submodule" &&
69 git clone --recurse-submodules parent super
72 test_expect_success
'recursive pull updates working tree' '
73 test_commit -C child merge_strategy &&
74 git -C parent submodule update --remote &&
75 git -C parent add sub &&
76 git -C parent commit -m "update submodule" &&
78 git -C super pull --no-rebase --recurse-submodules &&
79 test_path_is_file super/sub/merge_strategy.t
82 test_expect_success
"submodule.recurse option triggers recursive pull" '
83 test_commit -C child merge_strategy_2 &&
84 git -C parent submodule update --remote &&
85 git -C parent add sub &&
86 git -C parent commit -m "update submodule" &&
88 git -C super -c submodule.recurse pull --no-rebase &&
89 test_path_is_file super/sub/merge_strategy_2.t
92 test_expect_success
" --[no-]recurse-submodule and submodule.recurse" '
93 test_commit -C child merge_strategy_3 &&
94 git -C parent submodule update --remote &&
95 git -C parent add sub &&
96 git -C parent commit -m "update submodule" &&
98 git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase &&
99 test_path_is_missing super/sub/merge_strategy_3.t &&
100 git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase &&
101 test_path_is_file super/sub/merge_strategy_3.t &&
103 test_commit -C child merge_strategy_4 &&
104 git -C parent submodule update --remote &&
105 git -C parent add sub &&
106 git -C parent commit -m "update submodule" &&
108 git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase &&
109 test_path_is_missing super/sub/merge_strategy_4.t &&
110 git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase &&
111 test_path_is_file super/sub/merge_strategy_4.t
114 test_expect_success
'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
115 # This tests the following scenario :
116 # - local submodule has new commits
117 # - local superproject does not have new commits
118 # - upstream superproject has new commits that change the submodule pointer
121 test_commit -C child rebase_strategy &&
122 git -C parent submodule update --remote &&
123 git -C parent add sub &&
124 git -C parent commit -m "update submodule" &&
126 # also have local commits
127 test_commit -C super/sub local_stuff &&
129 git -C super pull --rebase --recurse-submodules &&
130 test_path_is_file super/sub/rebase_strategy.t &&
131 test_path_is_file super/sub/local_stuff.t
134 test_expect_success
'pull --rebase --recurse-submodules fails if both sides record submodule changes' '
135 # This tests the following scenario :
136 # - local superproject has new commits that change the submodule pointer
137 # - upstream superproject has new commits that change the submodule pointer
139 # local changes in submodule recorded in superproject:
140 test_commit -C super/sub local_stuff_2 &&
141 git -C super add sub &&
142 git -C super commit -m "local update submodule" &&
144 # and in the remote as well:
145 test_commit -C child important_upstream_work &&
146 git -C parent submodule update --remote &&
147 git -C parent add sub &&
148 git -C parent commit -m "remote update submodule" &&
150 # Unfortunately we fail here, despite no conflict in the
151 # submodule itself, but the merge strategy in submodules
152 # does not support rebase:
153 test_must_fail git -C super pull --rebase --recurse-submodules 2>err &&
154 test_i18ngrep "locally recorded submodule modifications" err
157 test_expect_success
'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
158 # This tests the following scenario :
159 # - local submodule does not have new commits
160 # - local superproject has new commits that *do not* change the submodule pointer
161 # - upstream superproject has new commits that *do not* change the submodule pointer
162 # - local superproject branch has no fork-point with its remote-tracking counter-part
164 # create upstream superproject
165 test_create_repo submodule &&
166 test_commit -C submodule first_in_sub &&
168 test_create_repo superprojet &&
169 test_commit -C superprojet first_in_super &&
170 git -C superprojet submodule add ../submodule &&
171 git -C superprojet commit -m "add submodule" &&
172 test_commit -C superprojet third_in_super &&
175 git clone --recurse-submodules superprojet superclone &&
177 # add commits upstream
178 test_commit -C superprojet fourth_in_super &&
180 # create topic branch in clone, not based on any remote-tracking branch
181 git -C superclone checkout -b feat HEAD~1 &&
182 test_commit -C superclone first_on_feat &&
183 git -C superclone pull --rebase --recurse-submodules origin HEAD
188 # This test is particular because there is only a single commit in the upstream superproject
189 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
190 # ('child') hard-resets its branch to a new root commit with the same tree as the one
191 # from the upstream superproject, so that its branch has no merge-base with its
192 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
193 # The result is that the local branch is reset to the remote-tracking branch (as it was
194 # originally before the hard-reset).
196 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
197 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
198 # which adds the submodule.
199 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
200 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
201 test_expect_success
'branch has no merge base with remote-tracking counterpart' '
202 rm -rf parent child &&
204 test_create_repo a-submodule &&
205 test_commit -C a-submodule foo &&
207 test_create_repo parent &&
208 git -C parent submodule add "$(pwd)/a-submodule" &&
209 git -C parent commit -m foo &&
211 git clone parent child &&
213 # Reset the current branch so that it has no merge base with
214 # the remote-tracking branch.
215 OTHER=$(git -C child commit-tree -m bar \
216 $(git -C child rev-parse HEAD^{tree})) &&
217 git -C child reset --hard "$OTHER" &&
219 git -C child pull --recurse-submodules --rebase