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