Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t5572-pull-submodule.sh
blob916e58c16696ba2676c3eb90e377c455f29c4016
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_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
10 . "$TEST_DIRECTORY"/lib-submodule-update.sh
12 reset_branch_to_HEAD () {
13 git branch -D "$1" &&
14 git checkout -b "$1" HEAD &&
15 git branch --set-upstream-to="origin/$1" "$1"
18 git_pull () {
19 reset_branch_to_HEAD "$1" &&
20 may_only_be_test_must_fail "$2" &&
21 $2 git pull
24 # pulls without conflicts
25 test_submodule_switch_func "git_pull"
27 git_pull_ff () {
28 reset_branch_to_HEAD "$1" &&
29 may_only_be_test_must_fail "$2" &&
30 $2 git pull --ff
33 test_submodule_switch_func "git_pull_ff"
35 git_pull_ff_only () {
36 reset_branch_to_HEAD "$1" &&
37 may_only_be_test_must_fail "$2" &&
38 $2 git pull --ff-only
41 test_submodule_switch_func "git_pull_ff_only"
43 git_pull_noff () {
44 reset_branch_to_HEAD "$1" &&
45 may_only_be_test_must_fail "$2" &&
46 $2 git pull --no-ff
49 if test "$GIT_TEST_MERGE_ALGORITHM" != ort
50 then
51 KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1
52 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1
54 test_submodule_switch_func "git_pull_noff"
56 test_expect_success 'setup' '
57 git config --global protocol.file.allow always
60 test_expect_success 'pull --recurse-submodule setup' '
61 test_create_repo child &&
62 test_commit -C child bar &&
64 test_create_repo parent &&
65 test_commit -C child foo &&
67 git -C parent submodule add ../child sub &&
68 git -C parent commit -m "add submodule" &&
70 git clone --recurse-submodules parent super
73 test_expect_success 'recursive pull updates working tree' '
74 test_commit -C child merge_strategy &&
75 git -C parent submodule update --remote &&
76 git -C parent add sub &&
77 git -C parent commit -m "update submodule" &&
79 git -C super pull --no-rebase --recurse-submodules &&
80 test_path_is_file super/sub/merge_strategy.t
83 test_expect_success "submodule.recurse option triggers recursive pull" '
84 test_commit -C child merge_strategy_2 &&
85 git -C parent submodule update --remote &&
86 git -C parent add sub &&
87 git -C parent commit -m "update submodule" &&
89 git -C super -c submodule.recurse pull --no-rebase &&
90 test_path_is_file super/sub/merge_strategy_2.t
93 test_expect_success " --[no-]recurse-submodule and submodule.recurse" '
94 test_commit -C child merge_strategy_3 &&
95 git -C parent submodule update --remote &&
96 git -C parent add sub &&
97 git -C parent commit -m "update submodule" &&
99 git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase &&
100 test_path_is_missing super/sub/merge_strategy_3.t &&
101 git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase &&
102 test_path_is_file super/sub/merge_strategy_3.t &&
104 test_commit -C child merge_strategy_4 &&
105 git -C parent submodule update --remote &&
106 git -C parent add sub &&
107 git -C parent commit -m "update submodule" &&
109 git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase &&
110 test_path_is_missing super/sub/merge_strategy_4.t &&
111 git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase &&
112 test_path_is_file super/sub/merge_strategy_4.t
115 test_expect_success "fetch.recurseSubmodules option triggers recursive fetch (but not recursive update)" '
116 test_commit -C child merge_strategy_5 &&
117 # Omit the parent commit, otherwise this passes with the
118 # default "pull" behavior.
120 git -C super -c fetch.recursesubmodules=true pull --no-rebase &&
121 # Check that the submodule commit was fetched
122 sub_oid=$(git -C child rev-parse HEAD) &&
123 git -C super/sub cat-file -e $sub_oid &&
124 # Check that the submodule worktree did not update
125 test_path_is_missing super/sub/merge_strategy_5.t
128 test_expect_success "fetch.recurseSubmodules takes precedence over submodule.recurse" '
129 test_commit -C child merge_strategy_6 &&
130 # Omit the parent commit, otherwise this passes with the
131 # default "pull" behavior.
133 git -C super -c submodule.recurse=false -c fetch.recursesubmodules=true pull --no-rebase &&
134 # Check that the submodule commit was fetched
135 sub_oid=$(git -C child rev-parse HEAD) &&
136 git -C super/sub cat-file -e $sub_oid &&
137 # Check that the submodule worktree did not update
138 test_path_is_missing super/sub/merge_strategy_6.t
141 test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
142 # This tests the following scenario :
143 # - local submodule has new commits
144 # - local superproject does not have new commits
145 # - upstream superproject has new commits that change the submodule pointer
147 # change upstream
148 test_commit -C child rebase_strategy &&
149 git -C parent submodule update --remote &&
150 git -C parent add sub &&
151 git -C parent commit -m "update submodule" &&
153 # also have local commits
154 test_commit -C super/sub local_stuff &&
156 git -C super pull --rebase --recurse-submodules &&
157 test_path_is_file super/sub/rebase_strategy.t &&
158 test_path_is_file super/sub/local_stuff.t
161 test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' '
162 # This tests the following scenario :
163 # - local superproject has new commits that change the submodule pointer
164 # - upstream superproject has new commits that change the submodule pointer
166 # local changes in submodule recorded in superproject:
167 test_commit -C super/sub local_stuff_2 &&
168 git -C super add sub &&
169 git -C super commit -m "local update submodule" &&
171 # and in the remote as well:
172 test_commit -C child important_upstream_work &&
173 git -C parent submodule update --remote &&
174 git -C parent add sub &&
175 git -C parent commit -m "remote update submodule" &&
177 # Unfortunately we fail here, despite no conflict in the
178 # submodule itself, but the merge strategy in submodules
179 # does not support rebase:
180 test_must_fail git -C super pull --rebase --recurse-submodules 2>err &&
181 test_grep "locally recorded submodule modifications" err
184 test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
185 # This tests the following scenario :
186 # - local submodule does not have new commits
187 # - local superproject has new commits that *do not* change the submodule pointer
188 # - upstream superproject has new commits that *do not* change the submodule pointer
189 # - local superproject branch has no fork-point with its remote-tracking counter-part
191 # create upstream superproject
192 test_create_repo submodule &&
193 test_commit -C submodule first_in_sub &&
195 test_create_repo superprojet &&
196 test_commit -C superprojet first_in_super &&
197 git -C superprojet submodule add ../submodule &&
198 git -C superprojet commit -m "add submodule" &&
199 test_commit -C superprojet third_in_super &&
201 # clone superproject
202 git clone --recurse-submodules superprojet superclone &&
204 # add commits upstream
205 test_commit -C superprojet fourth_in_super &&
207 # create topic branch in clone, not based on any remote-tracking branch
208 git -C superclone checkout -b feat HEAD~1 &&
209 test_commit -C superclone first_on_feat &&
210 git -C superclone pull --rebase --recurse-submodules origin HEAD
213 # NOTE:
215 # This test is particular because there is only a single commit in the upstream superproject
216 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
217 # ('child') hard-resets its branch to a new root commit with the same tree as the one
218 # from the upstream superproject, so that its branch has no merge-base with its
219 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
220 # The result is that the local branch is reset to the remote-tracking branch (as it was
221 # originally before the hard-reset).
223 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
224 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
225 # which adds the submodule.
226 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
227 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
228 test_expect_success 'branch has no merge base with remote-tracking counterpart' '
229 rm -rf parent child &&
231 test_create_repo a-submodule &&
232 test_commit -C a-submodule foo &&
234 test_create_repo parent &&
235 git -C parent submodule add "$(pwd)/a-submodule" &&
236 git -C parent commit -m foo &&
238 git clone parent child &&
240 # Reset the current branch so that it has no merge base with
241 # the remote-tracking branch.
242 OTHER=$(git -C child commit-tree -m bar \
243 $(git -C child rev-parse HEAD^{tree})) &&
244 git -C child reset --hard "$OTHER" &&
246 git -C child pull --recurse-submodules --rebase
249 test_done