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/t6424-merge-unrelated-index-changes.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 / t6424-merge-unrelated-index-changes.sh` 310 lines ยท 7585 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description="merges with unrelated index changes" 4 5 . ./test-lib.sh 6 7 # Testcase for some simple merges 8 # A 9 # o-------o B 10 # \ 11 # \-----o C 12 # \ 13 # \---o D 14 # \ 15 # \-o E 16 # \ 17 # o F 18 # Commit A: some file a 19 # Commit B: adds file b, modifies end of a 20 # Commit C: adds file c 21 # Commit D: adds file d, modifies beginning of a 22 # Commit E: renames a->subdir/a, adds subdir/e 23 # Commit F: empty commit 24 25 test_expect_success 'setup trivial merges' ' 26 test_seq 1 10 >a && 27 git add a && 28 test_tick && git commit -m A && 29 30 git branch A && 31 git branch B && 32 git branch C && 33 git branch D && 34 git branch E && 35 git branch F && 36 37 git checkout B && 38 echo b >b && 39 echo 11 >>a && 40 git add a b && 41 test_tick && git commit -m B && 42 43 git checkout C && 44 echo c >c && 45 git add c && 46 test_tick && git commit -m C && 47 48 git checkout D && 49 test_seq 2 10 >a && 50 echo d >d && 51 git add a d && 52 test_tick && git commit -m D && 53 54 git checkout E && 55 mkdir subdir && 56 git mv a subdir/a && 57 echo e >subdir/e && 58 git add subdir && 59 test_tick && git commit -m E && 60 61 git checkout F && 62 test_tick && git commit --allow-empty -m F 63 ' 64 65 test_expect_success 'ff update' ' 66 git reset --hard && 67 git checkout A^0 && 68 69 touch random_file && git add random_file && 70 71 git merge E^0 && 72 73 test_must_fail git rev-parse HEAD:random_file && 74 test "$(git diff --name-only --cached E)" = "random_file" && 75 test_path_is_file random_file && 76 git rev-parse --verify :random_file 77 ' 78 79 test_expect_success 'ff update, important file modified' ' 80 git reset --hard && 81 git checkout A^0 && 82 83 mkdir subdir && 84 touch subdir/e && 85 git add subdir/e && 86 87 test_must_fail git merge E^0 && 88 test_path_is_file subdir/e && 89 git rev-parse --verify :subdir/e && 90 test_path_is_missing .git/MERGE_HEAD 91 ' 92 93 test_expect_success 'resolve, trivial' ' 94 git reset --hard && 95 git checkout B^0 && 96 97 touch random_file && git add random_file && 98 99 test_must_fail git merge -s resolve C^0 && 100 test_path_is_file random_file && 101 git rev-parse --verify :random_file && 102 test_path_is_missing .git/MERGE_HEAD 103 ' 104 105 test_expect_success 'resolve, non-trivial' ' 106 git reset --hard && 107 git checkout B^0 && 108 109 touch random_file && git add random_file && 110 111 test_must_fail git merge -s resolve D^0 && 112 test_path_is_file random_file && 113 git rev-parse --verify :random_file && 114 test_path_is_missing .git/MERGE_HEAD 115 ' 116 117 test_expect_success 'resolve, trivial, related file removed' ' 118 git reset --hard && 119 git checkout B^0 && 120 121 git rm a && 122 test_path_is_missing a && 123 124 test_must_fail git merge -s resolve C^0 && 125 126 test_path_is_missing a && 127 test_path_is_missing .git/MERGE_HEAD 128 ' 129 130 test_expect_success 'resolve, non-trivial, related file removed' ' 131 git reset --hard && 132 git checkout B^0 && 133 134 git rm a && 135 test_path_is_missing a && 136 137 # We also ask for recursive in order to turn off the "allow_trivial" 138 # setting in builtin/merge.c, and ensure that resolve really does 139 # correctly fail the merge (I guess this also tests that recursive 140 # correctly fails the merge, but the main thing we are attempting 141 # to test here is resolve and are just using the side effect of 142 # adding recursive to ensure that resolve is actually tested rather 143 # than the trivial merge codepath) 144 test_must_fail git merge -s resolve -s recursive D^0 && 145 146 test_path_is_missing a && 147 test_path_is_missing .git/MERGE_HEAD 148 ' 149 150 test_expect_success 'recursive' ' 151 git reset --hard && 152 git checkout B^0 && 153 154 touch random_file && git add random_file && 155 156 test_must_fail git merge -s recursive C^0 && 157 test_path_is_file random_file && 158 git rev-parse --verify :random_file && 159 test_path_is_missing .git/MERGE_HEAD 160 ' 161 162 test_expect_success 'recursive, when merge branch matches merge base' ' 163 git reset --hard && 164 git checkout B^0 && 165 166 touch random_file && git add random_file && 167 168 test_must_fail git merge -s recursive F^0 && 169 test_path_is_missing .git/MERGE_HEAD 170 ' 171 172 test_expect_success 'merge-recursive, when index==head but head!=HEAD' ' 173 git reset --hard && 174 git checkout C^0 && 175 176 # Make index match B 177 git diff C B -- | git apply --cached && 178 test_when_finished "git clean -fd" && # Do not leave untracked around 179 git write-tree >index-before && 180 # Merge B & F, with B as "head" 181 git merge-recursive A -- B F > out && 182 git write-tree >index-after && 183 test_cmp index-before index-after 184 ' 185 186 test_expect_success 'recursive, when file has staged changes not matching HEAD nor what a merge would give' ' 187 git reset --hard && 188 git checkout B^0 && 189 190 mkdir subdir && 191 test_seq 1 10 >subdir/a && 192 git add subdir/a && 193 git rev-parse --verify :subdir/a >expect && 194 195 # We have staged changes; merge should error out 196 test_must_fail git merge -s recursive E^0 2>err && 197 git rev-parse --verify :subdir/a >actual && 198 test_cmp expect actual && 199 test_grep "changes to the following files would be overwritten" err 200 ' 201 202 test_expect_success 'recursive, when file has staged changes matching what a merge would give' ' 203 git reset --hard && 204 git checkout B^0 && 205 206 mkdir subdir && 207 test_seq 1 11 >subdir/a && 208 git add subdir/a && 209 git rev-parse --verify :subdir/a >expect && 210 211 # We have staged changes; merge should error out 212 test_must_fail git merge -s recursive E^0 2>err && 213 git rev-parse --verify :subdir/a >actual && 214 test_cmp expect actual && 215 test_grep "changes to the following files would be overwritten" err 216 ' 217 218 test_expect_success 'octopus, unrelated file touched' ' 219 git reset --hard && 220 git checkout B^0 && 221 222 touch random_file && git add random_file && 223 224 test_must_fail git merge C^0 D^0 && 225 test_path_is_missing .git/MERGE_HEAD && 226 git rev-parse --verify :random_file && 227 test_path_exists random_file 228 ' 229 230 test_expect_success 'octopus, related file removed' ' 231 git reset --hard && 232 git checkout B^0 && 233 234 git rm b && 235 236 test_must_fail git merge C^0 D^0 && 237 test_path_is_missing b && 238 test_must_fail git rev-parse --verify :b && 239 test_path_is_missing .git/MERGE_HEAD 240 ' 241 242 test_expect_success 'octopus, related file modified' ' 243 git reset --hard && 244 git checkout B^0 && 245 246 echo 12 >>a && git add a && 247 git rev-parse --verify :a >expect && 248 249 test_must_fail git merge C^0 D^0 && 250 test_path_is_file a && 251 git rev-parse --verify :a >actual && 252 test_cmp expect actual && 253 test_path_is_missing .git/MERGE_HEAD 254 ' 255 256 test_expect_success 'ours' ' 257 git reset --hard && 258 git checkout B^0 && 259 260 touch random_file && git add random_file && 261 262 test_must_fail git merge -s ours C^0 && 263 test_path_is_file random_file && 264 git rev-parse --verify :random_file && 265 test_path_is_missing .git/MERGE_HEAD 266 ' 267 268 test_expect_success 'subtree' ' 269 git reset --hard && 270 git checkout B^0 && 271 272 touch random_file && git add random_file && 273 274 test_must_fail git merge -s subtree E^0 && 275 test_path_is_file random_file && 276 git rev-parse --verify :random_file && 277 test_path_is_missing .git/MERGE_HEAD 278 ' 279 280 test_expect_success 'avoid failure due to stat-dirty files' ' 281 git reset --hard && 282 git checkout B^0 && 283 284 # Make "a" be stat-dirty 285 test-tool chmtime =+1 a && 286 287 # stat-dirty file should not prevent stash creation in builtin/merge.c 288 git merge -s resolve -s recursive D^0 289 ' 290 291 test_expect_success 'with multiple strategies, recursive or ort failure do not early abort' ' 292 git reset --hard && 293 git checkout B^0 && 294 295 test_seq 0 10 >a && 296 git add a && 297 git rev-parse :a >expect && 298 299 test_must_fail git merge -s ort -s octopus C^0 >output 2>&1 && 300 301 test_grep "Trying merge strategy ort..." output && 302 test_grep "Trying merge strategy octopus..." output && 303 test_grep "No merge strategy handled the merge." output && 304 305 # Changes to "a" should remain staged 306 git rev-parse :a >actual && 307 test_cmp expect actual 308 ' 309 310 test_done