Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t5572-pull-submodule.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t5572-pull-submodule.sh` 279 lines ยท 9795 bytes Raw Blame History 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 test_submodule_switch_func "git_pull_noff" 46 47 test_expect_success 'setup' ' 48 git config --global protocol.file.allow always 49 ' 50 51 test_expect_success 'pull --recurse-submodule setup' ' 52 test_create_repo child && 53 test_commit -C child bar && 54 55 test_create_repo parent && 56 test_commit -C child foo && 57 58 git -C parent submodule add ../child sub && 59 git -C parent commit -m "add submodule" && 60 61 git clone --recurse-submodules parent super 62 ' 63 64 test_expect_success 'recursive pull updates working tree' ' 65 test_commit -C child merge_strategy && 66 git -C parent submodule update --remote && 67 git -C parent add sub && 68 git -C parent commit -m "update submodule" && 69 70 git -C super pull --no-rebase --recurse-submodules && 71 test_path_is_file super/sub/merge_strategy.t 72 ' 73 74 test_expect_success "submodule.recurse option triggers recursive pull" ' 75 test_commit -C child merge_strategy_2 && 76 git -C parent submodule update --remote && 77 git -C parent add sub && 78 git -C parent commit -m "update submodule" && 79 80 git -C super -c submodule.recurse pull --no-rebase && 81 test_path_is_file super/sub/merge_strategy_2.t 82 ' 83 84 test_expect_success " --[no-]recurse-submodule and submodule.recurse" ' 85 test_commit -C child merge_strategy_3 && 86 git -C parent submodule update --remote && 87 git -C parent add sub && 88 git -C parent commit -m "update submodule" && 89 90 git -C super -c submodule.recurse pull --no-recurse-submodules --no-rebase && 91 test_path_is_missing super/sub/merge_strategy_3.t && 92 git -C super -c submodule.recurse=false pull --recurse-submodules --no-rebase && 93 test_path_is_file super/sub/merge_strategy_3.t && 94 95 test_commit -C child merge_strategy_4 && 96 git -C parent submodule update --remote && 97 git -C parent add sub && 98 git -C parent commit -m "update submodule" && 99 100 git -C super -c submodule.recurse=false pull --no-recurse-submodules --no-rebase && 101 test_path_is_missing super/sub/merge_strategy_4.t && 102 git -C super -c submodule.recurse=true pull --recurse-submodules --no-rebase && 103 test_path_is_file super/sub/merge_strategy_4.t 104 ' 105 106 test_expect_success "fetch.recurseSubmodules option triggers recursive fetch (but not recursive update)" ' 107 test_commit -C child merge_strategy_5 && 108 # Omit the parent commit, otherwise this passes with the 109 # default "pull" behavior. 110 111 git -C super -c fetch.recursesubmodules=true pull --no-rebase && 112 # Check that the submodule commit was fetched 113 sub_oid=$(git -C child rev-parse HEAD) && 114 git -C super/sub cat-file -e $sub_oid && 115 # Check that the submodule worktree did not update 116 test_path_is_missing super/sub/merge_strategy_5.t 117 ' 118 119 test_expect_success "fetch.recurseSubmodules takes precedence over submodule.recurse" ' 120 test_commit -C child merge_strategy_6 && 121 # Omit the parent commit, otherwise this passes with the 122 # default "pull" behavior. 123 124 git -C super -c submodule.recurse=false -c fetch.recursesubmodules=true pull --no-rebase && 125 # Check that the submodule commit was fetched 126 sub_oid=$(git -C child rev-parse HEAD) && 127 git -C super/sub cat-file -e $sub_oid && 128 # Check that the submodule worktree did not update 129 test_path_is_missing super/sub/merge_strategy_6.t 130 ' 131 132 test_expect_success 'pull --rebase --recurse-submodules (remote superproject submodule changes, local submodule changes)' ' 133 # This tests the following scenario : 134 # - local submodule has new commits 135 # - local superproject does not have new commits 136 # - upstream superproject has new commits that change the submodule pointer 137 138 # change upstream 139 test_commit -C child rebase_strategy && 140 git -C parent submodule update --remote && 141 git -C parent add sub && 142 git -C parent commit -m "update submodule" && 143 144 # also have local commits 145 test_commit -C super/sub local_stuff && 146 147 git -C super pull --rebase --recurse-submodules && 148 test_path_is_file super/sub/rebase_strategy.t && 149 test_path_is_file super/sub/local_stuff.t 150 ' 151 152 test_expect_success 'pull --rebase --recurse-submodules fails if both sides record submodule changes' ' 153 # This tests the following scenario : 154 # - local superproject has new commits that change the submodule pointer 155 # - upstream superproject has new commits that change the submodule pointer 156 157 # local changes in submodule recorded in superproject: 158 test_commit -C super/sub local_stuff_2 && 159 git -C super add sub && 160 git -C super commit -m "local update submodule" && 161 162 # and in the remote as well: 163 test_commit -C child important_upstream_work && 164 git -C parent submodule update --remote && 165 git -C parent add sub && 166 git -C parent commit -m "remote update submodule" && 167 168 # Unfortunately we fail here, despite no conflict in the 169 # submodule itself, but the merge strategy in submodules 170 # does not support rebase: 171 test_must_fail git -C super pull --rebase --recurse-submodules 2>err && 172 test_grep "locally recorded submodule modifications" err 173 ' 174 175 test_expect_success 'pull --rebase --recurse-submodules (no submodule changes, no fork-point)' ' 176 # This tests the following scenario : 177 # - local submodule does not have new commits 178 # - local superproject has new commits that *do not* change the submodule pointer 179 # - upstream superproject has new commits that *do not* change the submodule pointer 180 # - local superproject branch has no fork-point with its remote-tracking counter-part 181 182 # create upstream superproject 183 test_create_repo submodule && 184 test_commit -C submodule first_in_sub && 185 186 test_create_repo superprojet && 187 test_commit -C superprojet first_in_super && 188 git -C superprojet submodule add ../submodule && 189 git -C superprojet commit -m "add submodule" && 190 test_commit -C superprojet third_in_super && 191 192 # clone superproject 193 git clone --recurse-submodules superprojet superclone && 194 195 # add commits upstream 196 test_commit -C superprojet fourth_in_super && 197 198 # create topic branch in clone, not based on any remote-tracking branch 199 git -C superclone checkout -b feat HEAD~1 && 200 test_commit -C superclone first_on_feat && 201 git -C superclone pull --rebase --recurse-submodules origin HEAD 202 ' 203 204 # NOTE: 205 # 206 # This test is particular because there is only a single commit in the upstream superproject 207 # 'parent' (which adds the submodule 'a-submodule'). The clone of the superproject 208 # ('child') hard-resets its branch to a new root commit with the same tree as the one 209 # from the upstream superproject, so that its branch has no merge-base with its 210 # remote-tracking counterpart, and then calls 'git pull --recurse-submodules --rebase'. 211 # The result is that the local branch is reset to the remote-tracking branch (as it was 212 # originally before the hard-reset). 213 214 # The only commit in the range generated by 'submodule.c::submodule_touches_in_range' and 215 # passed to 'submodule.c::collect_changed_submodules' is the new (regenerated) initial commit, 216 # which adds the submodule. 217 # However, 'submodule_touches_in_range' does not error (even though this commit adds the submodule) 218 # because 'combine-diff.c::diff_tree_combined' returns early, as the initial commit has no parents. 219 test_expect_success 'branch has no merge base with remote-tracking counterpart' ' 220 rm -rf parent child && 221 222 test_create_repo a-submodule && 223 test_commit -C a-submodule foo && 224 test_commit -C a-submodule bar && 225 226 test_create_repo parent && 227 git -C parent submodule add "$(pwd)/a-submodule" && 228 git -C parent commit -m foo && 229 230 git clone parent child && 231 232 # Reset the current branch so that it has no merge base with 233 # the remote-tracking branch. 234 OTHER=$(git -C child commit-tree -m bar \ 235 $(git -C child rev-parse HEAD^{tree})) && 236 git -C child reset --hard "$OTHER" && 237 238 git -C child pull --recurse-submodules --rebase 239 ' 240 241 test_expect_success 'fetch submodule remote of different name from superproject' ' 242 git -C child remote rename origin o1 && 243 git -C child submodule update --init && 244 245 # Needs to create unreachable commit from current master branch. 246 git -C a-submodule checkout -b newmain HEAD^ && 247 test_commit -C a-submodule echo && 248 test_commit -C a-submodule moreecho && 249 subc=$(git -C a-submodule rev-parse --short HEAD) && 250 251 git -C parent/a-submodule fetch && 252 git -C parent/a-submodule checkout "$subc" && 253 git -C parent commit -m "update submodule" a-submodule && 254 git -C a-submodule reset --hard HEAD^^ && 255 256 git -C child pull --no-recurse-submodules && 257 git -C child submodule update && 258 test_path_is_file child/a-submodule/moreecho.t 259 ' 260 261 test_expect_success 'fetch non-origin submodule remote named different from superproject' ' 262 git -C child/a-submodule remote rename origin o2 && 263 264 # Create commit that is unreachable from current master branch 265 # newmain is already reset in the previous test 266 test_commit -C a-submodule echo_o2 && 267 test_commit -C a-submodule moreecho_o2 && 268 subc=$(git -C a-submodule rev-parse --short HEAD) && 269 270 git -C parent/a-submodule fetch && 271 git -C parent/a-submodule checkout "$subc" && 272 git -C parent commit -m "update submodule o2" a-submodule && 273 git -C a-submodule reset --hard HEAD^^ && 274 275 git -C child pull --recurse-submodules && 276 test_path_is_file child/a-submodule/moreecho_o2.t 277 ' 278 279 test_done