Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='recursive merge diff3 style conflict markers' |
| 4 | |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 5 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
Johannes Schindelin | 334afbc | 2020-11-18 23:44:19 +0000 | [diff] [blame] | 6 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 7 | |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 8 | . ./test-lib.sh |
| 9 | |
| 10 | # Setup: |
| 11 | # L1 |
| 12 | # \ |
| 13 | # ? |
| 14 | # / |
| 15 | # R1 |
| 16 | # |
| 17 | # Where: |
| 18 | # L1 and R1 both have a file named 'content' but have no common history |
| 19 | # |
| 20 | |
| 21 | test_expect_success 'setup no merge base' ' |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 22 | git init no_merge_base && |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 23 | ( |
| 24 | cd no_merge_base && |
| 25 | |
| 26 | git checkout -b L && |
| 27 | test_commit A content A && |
| 28 | |
| 29 | git checkout --orphan R && |
| 30 | test_commit B content B |
| 31 | ) |
| 32 | ' |
| 33 | |
| 34 | test_expect_success 'check no merge base' ' |
| 35 | ( |
| 36 | cd no_merge_base && |
| 37 | |
| 38 | git checkout L^0 && |
| 39 | |
| 40 | test_must_fail git -c merge.conflictstyle=diff3 merge --allow-unrelated-histories -s recursive R^0 && |
| 41 | |
| 42 | grep "|||||| empty tree" content |
| 43 | ) |
| 44 | ' |
| 45 | |
| 46 | # Setup: |
| 47 | # L1 |
| 48 | # / \ |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 49 | # main ? |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 50 | # \ / |
| 51 | # R1 |
| 52 | # |
| 53 | # Where: |
| 54 | # L1 and R1 have modified the same file ('content') in conflicting ways |
| 55 | # |
| 56 | |
| 57 | test_expect_success 'setup unique merge base' ' |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 58 | git init unique_merge_base && |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 59 | ( |
| 60 | cd unique_merge_base && |
| 61 | |
| 62 | test_commit base content "1 |
| 63 | 2 |
| 64 | 3 |
| 65 | 4 |
| 66 | 5 |
| 67 | " && |
| 68 | |
| 69 | git branch L && |
| 70 | git branch R && |
| 71 | |
| 72 | git checkout L && |
| 73 | test_commit L content "1 |
| 74 | 2 |
| 75 | 3 |
| 76 | 4 |
| 77 | 5 |
| 78 | 7" && |
| 79 | |
| 80 | git checkout R && |
| 81 | git rm content && |
| 82 | test_commit R renamed "1 |
| 83 | 2 |
| 84 | 3 |
| 85 | 4 |
| 86 | 5 |
| 87 | six" |
| 88 | ) |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'check unique merge base' ' |
| 92 | ( |
| 93 | cd unique_merge_base && |
| 94 | |
| 95 | git checkout L^0 && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 96 | MAIN=$(git rev-parse --short main) && |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 97 | |
| 98 | test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 && |
| 99 | |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 100 | grep "|||||| $MAIN:content" renamed |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 101 | ) |
| 102 | ' |
| 103 | |
| 104 | # Setup: |
| 105 | # L1---L2--L3 |
| 106 | # / \ / \ |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 107 | # main X1 ? |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 108 | # \ / \ / |
| 109 | # R1---R2--R3 |
| 110 | # |
| 111 | # Where: |
| 112 | # commits L1 and R1 have modified the same file in non-conflicting ways |
| 113 | # X1 is an auto-generated merge-base used when merging L1 and R1 |
| 114 | # commits L2 and R2 are merges of R1 and L1 into L1 and R1, respectively |
| 115 | # commits L3 and R3 both modify 'content' in conflicting ways |
| 116 | # |
| 117 | |
| 118 | test_expect_success 'setup multiple merge bases' ' |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 119 | git init multiple_merge_bases && |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 120 | ( |
| 121 | cd multiple_merge_bases && |
| 122 | |
| 123 | test_commit initial content "1 |
| 124 | 2 |
| 125 | 3 |
| 126 | 4 |
| 127 | 5" && |
| 128 | |
| 129 | git branch L && |
| 130 | git branch R && |
| 131 | |
| 132 | # Create L1 |
| 133 | git checkout L && |
| 134 | test_commit L1 content "0 |
| 135 | 1 |
| 136 | 2 |
| 137 | 3 |
| 138 | 4 |
| 139 | 5" && |
| 140 | |
| 141 | # Create R1 |
| 142 | git checkout R && |
| 143 | test_commit R1 content "1 |
| 144 | 2 |
| 145 | 3 |
| 146 | 4 |
| 147 | 5 |
| 148 | 6" && |
| 149 | |
| 150 | # Create L2 |
| 151 | git checkout L && |
| 152 | git merge R1 && |
| 153 | |
| 154 | # Create R2 |
| 155 | git checkout R && |
| 156 | git merge L1 && |
| 157 | |
| 158 | # Create L3 |
| 159 | git checkout L && |
| 160 | test_commit L3 content "0 |
| 161 | 1 |
| 162 | 2 |
| 163 | 3 |
| 164 | 4 |
| 165 | 5 |
| 166 | A" && |
| 167 | |
| 168 | # Create R3 |
| 169 | git checkout R && |
| 170 | git rm content && |
| 171 | test_commit R3 renamed "0 |
| 172 | 2 |
| 173 | 3 |
| 174 | 4 |
| 175 | 5 |
| 176 | six" |
| 177 | ) |
| 178 | ' |
| 179 | |
| 180 | test_expect_success 'check multiple merge bases' ' |
| 181 | ( |
| 182 | cd multiple_merge_bases && |
| 183 | |
| 184 | git checkout L^0 && |
| 185 | |
| 186 | test_must_fail git -c merge.conflictstyle=diff3 merge -s recursive R^0 && |
| 187 | |
| 188 | grep "|||||| merged common ancestors:content" renamed |
| 189 | ) |
| 190 | ' |
| 191 | |
Elijah Newren | 76340c8 | 2020-02-15 21:36:38 +0000 | [diff] [blame] | 192 | test_expect_success 'rebase --merge describes parent of commit being picked' ' |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 193 | git init rebase && |
Elijah Newren | 8e4ec33 | 2019-10-01 11:17:27 -0700 | [diff] [blame] | 194 | ( |
| 195 | cd rebase && |
| 196 | test_commit base file && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 197 | test_commit main file && |
Elijah Newren | 8e4ec33 | 2019-10-01 11:17:27 -0700 | [diff] [blame] | 198 | git checkout -b side HEAD^ && |
| 199 | test_commit side file && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 200 | test_must_fail git -c merge.conflictstyle=diff3 rebase --merge main && |
Elijah Newren | 76340c8 | 2020-02-15 21:36:38 +0000 | [diff] [blame] | 201 | grep "||||||| parent of" file |
| 202 | ) |
| 203 | ' |
| 204 | |
Elijah Newren | 10cdb9f | 2020-02-15 21:36:41 +0000 | [diff] [blame] | 205 | test_expect_success 'rebase --apply describes fake ancestor base' ' |
Elijah Newren | 76340c8 | 2020-02-15 21:36:38 +0000 | [diff] [blame] | 206 | ( |
| 207 | cd rebase && |
| 208 | git rebase --abort && |
Johannes Schindelin | 5902f5f | 2020-11-18 23:44:38 +0000 | [diff] [blame] | 209 | test_must_fail git -c merge.conflictstyle=diff3 rebase --apply main && |
Elijah Newren | 8e4ec33 | 2019-10-01 11:17:27 -0700 | [diff] [blame] | 210 | grep "||||||| constructed merge base" file |
| 211 | ) |
| 212 | ' |
| 213 | |
Phillip Wood | 4496526 | 2021-12-01 00:05:06 +0000 | [diff] [blame] | 214 | test_setup_zdiff3 () { |
Elijah Newren | 6693fb3 | 2022-08-26 03:49:19 +0000 | [diff] [blame] | 215 | git init zdiff3 && |
Phillip Wood | 4496526 | 2021-12-01 00:05:06 +0000 | [diff] [blame] | 216 | ( |
| 217 | cd zdiff3 && |
| 218 | |
| 219 | test_write_lines 1 2 3 4 5 6 7 8 9 >basic && |
| 220 | test_write_lines 1 2 3 AA 4 5 BB 6 7 8 >middle-common && |
| 221 | test_write_lines 1 2 3 4 5 6 7 8 9 >interesting && |
| 222 | test_write_lines 1 2 3 4 5 6 7 8 9 >evil && |
| 223 | |
| 224 | git add basic middle-common interesting evil && |
| 225 | git commit -m base && |
| 226 | |
| 227 | git branch left && |
| 228 | git branch right && |
| 229 | |
| 230 | git checkout left && |
| 231 | test_write_lines 1 2 3 4 A B C D E 7 8 9 >basic && |
| 232 | test_write_lines 1 2 3 CC 4 5 DD 6 7 8 >middle-common && |
| 233 | test_write_lines 1 2 3 4 A B C D E F G H I J 7 8 9 >interesting && |
| 234 | test_write_lines 1 2 3 4 X A B C 7 8 9 >evil && |
| 235 | git add -u && |
| 236 | git commit -m letters && |
| 237 | |
| 238 | git checkout right && |
| 239 | test_write_lines 1 2 3 4 A X C Y E 7 8 9 >basic && |
| 240 | test_write_lines 1 2 3 EE 4 5 FF 6 7 8 >middle-common && |
| 241 | test_write_lines 1 2 3 4 A B C 5 6 G H I J 7 8 9 >interesting && |
| 242 | test_write_lines 1 2 3 4 Y A B C B C 7 8 9 >evil && |
| 243 | git add -u && |
| 244 | git commit -m permuted |
| 245 | ) |
| 246 | } |
| 247 | |
| 248 | test_expect_success 'check zdiff3 markers' ' |
| 249 | test_setup_zdiff3 && |
| 250 | ( |
| 251 | cd zdiff3 && |
| 252 | |
| 253 | git checkout left^0 && |
| 254 | |
| 255 | base=$(git rev-parse --short HEAD^1) && |
| 256 | test_must_fail git -c merge.conflictstyle=zdiff3 merge -s recursive right^0 && |
| 257 | |
| 258 | test_write_lines 1 2 3 4 A \ |
| 259 | "<<<<<<< HEAD" B C D \ |
| 260 | "||||||| $base" 5 6 \ |
| 261 | ======= X C Y \ |
| 262 | ">>>>>>> right^0" \ |
| 263 | E 7 8 9 \ |
| 264 | >expect && |
| 265 | test_cmp expect basic && |
| 266 | |
| 267 | test_write_lines 1 2 3 \ |
| 268 | "<<<<<<< HEAD" CC \ |
| 269 | "||||||| $base" AA \ |
| 270 | ======= EE \ |
| 271 | ">>>>>>> right^0" \ |
| 272 | 4 5 \ |
| 273 | "<<<<<<< HEAD" DD \ |
| 274 | "||||||| $base" BB \ |
| 275 | ======= FF \ |
| 276 | ">>>>>>> right^0" \ |
| 277 | 6 7 8 \ |
| 278 | >expect && |
| 279 | test_cmp expect middle-common && |
| 280 | |
| 281 | test_write_lines 1 2 3 4 A B C \ |
| 282 | "<<<<<<< HEAD" D E F \ |
| 283 | "||||||| $base" 5 6 \ |
| 284 | ======= 5 6 \ |
| 285 | ">>>>>>> right^0" \ |
| 286 | G H I J 7 8 9 \ |
| 287 | >expect && |
| 288 | test_cmp expect interesting && |
| 289 | |
| 290 | # Not passing this one yet; the common "B C" lines is still |
| 291 | # being left in the conflict blocks on the left and right |
| 292 | # sides. |
| 293 | test_write_lines 1 2 3 4 \ |
| 294 | "<<<<<<< HEAD" X A \ |
| 295 | "||||||| $base" 5 6 \ |
| 296 | ======= Y A B C \ |
| 297 | ">>>>>>> right^0" \ |
| 298 | B C 7 8 9 \ |
| 299 | >expect && |
| 300 | test_cmp expect evil |
| 301 | ) |
| 302 | ' |
| 303 | |
Elijah Newren | 743474c | 2019-08-17 11:41:24 -0700 | [diff] [blame] | 304 | test_done |