]>
Commit | Line | Data |
---|---|---|
921f50b4 JL |
1 | #!/bin/sh |
2 | ||
3 | test_description='pull can handle submodules' | |
4 | ||
13a2f620 JT |
5 | GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1 |
6 | export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB | |
7 | ||
921f50b4 JL |
8 | . ./test-lib.sh |
9 | . "$TEST_DIRECTORY"/lib-submodule-update.sh | |
10 | ||
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" | |
15 | } | |
16 | ||
17 | git_pull () { | |
18 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
19 | may_only_be_test_must_fail "$2" && |
20 | $2 git pull | |
921f50b4 JL |
21 | } |
22 | ||
23 | # pulls without conflicts | |
aa06180a | 24 | test_submodule_switch_func "git_pull" |
921f50b4 JL |
25 | |
26 | git_pull_ff () { | |
27 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
28 | may_only_be_test_must_fail "$2" && |
29 | $2 git pull --ff | |
921f50b4 JL |
30 | } |
31 | ||
aa06180a | 32 | test_submodule_switch_func "git_pull_ff" |
921f50b4 JL |
33 | |
34 | git_pull_ff_only () { | |
35 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
36 | may_only_be_test_must_fail "$2" && |
37 | $2 git pull --ff-only | |
921f50b4 JL |
38 | } |
39 | ||
aa06180a | 40 | test_submodule_switch_func "git_pull_ff_only" |
921f50b4 JL |
41 | |
42 | git_pull_noff () { | |
43 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
44 | may_only_be_test_must_fail "$2" && |
45 | $2 git pull --no-ff | |
921f50b4 JL |
46 | } |
47 | ||
aa2faac0 EN |
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 | |
52 | fi | |
aa06180a | 53 | test_submodule_switch_func "git_pull_noff" |
921f50b4 | 54 | |
225d2d50 TB |
55 | test_expect_success 'setup' ' |
56 | git config --global protocol.file.allow always | |
57 | ' | |
58 | ||
a6d7eb2c SB |
59 | test_expect_success 'pull --recurse-submodule setup' ' |
60 | test_create_repo child && | |
61 | test_commit -C child bar && | |
62 | ||
63 | test_create_repo parent && | |
64 | test_commit -C child foo && | |
65 | ||
66 | git -C parent submodule add ../child sub && | |
67 | git -C parent commit -m "add submodule" && | |
68 | ||
69 | git clone --recurse-submodules parent super | |
70 | ' | |
71 | ||
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" && | |
77 | ||
78 | git -C super pull --no-rebase --recurse-submodules && | |
79 | test_path_is_file super/sub/merge_strategy.t | |
80 | ' | |
81 | ||
121e43fa NMC |
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" && | |
87 | ||
88 | git -C super -c submodule.recurse pull --no-rebase && | |
89 | test_path_is_file super/sub/merge_strategy_2.t | |
90 | ' | |
91 | ||
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" && | |
97 | ||
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 && | |
102 | ||
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" && | |
107 | ||
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 | |
112 | ' | |
113 | ||
58194173 GC |
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. | |
118 | ||
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 | |
b126b65b | 124 | test_path_is_missing super/sub/merge_strategy_5.t |
58194173 GC |
125 | ' |
126 | ||
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. | |
131 | ||
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 | |
b126b65b | 137 | test_path_is_missing super/sub/merge_strategy_6.t |
58194173 GC |
138 | ' |
139 | ||
f260c6b4 PB |
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 | |
145 | ||
a6d7eb2c SB |
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" && | |
151 | ||
152 | # also have local commits | |
153 | test_commit -C super/sub local_stuff && | |
154 | ||
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 | |
158 | ' | |
159 | ||
f260c6b4 PB |
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 | |
a6d7eb2c SB |
164 | |
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" && | |
169 | ||
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" && | |
175 | ||
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 && | |
6789275d | 180 | test_grep "locally recorded submodule modifications" err |
a6d7eb2c SB |
181 | ' |
182 | ||
5176f20f PB |
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 | |
189 | ||
190 | # create upstream superproject | |
191 | test_create_repo submodule && | |
192 | test_commit -C submodule first_in_sub && | |
193 | ||
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 && | |
199 | ||
200 | # clone superproject | |
201 | git clone --recurse-submodules superprojet superclone && | |
202 | ||
203 | # add commits upstream | |
204 | test_commit -C superprojet fourth_in_super && | |
205 | ||
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 && | |
27d7c859 | 209 | git -C superclone pull --rebase --recurse-submodules origin HEAD |
5176f20f PB |
210 | ' |
211 | ||
ba58ddd0 PB |
212 | # NOTE: |
213 | # | |
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). | |
221 | ||
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. | |
4d36f88b JT |
227 | test_expect_success 'branch has no merge base with remote-tracking counterpart' ' |
228 | rm -rf parent child && | |
229 | ||
230 | test_create_repo a-submodule && | |
231 | test_commit -C a-submodule foo && | |
232 | ||
233 | test_create_repo parent && | |
234 | git -C parent submodule add "$(pwd)/a-submodule" && | |
235 | git -C parent commit -m foo && | |
236 | ||
237 | git clone parent child && | |
238 | ||
27d7c859 JH |
239 | # Reset the current branch so that it has no merge base with |
240 | # the remote-tracking branch. | |
4d36f88b JT |
241 | OTHER=$(git -C child commit-tree -m bar \ |
242 | $(git -C child rev-parse HEAD^{tree})) && | |
243 | git -C child reset --hard "$OTHER" && | |
244 | ||
245 | git -C child pull --recurse-submodules --rebase | |
246 | ' | |
247 | ||
921f50b4 | 248 | test_done |