Merge branch 'jc/tree-walk-drop-base-offset'
[git/debian.git] / t / t5572-pull-submodule.sh
blob4e917bf87d2d4213019797ffa4d12215ffeb05f5
1 #!/bin/sh
3 test_description='pull can handle submodules'
5 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
6 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-submodule-update.sh
11 reset_branch_to_HEAD () {
12 git branch -D "$1" &&
13 git checkout -b "$1" HEAD &&
14 git branch --set-upstream-to="origin/$1" "$1"
17 git_pull () {
18 reset_branch_to_HEAD "$1" &&
19 may_only_be_test_must_fail "$2" &&
20 $2 git pull
23 # pulls without conflicts
24 test_submodule_switch_func "git_pull"
26 git_pull_ff () {
27 reset_branch_to_HEAD "$1" &&
28 may_only_be_test_must_fail "$2" &&
29 $2 git pull --ff
32 test_submodule_switch_func "git_pull_ff"
34 git_pull_ff_only () {
35 reset_branch_to_HEAD "$1" &&
36 may_only_be_test_must_fail "$2" &&
37 $2 git pull --ff-only
40 test_submodule_switch_func "git_pull_ff_only"
42 git_pull_noff () {
43 reset_branch_to_HEAD "$1" &&
44 may_only_be_test_must_fail "$2" &&
45 $2 git pull --no-ff
48 if test "$GIT_TEST_MERGE_ALGORITHM" != ort
49 then
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 "fetch.recurseSubmodules option triggers recursive fetch (but not recursive update)" '
115 test_commit -C child merge_strategy_5 &&
116 # Omit the parent commit, otherwise this passes with the
117 # default "pull" behavior.
119 git -C super -c fetch.recursesubmodules=true pull --no-rebase &&
120 # Check that the submodule commit was fetched
121 sub_oid=$(git -C child rev-parse HEAD) &&
122 git -C super/sub cat-file -e $sub_oid &&
123 # Check that the submodule worktree did not update
124 test_path_is_missing super/sub/merge_strategy_5.t
127 test_expect_success "fetch.recurseSubmodules takes precedence over submodule.recurse" '
128 test_commit -C child merge_strategy_6 &&
129 # Omit the parent commit, otherwise this passes with the
130 # default "pull" behavior.
132 git -C super -c submodule.recurse=false -c fetch.recursesubmodules=true pull --no-rebase &&
133 # Check that the submodule commit was fetched
134 sub_oid=$(git -C child rev-parse HEAD) &&
135 git -C super/sub cat-file -e $sub_oid &&
136 # Check that the submodule worktree did not update
137 test_path_is_missing super/sub/merge_strategy_6.t
140 test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
141 # This tests the following scenario :
142 # - local submodule has new commits
143 # - local superproject does not have new commits
144 # - upstream superproject has new commits that change the submodule pointer
146 # change upstream
147 test_commit -C child rebase_strategy &&
148 git -C parent submodule update --remote &&
149 git -C parent add sub &&
150 git -C parent commit -m "update submodule" &&
152 # also have local commits
153 test_commit -C super/sub local_stuff &&
155 git -C super pull --rebase --recurse-submodules &&
156 test_path_is_file super/sub/rebase_strategy.t &&
157 test_path_is_file super/sub/local_stuff.t
160 test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' '
161 # This tests the following scenario :
162 # - local superproject has new commits that change the submodule pointer
163 # - upstream superproject has new commits that change the submodule pointer
165 # local changes in submodule recorded in superproject:
166 test_commit -C super/sub local_stuff_2 &&
167 git -C super add sub &&
168 git -C super commit -m "local update submodule" &&
170 # and in the remote as well:
171 test_commit -C child important_upstream_work &&
172 git -C parent submodule update --remote &&
173 git -C parent add sub &&
174 git -C parent commit -m "remote update submodule" &&
176 # Unfortunately we fail here, despite no conflict in the
177 # submodule itself, but the merge strategy in submodules
178 # does not support rebase:
179 test_must_fail git -C super pull --rebase --recurse-submodules 2>err &&
180 test_i18ngrep "locally recorded submodule modifications" err
183 test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
184 # This tests the following scenario :
185 # - local submodule does not have new commits
186 # - local superproject has new commits that *do not* change the submodule pointer
187 # - upstream superproject has new commits that *do not* change the submodule pointer
188 # - local superproject branch has no fork-point with its remote-tracking counter-part
190 # create upstream superproject
191 test_create_repo submodule &&
192 test_commit -C submodule first_in_sub &&
194 test_create_repo superprojet &&
195 test_commit -C superprojet first_in_super &&
196 git -C superprojet submodule add ../submodule &&
197 git -C superprojet commit -m "add submodule" &&
198 test_commit -C superprojet third_in_super &&
200 # clone superproject
201 git clone --recurse-submodules superprojet superclone &&
203 # add commits upstream
204 test_commit -C superprojet fourth_in_super &&
206 # create topic branch in clone, not based on any remote-tracking branch
207 git -C superclone checkout -b feat HEAD~1 &&
208 test_commit -C superclone first_on_feat &&
209 git -C superclone pull --rebase --recurse-submodules origin HEAD
212 # NOTE:
214 # This test is particular because there is only a single commit in the upstream superproject
215 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
216 # ('child') hard-resets its branch to a new root commit with the same tree as the one
217 # from the upstream superproject, so that its branch has no merge-base with its
218 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
219 # The result is that the local branch is reset to the remote-tracking branch (as it was
220 # originally before the hard-reset).
222 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
223 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
224 # which adds the submodule.
225 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
226 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
227 test_expect_success 'branch has no merge base with remote-tracking counterpart' '
228 rm -rf parent child &&
230 test_create_repo a-submodule &&
231 test_commit -C a-submodule foo &&
233 test_create_repo parent &&
234 git -C parent submodule add "$(pwd)/a-submodule" &&
235 git -C parent commit -m foo &&
237 git clone parent child &&
239 # Reset the current branch so that it has no merge base with
240 # the remote-tracking branch.
241 OTHER=$(git -C child commit-tree -m bar \
242 $(git -C child rev-parse HEAD^{tree})) &&
243 git -C child reset --hard "$OTHER" &&
245 git -C child pull --recurse-submodules --rebase
248 test_done