]>
Commit | Line | Data |
---|---|---|
921f50b4 JL |
1 | #!/bin/sh |
2 | ||
3 | test_description='pull can handle submodules' | |
4 | ||
5 | . ./test-lib.sh | |
6 | . "$TEST_DIRECTORY"/lib-submodule-update.sh | |
7 | ||
8 | reset_branch_to_HEAD () { | |
9 | git branch -D "$1" && | |
10 | git checkout -b "$1" HEAD && | |
11 | git branch --set-upstream-to="origin/$1" "$1" | |
12 | } | |
13 | ||
14 | git_pull () { | |
15 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
16 | may_only_be_test_must_fail "$2" && |
17 | $2 git pull | |
921f50b4 JL |
18 | } |
19 | ||
20 | # pulls without conflicts | |
aa06180a | 21 | test_submodule_switch_func "git_pull" |
921f50b4 JL |
22 | |
23 | git_pull_ff () { | |
24 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
25 | may_only_be_test_must_fail "$2" && |
26 | $2 git pull --ff | |
921f50b4 JL |
27 | } |
28 | ||
aa06180a | 29 | test_submodule_switch_func "git_pull_ff" |
921f50b4 JL |
30 | |
31 | git_pull_ff_only () { | |
32 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
33 | may_only_be_test_must_fail "$2" && |
34 | $2 git pull --ff-only | |
921f50b4 JL |
35 | } |
36 | ||
aa06180a | 37 | test_submodule_switch_func "git_pull_ff_only" |
921f50b4 JL |
38 | |
39 | git_pull_noff () { | |
40 | reset_branch_to_HEAD "$1" && | |
5b0ac09f DL |
41 | may_only_be_test_must_fail "$2" && |
42 | $2 git pull --no-ff | |
921f50b4 JL |
43 | } |
44 | ||
aa2faac0 EN |
45 | if test "$GIT_TEST_MERGE_ALGORITHM" != ort |
46 | then | |
47 | KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 | |
48 | KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 | |
49 | fi | |
aa06180a | 50 | test_submodule_switch_func "git_pull_noff" |
921f50b4 | 51 | |
225d2d50 TB |
52 | test_expect_success 'setup' ' |
53 | git config --global protocol.file.allow always | |
54 | ' | |
55 | ||
a6d7eb2c SB |
56 | test_expect_success 'pull --recurse-submodule setup' ' |
57 | test_create_repo child && | |
58 | test_commit -C child bar && | |
59 | ||
60 | test_create_repo parent && | |
61 | test_commit -C child foo && | |
62 | ||
63 | git -C parent submodule add ../child sub && | |
64 | git -C parent commit -m "add submodule" && | |
65 | ||
66 | git clone --recurse-submodules parent super | |
67 | ' | |
68 | ||
69 | test_expect_success 'recursive pull updates working tree' ' | |
70 | test_commit -C child merge_strategy && | |
71 | git -C parent submodule update --remote && | |
72 | git -C parent add sub && | |
73 | git -C parent commit -m "update submodule" && | |
74 | ||
75 | git -C super pull --no-rebase --recurse-submodules && | |
76 | test_path_is_file super/sub/merge_strategy.t | |
77 | ' | |
78 | ||
121e43fa NMC |
79 | test_expect_success "submodule.recurse option triggers recursive pull" ' |
80 | test_commit -C child merge_strategy_2 && | |
81 | git -C parent submodule update --remote && | |
82 | git -C parent add sub && | |
83 | git -C parent commit -m "update submodule" && | |
84 | ||
85 | git -C super -c submodule.recurse pull --no-rebase && | |
86 | test_path_is_file super/sub/merge_strategy_2.t | |
87 | ' | |
88 | ||
89 | test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' | |
90 | test_commit -C child merge_strategy_3 && | |
91 | git -C parent submodule update --remote && | |
92 | git -C parent add sub && | |
93 | git -C parent commit -m "update submodule" && | |
94 | ||
95 | git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase && | |
96 | test_path_is_missing super/sub/merge_strategy_3.t && | |
97 | git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase && | |
98 | test_path_is_file super/sub/merge_strategy_3.t && | |
99 | ||
100 | test_commit -C child merge_strategy_4 && | |
101 | git -C parent submodule update --remote && | |
102 | git -C parent add sub && | |
103 | git -C parent commit -m "update submodule" && | |
104 | ||
105 | git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase && | |
106 | test_path_is_missing super/sub/merge_strategy_4.t && | |
107 | git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase && | |
108 | test_path_is_file super/sub/merge_strategy_4.t | |
109 | ' | |
110 | ||
f260c6b4 PB |
111 | test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' |
112 | # This tests the following scenario : | |
113 | # - local submodule has new commits | |
114 | # - local superproject does not have new commits | |
115 | # - upstream superproject has new commits that change the submodule pointer | |
116 | ||
a6d7eb2c SB |
117 | # change upstream |
118 | test_commit -C child rebase_strategy && | |
119 | git -C parent submodule update --remote && | |
120 | git -C parent add sub && | |
121 | git -C parent commit -m "update submodule" && | |
122 | ||
123 | # also have local commits | |
124 | test_commit -C super/sub local_stuff && | |
125 | ||
126 | git -C super pull --rebase --recurse-submodules && | |
127 | test_path_is_file super/sub/rebase_strategy.t && | |
128 | test_path_is_file super/sub/local_stuff.t | |
129 | ' | |
130 | ||
f260c6b4 PB |
131 | test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' ' |
132 | # This tests the following scenario : | |
133 | # - local superproject has new commits that change the submodule pointer | |
134 | # - upstream superproject has new commits that change the submodule pointer | |
a6d7eb2c SB |
135 | |
136 | # local changes in submodule recorded in superproject: | |
137 | test_commit -C super/sub local_stuff_2 && | |
138 | git -C super add sub && | |
139 | git -C super commit -m "local update submodule" && | |
140 | ||
141 | # and in the remote as well: | |
142 | test_commit -C child important_upstream_work && | |
143 | git -C parent submodule update --remote && | |
144 | git -C parent add sub && | |
145 | git -C parent commit -m "remote update submodule" && | |
146 | ||
147 | # Unfortunately we fail here, despite no conflict in the | |
148 | # submodule itself, but the merge strategy in submodules | |
149 | # does not support rebase: | |
150 | test_must_fail git -C super pull --rebase --recurse-submodules 2>err && | |
151 | test_i18ngrep "locally recorded submodule modifications" err | |
152 | ' | |
153 | ||
5176f20f PB |
154 | test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' ' |
155 | # This tests the following scenario : | |
156 | # - local submodule does not have new commits | |
157 | # - local superproject has new commits that *do not* change the submodule pointer | |
158 | # - upstream superproject has new commits that *do not* change the submodule pointer | |
159 | # - local superproject branch has no fork-point with its remote-tracking counter-part | |
160 | ||
161 | # create upstream superproject | |
162 | test_create_repo submodule && | |
163 | test_commit -C submodule first_in_sub && | |
164 | ||
165 | test_create_repo superprojet && | |
166 | test_commit -C superprojet first_in_super && | |
167 | git -C superprojet submodule add ../submodule && | |
168 | git -C superprojet commit -m "add submodule" && | |
169 | test_commit -C superprojet third_in_super && | |
170 | ||
171 | # clone superproject | |
172 | git clone --recurse-submodules superprojet superclone && | |
173 | ||
174 | # add commits upstream | |
175 | test_commit -C superprojet fourth_in_super && | |
176 | ||
177 | # create topic branch in clone, not based on any remote-tracking branch | |
178 | git -C superclone checkout -b feat HEAD~1 && | |
179 | test_commit -C superclone first_on_feat && | |
27d7c859 | 180 | git -C superclone pull --rebase --recurse-submodules origin HEAD |
5176f20f PB |
181 | ' |
182 | ||
ba58ddd0 PB |
183 | # NOTE: |
184 | # | |
185 | # This test is particular because there is only a single commit in the upstream superproject | |
186 | # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject | |
187 | # ('child') hard-resets its branch to a new root commit with the same tree as the one | |
188 | # from the upstream superproject, so that its branch has no merge-base with its | |
189 | # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'. | |
190 | # The result is that the local branch is reset to the remote-tracking branch (as it was | |
191 | # originally before the hard-reset). | |
192 | ||
193 | # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and | |
194 | # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit, | |
195 | # which adds the submodule. | |
196 | # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule) | |
197 | # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents. | |
4d36f88b JT |
198 | test_expect_success 'branch has no merge base with remote-tracking counterpart' ' |
199 | rm -rf parent child && | |
200 | ||
201 | test_create_repo a-submodule && | |
202 | test_commit -C a-submodule foo && | |
203 | ||
204 | test_create_repo parent && | |
205 | git -C parent submodule add "$(pwd)/a-submodule" && | |
206 | git -C parent commit -m foo && | |
207 | ||
208 | git clone parent child && | |
209 | ||
27d7c859 JH |
210 | # Reset the current branch so that it has no merge base with |
211 | # the remote-tracking branch. | |
4d36f88b JT |
212 | OTHER=$(git -C child commit-tree -m bar \ |
213 | $(git -C child rev-parse HEAD^{tree})) && | |
214 | git -C child reset --hard "$OTHER" && | |
215 | ||
216 | git -C child pull --recurse-submodules --rebase | |
217 | ' | |
218 | ||
921f50b4 | 219 | test_done |