]>
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 | |
a6d7eb2c SB |
52 | test_expect_success 'pull --recurse-submodule setup' ' |
53 | test_create_repo child && | |
54 | test_commit -C child bar && | |
55 | ||
56 | test_create_repo parent && | |
57 | test_commit -C child foo && | |
58 | ||
59 | git -C parent submodule add ../child sub && | |
60 | git -C parent commit -m "add submodule" && | |
61 | ||
62 | git clone --recurse-submodules parent super | |
63 | ' | |
64 | ||
65 | test_expect_success 'recursive pull updates working tree' ' | |
66 | test_commit -C child merge_strategy && | |
67 | git -C parent submodule update --remote && | |
68 | git -C parent add sub && | |
69 | git -C parent commit -m "update submodule" && | |
70 | ||
71 | git -C super pull --no-rebase --recurse-submodules && | |
72 | test_path_is_file super/sub/merge_strategy.t | |
73 | ' | |
74 | ||
121e43fa NMC |
75 | test_expect_success "submodule.recurse option triggers recursive pull" ' |
76 | test_commit -C child merge_strategy_2 && | |
77 | git -C parent submodule update --remote && | |
78 | git -C parent add sub && | |
79 | git -C parent commit -m "update submodule" && | |
80 | ||
81 | git -C super -c submodule.recurse pull --no-rebase && | |
82 | test_path_is_file super/sub/merge_strategy_2.t | |
83 | ' | |
84 | ||
85 | test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' | |
86 | test_commit -C child merge_strategy_3 && | |
87 | git -C parent submodule update --remote && | |
88 | git -C parent add sub && | |
89 | git -C parent commit -m "update submodule" && | |
90 | ||
91 | git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase && | |
92 | test_path_is_missing super/sub/merge_strategy_3.t && | |
93 | git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase && | |
94 | test_path_is_file super/sub/merge_strategy_3.t && | |
95 | ||
96 | test_commit -C child merge_strategy_4 && | |
97 | git -C parent submodule update --remote && | |
98 | git -C parent add sub && | |
99 | git -C parent commit -m "update submodule" && | |
100 | ||
101 | git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase && | |
102 | test_path_is_missing super/sub/merge_strategy_4.t && | |
103 | git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase && | |
104 | test_path_is_file super/sub/merge_strategy_4.t | |
105 | ' | |
106 | ||
f260c6b4 PB |
107 | test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' |
108 | # This tests the following scenario : | |
109 | # - local submodule has new commits | |
110 | # - local superproject does not have new commits | |
111 | # - upstream superproject has new commits that change the submodule pointer | |
112 | ||
a6d7eb2c SB |
113 | # change upstream |
114 | test_commit -C child rebase_strategy && | |
115 | git -C parent submodule update --remote && | |
116 | git -C parent add sub && | |
117 | git -C parent commit -m "update submodule" && | |
118 | ||
119 | # also have local commits | |
120 | test_commit -C super/sub local_stuff && | |
121 | ||
122 | git -C super pull --rebase --recurse-submodules && | |
123 | test_path_is_file super/sub/rebase_strategy.t && | |
124 | test_path_is_file super/sub/local_stuff.t | |
125 | ' | |
126 | ||
f260c6b4 PB |
127 | test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' ' |
128 | # This tests the following scenario : | |
129 | # - local superproject has new commits that change the submodule pointer | |
130 | # - upstream superproject has new commits that change the submodule pointer | |
a6d7eb2c SB |
131 | |
132 | # local changes in submodule recorded in superproject: | |
133 | test_commit -C super/sub local_stuff_2 && | |
134 | git -C super add sub && | |
135 | git -C super commit -m "local update submodule" && | |
136 | ||
137 | # and in the remote as well: | |
138 | test_commit -C child important_upstream_work && | |
139 | git -C parent submodule update --remote && | |
140 | git -C parent add sub && | |
141 | git -C parent commit -m "remote update submodule" && | |
142 | ||
143 | # Unfortunately we fail here, despite no conflict in the | |
144 | # submodule itself, but the merge strategy in submodules | |
145 | # does not support rebase: | |
146 | test_must_fail git -C super pull --rebase --recurse-submodules 2>err && | |
147 | test_i18ngrep "locally recorded submodule modifications" err | |
148 | ' | |
149 | ||
5176f20f PB |
150 | test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' ' |
151 | # This tests the following scenario : | |
152 | # - local submodule does not have new commits | |
153 | # - local superproject has new commits that *do not* change the submodule pointer | |
154 | # - upstream superproject has new commits that *do not* change the submodule pointer | |
155 | # - local superproject branch has no fork-point with its remote-tracking counter-part | |
156 | ||
157 | # create upstream superproject | |
158 | test_create_repo submodule && | |
159 | test_commit -C submodule first_in_sub && | |
160 | ||
161 | test_create_repo superprojet && | |
162 | test_commit -C superprojet first_in_super && | |
163 | git -C superprojet submodule add ../submodule && | |
164 | git -C superprojet commit -m "add submodule" && | |
165 | test_commit -C superprojet third_in_super && | |
166 | ||
167 | # clone superproject | |
168 | git clone --recurse-submodules superprojet superclone && | |
169 | ||
170 | # add commits upstream | |
171 | test_commit -C superprojet fourth_in_super && | |
172 | ||
173 | # create topic branch in clone, not based on any remote-tracking branch | |
174 | git -C superclone checkout -b feat HEAD~1 && | |
175 | test_commit -C superclone first_on_feat && | |
27d7c859 | 176 | git -C superclone pull --rebase --recurse-submodules origin HEAD |
5176f20f PB |
177 | ' |
178 | ||
ba58ddd0 PB |
179 | # NOTE: |
180 | # | |
181 | # This test is particular because there is only a single commit in the upstream superproject | |
182 | # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject | |
183 | # ('child') hard-resets its branch to a new root commit with the same tree as the one | |
184 | # from the upstream superproject, so that its branch has no merge-base with its | |
185 | # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'. | |
186 | # The result is that the local branch is reset to the remote-tracking branch (as it was | |
187 | # originally before the hard-reset). | |
188 | ||
189 | # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and | |
190 | # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit, | |
191 | # which adds the submodule. | |
192 | # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule) | |
193 | # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents. | |
4d36f88b JT |
194 | test_expect_success 'branch has no merge base with remote-tracking counterpart' ' |
195 | rm -rf parent child && | |
196 | ||
197 | test_create_repo a-submodule && | |
198 | test_commit -C a-submodule foo && | |
199 | ||
200 | test_create_repo parent && | |
201 | git -C parent submodule add "$(pwd)/a-submodule" && | |
202 | git -C parent commit -m foo && | |
203 | ||
204 | git clone parent child && | |
205 | ||
27d7c859 JH |
206 | # Reset the current branch so that it has no merge base with |
207 | # the remote-tracking branch. | |
4d36f88b JT |
208 | OTHER=$(git -C child commit-tree -m bar \ |
209 | $(git -C child rev-parse HEAD^{tree})) && | |
210 | git -C child reset --hard "$OTHER" && | |
211 | ||
212 | git -C child pull --recurse-submodules --rebase | |
213 | ' | |
214 | ||
921f50b4 | 215 | test_done |