]> git.ipfire.org Git - thirdparty/git.git/blob - t/t5572-pull-submodule.sh
Sync with 2.33.5
[thirdparty/git.git] / t / t5572-pull-submodule.sh
1 #!/bin/sh
2
3 test_description='pull can handle submodules'
4
5 GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
6 export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
7
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" &&
19 may_only_be_test_must_fail "$2" &&
20 $2 git pull
21 }
22
23 # pulls without conflicts
24 test_submodule_switch_func "git_pull"
25
26 git_pull_ff () {
27 reset_branch_to_HEAD "$1" &&
28 may_only_be_test_must_fail "$2" &&
29 $2 git pull --ff
30 }
31
32 test_submodule_switch_func "git_pull_ff"
33
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
38 }
39
40 test_submodule_switch_func "git_pull_ff_only"
41
42 git_pull_noff () {
43 reset_branch_to_HEAD "$1" &&
44 may_only_be_test_must_fail "$2" &&
45 $2 git pull --no-ff
46 }
47
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
53 test_submodule_switch_func "git_pull_noff"
54
55 test_expect_success 'setup' '
56 git config --global protocol.file.allow always
57 '
58
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
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
114 test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' '
115 # This tests the following scenario :
116 # - local submodule has new commits
117 # - local superproject does not have new commits
118 # - upstream superproject has new commits that change the submodule pointer
119
120 # change upstream
121 test_commit -C child rebase_strategy &&
122 git -C parent submodule update --remote &&
123 git -C parent add sub &&
124 git -C parent commit -m "update submodule" &&
125
126 # also have local commits
127 test_commit -C super/sub local_stuff &&
128
129 git -C super pull --rebase --recurse-submodules &&
130 test_path_is_file super/sub/rebase_strategy.t &&
131 test_path_is_file super/sub/local_stuff.t
132 '
133
134 test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' '
135 # This tests the following scenario :
136 # - local superproject has new commits that change the submodule pointer
137 # - upstream superproject has new commits that change the submodule pointer
138
139 # local changes in submodule recorded in superproject:
140 test_commit -C super/sub local_stuff_2 &&
141 git -C super add sub &&
142 git -C super commit -m "local update submodule" &&
143
144 # and in the remote as well:
145 test_commit -C child important_upstream_work &&
146 git -C parent submodule update --remote &&
147 git -C parent add sub &&
148 git -C parent commit -m "remote update submodule" &&
149
150 # Unfortunately we fail here, despite no conflict in the
151 # submodule itself, but the merge strategy in submodules
152 # does not support rebase:
153 test_must_fail git -C super pull --rebase --recurse-submodules 2>err &&
154 test_i18ngrep "locally recorded submodule modifications" err
155 '
156
157 test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' '
158 # This tests the following scenario :
159 # - local submodule does not have new commits
160 # - local superproject has new commits that *do not* change the submodule pointer
161 # - upstream superproject has new commits that *do not* change the submodule pointer
162 # - local superproject branch has no fork-point with its remote-tracking counter-part
163
164 # create upstream superproject
165 test_create_repo submodule &&
166 test_commit -C submodule first_in_sub &&
167
168 test_create_repo superprojet &&
169 test_commit -C superprojet first_in_super &&
170 git -C superprojet submodule add ../submodule &&
171 git -C superprojet commit -m "add submodule" &&
172 test_commit -C superprojet third_in_super &&
173
174 # clone superproject
175 git clone --recurse-submodules superprojet superclone &&
176
177 # add commits upstream
178 test_commit -C superprojet fourth_in_super &&
179
180 # create topic branch in clone, not based on any remote-tracking branch
181 git -C superclone checkout -b feat HEAD~1 &&
182 test_commit -C superclone first_on_feat &&
183 git -C superclone pull --rebase --recurse-submodules origin HEAD
184 '
185
186 # NOTE:
187 #
188 # This test is particular because there is only a single commit in the upstream superproject
189 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject
190 # ('child') hard-resets its branch to a new root commit with the same tree as the one
191 # from the upstream superproject, so that its branch has no merge-base with its
192 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'.
193 # The result is that the local branch is reset to the remote-tracking branch (as it was
194 # originally before the hard-reset).
195
196 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and
197 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit,
198 # which adds the submodule.
199 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule)
200 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents.
201 test_expect_success 'branch has no merge base with remote-tracking counterpart' '
202 rm -rf parent child &&
203
204 test_create_repo a-submodule &&
205 test_commit -C a-submodule foo &&
206
207 test_create_repo parent &&
208 git -C parent submodule add "$(pwd)/a-submodule" &&
209 git -C parent commit -m foo &&
210
211 git clone parent child &&
212
213 # Reset the current branch so that it has no merge base with
214 # the remote-tracking branch.
215 OTHER=$(git -C child commit-tree -m bar \
216 $(git -C child rev-parse HEAD^{tree})) &&
217 git -C child reset --hard "$OTHER" &&
218
219 git -C child pull --recurse-submodules --rebase
220 '
221
222 test_done