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