3 test_description
='pull can handle submodules'
6 .
"$TEST_DIRECTORY"/lib-submodule-update.sh
8 reset_branch_to_HEAD
() {
10 git checkout
-b "$1" HEAD
&&
11 git branch
--set-upstream-to="origin/$1" "$1"
15 reset_branch_to_HEAD
"$1" &&
16 may_only_be_test_must_fail
"$2" &&
20 # pulls without conflicts
21 test_submodule_switch_func
"git_pull"
24 reset_branch_to_HEAD
"$1" &&
25 may_only_be_test_must_fail
"$2" &&
29 test_submodule_switch_func
"git_pull_ff"
32 reset_branch_to_HEAD
"$1" &&
33 may_only_be_test_must_fail
"$2" &&
37 test_submodule_switch_func
"git_pull_ff_only"
40 reset_branch_to_HEAD
"$1" &&
41 may_only_be_test_must_fail
"$2" &&
45 if test "$GIT_TEST_MERGE_ALGORITHM" != ort
47 KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR
=1
48 KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES
=1
50 test_submodule_switch_func
"git_pull_noff"
52 test_expect_success
'setup' '
53 git config --global protocol.file.allow always
56 test_expect_success
'pull --recurse-submodule setup' '
57 test_create_repo child &&
58 test_commit -C child bar &&
60 test_create_repo parent &&
61 test_commit -C child foo &&
63 git -C parent submodule add ../child sub &&
64 git -C parent commit -m "add submodule" &&
66 git clone --recurse-submodules parent super
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" &&
75 git -C super pull --no-rebase --recurse-submodules &&
76 test_path_is_file super/sub/merge_strategy.t
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" &&
85 git -C super -c submodule.recurse pull --no-rebase &&
86 test_path_is_file super/sub/merge_strategy_2.t
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" &&
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 &&
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" &&
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
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
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" &&
123 # also have local commits
124 test_commit -C super/sub local_stuff &&
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
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
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" &&
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" &&
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
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
161 # create upstream superproject
162 test_create_repo submodule &&
163 test_commit -C submodule first_in_sub &&
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 &&
172 git clone --recurse-submodules superprojet superclone &&
174 # add commits upstream
175 test_commit -C superprojet fourth_in_super &&
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 &&
180 git -C superclone pull --rebase --recurse-submodules origin HEAD
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).
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.
198 test_expect_success
'branch has no merge base with remote-tracking counterpart' '
199 rm -rf parent child &&
201 test_create_repo a-submodule &&
202 test_commit -C a-submodule foo &&
204 test_create_repo parent &&
205 git -C parent submodule add "$(pwd)/a-submodule" &&
206 git -C parent commit -m foo &&
208 git clone parent child &&
210 # Reset the current branch so that it has no merge base with
211 # the remote-tracking branch.
212 OTHER=$(git -C child commit-tree -m bar \
213 $(git -C child rev-parse HEAD^{tree})) &&
214 git -C child reset --hard "$OTHER" &&
216 git -C child pull --recurse-submodules --rebase