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/t3206-range-diff.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 / t3206-range-diff.sh` 1027 lines ยท 31225 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='range-diff tests' 4 5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 7 8 . ./test-lib.sh 9 10 # Note that because of the range-diff's heuristics, test_commit does more 11 # harm than good. We need some real history. 12 13 test_expect_success 'setup' ' 14 git fast-import <"$TEST_DIRECTORY"/t3206/history.export && 15 test_oid_cache <<-\EOF 16 # topic 17 t1 sha1:`4de457d` 18 t2 sha1:`fccce22` 19 t3 sha1:`147e64e` 20 t4 sha1:`a63e992` 21 t1 sha256:`b89f8b9` 22 t2 sha256:`5f12aad` 23 t3 sha256:`ea8b273` 24 t4 sha256:`14b7336` 25 26 # unmodified 27 u1 sha1:`35b9b25` 28 u2 sha1:`de345ab` 29 u3 sha1:`9af6654` 30 u4 sha1:`2901f77` 31 u1 sha256:`e3731be` 32 u2 sha256:`14fadf8` 33 u3 sha256:`736c4bc` 34 u4 sha256:`673e77d` 35 36 # topic (abbrev=10) 37 t1_abbrev sha1:`4de457d2c0` 38 t2_abbrev sha1:`fccce22f8c` 39 t3_abbrev sha1:`147e64ef53` 40 t4_abbrev sha1:`a63e992599` 41 t1_abbrev sha256:`b89f8b9092` 42 t2_abbrev sha256:`5f12aadf34` 43 t3_abbrev sha256:`ea8b273a6c` 44 t4_abbrev sha256:`14b73361fc` 45 46 # unmodified (abbrev=10) 47 u1_abbrev sha1:`35b9b25f76` 48 u2_abbrev sha1:`de345ab3de` 49 u3_abbrev sha1:`9af6654000` 50 u4_abbrev sha1:`2901f773f3` 51 u1_abbrev sha256:`e3731be242` 52 u2_abbrev sha256:`14fadf8cee` 53 u3_abbrev sha256:`736c4bcb44` 54 u4_abbrev sha256:`673e77d589` 55 56 # reordered 57 r1 sha1:`aca177a` 58 r2 sha1:`14ad629` 59 r3 sha1:`ee58208` 60 r4 sha1:`307b27a` 61 r1 sha256:`f59d3aa` 62 r2 sha256:`fb261a8` 63 r3 sha256:`cb2649b` 64 r4 sha256:`958577e` 65 66 # removed (deleted) 67 d1 sha1:`7657159` 68 d2 sha1:`43d84d3` 69 d3 sha1:`a740396` 70 d1 sha256:`e312513` 71 d2 sha256:`eb19258` 72 d3 sha256:`1ccb3c1` 73 74 # added 75 a1 sha1:`2716022` 76 a2 sha1:`b62accd` 77 a3 sha1:`df46cfa` 78 a4 sha1:`3e64548` 79 a5 sha1:`12b4063` 80 a1 sha256:`d724f4d` 81 a2 sha256:`1de7762` 82 a3 sha256:`e159431` 83 a4 sha256:`b3e483c` 84 a5 sha256:`90866a7` 85 86 # rebased 87 b1 sha1:`cc9c443` 88 b2 sha1:`c5d9641` 89 b3 sha1:`28cc2b6` 90 b4 sha1:`5628ab7` 91 b5 sha1:`a31b12e` 92 b1 sha256:`a1a8717` 93 b2 sha256:`20a5862` 94 b3 sha256:`587172a` 95 b4 sha256:`2721c5d` 96 b5 sha256:`7b57864` 97 98 # changed 99 c1 sha1:`a4b3333` 100 c2 sha1:`f51d370` 101 c3 sha1:`0559556` 102 c4 sha1:`d966c5c` 103 c1 sha256:`f8c2b9d` 104 c2 sha256:`3fb6318` 105 c3 sha256:`168ab68` 106 c4 sha256:`3526539` 107 108 # changed-message 109 m1 sha1:`f686024` 110 m2 sha1:`4ab067d` 111 m3 sha1:`b9cb956` 112 m4 sha1:`8add5f1` 113 m1 sha256:`31e6281` 114 m2 sha256:`a06bf1b` 115 m3 sha256:`82dc654` 116 m4 sha256:`48470c5` 117 118 # renamed 119 n1 sha1:`f258d75` 120 n2 sha1:`017b62d` 121 n3 sha1:`3ce7af6` 122 n4 sha1:`1e6226b` 123 n1 sha256:`ad52114` 124 n2 sha256:`3b54c8f` 125 n3 sha256:`3b0a644` 126 n4 sha256:`e461653` 127 128 # mode change 129 o1 sha1:`4d39cb3` 130 o2 sha1:`26c107f` 131 o3 sha1:`4c1e0f5` 132 o1 sha256:`d0dd598` 133 o2 sha256:`c4a279e` 134 o3 sha256:`78459d7` 135 136 # added and removed 137 s1 sha1:`096b1ba` 138 s2 sha1:`d92e698` 139 s3 sha1:`9a1db4d` 140 s4 sha1:`fea3b5c` 141 s1 sha256:`a7f9134` 142 s2 sha256:`b4c2580` 143 s3 sha256:`1d62aa2` 144 s4 sha256:`48160e8` 145 146 # Empty delimiter (included so lines match neatly) 147 __ sha1:------- 148 __ sha256:------- 149 EOF 150 ' 151 152 test_expect_success 'simple A..B A..C (unmodified)' ' 153 git range-diff --no-color main..topic main..unmodified \ 154 >actual && 155 cat >expect <<-EOF && 156 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ 157 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ 158 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ 159 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/ 160 EOF 161 test_cmp expect actual 162 ' 163 164 test_expect_success 'simple B...C (unmodified)' ' 165 git range-diff --no-color topic...unmodified >actual && 166 # same "expect" as above 167 test_cmp expect actual 168 ' 169 170 test_expect_success 'simple A B C (unmodified)' ' 171 git range-diff --no-color main topic unmodified >actual && 172 # same "expect" as above 173 test_cmp expect actual 174 ' 175 176 test_expect_success 'simple A..B A..C (unmodified) with --abbrev' ' 177 git range-diff --no-color --abbrev=10 main..topic main..unmodified \ 178 >actual && 179 cat >expect <<-EOF && 180 1: $(test_oid t1_abbrev) = 1: $(test_oid u1_abbrev) s/5/A/ 181 2: $(test_oid t2_abbrev) = 2: $(test_oid u2_abbrev) s/4/A/ 182 3: $(test_oid t3_abbrev) = 3: $(test_oid u3_abbrev) s/11/B/ 183 4: $(test_oid t4_abbrev) = 4: $(test_oid u4_abbrev) s/12/B/ 184 EOF 185 test_cmp expect actual 186 ' 187 188 test_expect_success 'A^! and A^- (unmodified)' ' 189 git range-diff --no-color topic^! unmodified^-1 >actual && 190 cat >expect <<-EOF && 191 1: $(test_oid t4) = 1: $(test_oid u4) s/12/B/ 192 EOF 193 test_cmp expect actual 194 ' 195 196 test_expect_success 'A^{/..} is not mistaken for a range' ' 197 test_must_fail git range-diff topic^.. topic^{/..} -- 2>error && 198 test_grep "not a commit range" error 199 ' 200 201 test_expect_success 'trivial reordering' ' 202 git range-diff --no-color main topic reordered >actual && 203 cat >expect <<-EOF && 204 1: $(test_oid t1) = 1: $(test_oid r1) s/5/A/ 205 3: $(test_oid t3) = 2: $(test_oid r2) s/11/B/ 206 4: $(test_oid t4) = 3: $(test_oid r3) s/12/B/ 207 2: $(test_oid t2) = 4: $(test_oid r4) s/4/A/ 208 EOF 209 test_cmp expect actual 210 ' 211 212 test_expect_success 'removed a commit' ' 213 git range-diff --no-color main topic removed >actual && 214 cat >expect <<-EOF && 215 1: $(test_oid t1) = 1: $(test_oid d1) s/5/A/ 216 2: $(test_oid t2) < -: $(test_oid __) s/4/A/ 217 3: $(test_oid t3) = 2: $(test_oid d2) s/11/B/ 218 4: $(test_oid t4) = 3: $(test_oid d3) s/12/B/ 219 EOF 220 test_cmp expect actual 221 ' 222 223 test_expect_success 'added a commit' ' 224 git range-diff --no-color main topic added >actual && 225 cat >expect <<-EOF && 226 1: $(test_oid t1) = 1: $(test_oid a1) s/5/A/ 227 2: $(test_oid t2) = 2: $(test_oid a2) s/4/A/ 228 -: $(test_oid __) > 3: $(test_oid a3) s/6/A/ 229 3: $(test_oid t3) = 4: $(test_oid a4) s/11/B/ 230 4: $(test_oid t4) = 5: $(test_oid a5) s/12/B/ 231 EOF 232 test_cmp expect actual 233 ' 234 235 test_expect_success 'new base, A B C' ' 236 git range-diff --no-color main topic rebased >actual && 237 cat >expect <<-EOF && 238 1: $(test_oid t1) = 1: $(test_oid b1) s/5/A/ 239 2: $(test_oid t2) = 2: $(test_oid b2) s/4/A/ 240 3: $(test_oid t3) = 3: $(test_oid b3) s/11/B/ 241 4: $(test_oid t4) = 4: $(test_oid b4) s/12/B/ 242 EOF 243 test_cmp expect actual 244 ' 245 246 test_expect_success 'new base, B...C' ' 247 # this syntax includes the commits from main! 248 git range-diff --no-color topic...rebased >actual && 249 cat >expect <<-EOF && 250 -: $(test_oid __) > 1: $(test_oid b5) unrelated 251 1: $(test_oid t1) = 2: $(test_oid b1) s/5/A/ 252 2: $(test_oid t2) = 3: $(test_oid b2) s/4/A/ 253 3: $(test_oid t3) = 4: $(test_oid b3) s/11/B/ 254 4: $(test_oid t4) = 5: $(test_oid b4) s/12/B/ 255 EOF 256 test_cmp expect actual 257 ' 258 259 test_expect_success 'changed commit' ' 260 git range-diff --no-color topic...changed >actual && 261 cat >expect <<-EOF && 262 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 263 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 264 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 265 @@ file: A 266 9 267 10 268 -11 269 -+B 270 ++BB 271 12 272 13 273 14 274 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ 275 @@ file 276 @@ file: A 277 9 278 10 279 - B 280 + BB 281 -12 282 +B 283 13 284 EOF 285 test_cmp expect actual 286 ' 287 288 test_expect_success 'changed commit with --no-patch diff option' ' 289 git range-diff --no-color --no-patch topic...changed >actual && 290 cat >expect <<-EOF && 291 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 292 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 293 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 294 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ 295 EOF 296 test_cmp expect actual 297 ' 298 299 test_expect_success 'changed commit with --stat diff option' ' 300 git range-diff --no-color --stat topic...changed >actual && 301 cat >expect <<-EOF && 302 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 303 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 304 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 305 a => b | 2 +- 306 1 file changed, 1 insertion(+), 1 deletion(-) 307 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ 308 a => b | 2 +- 309 1 file changed, 1 insertion(+), 1 deletion(-) 310 EOF 311 test_cmp expect actual 312 ' 313 314 test_expect_success 'changed commit with sm config' ' 315 git range-diff --no-color --submodule=log topic...changed >actual && 316 cat >expect <<-EOF && 317 1: $(test_oid t1) = 1: $(test_oid c1) s/5/A/ 318 2: $(test_oid t2) = 2: $(test_oid c2) s/4/A/ 319 3: $(test_oid t3) ! 3: $(test_oid c3) s/11/B/ 320 @@ file: A 321 9 322 10 323 -11 324 -+B 325 ++BB 326 12 327 13 328 14 329 4: $(test_oid t4) ! 4: $(test_oid c4) s/12/B/ 330 @@ file 331 @@ file: A 332 9 333 10 334 - B 335 + BB 336 -12 337 +B 338 13 339 EOF 340 test_cmp expect actual 341 ' 342 343 test_expect_success 'renamed file' ' 344 git range-diff --no-color --submodule=log topic...renamed-file >actual && 345 sed s/Z/\ /g >expect <<-EOF && 346 1: $(test_oid t1) = 1: $(test_oid n1) s/5/A/ 347 2: $(test_oid t2) ! 2: $(test_oid n2) s/4/A/ 348 @@ Metadata 349 ZAuthor: Thomas Rast 350 Z 351 Z ## Commit message ## 352 - s/4/A/ 353 + s/4/A/ + rename file 354 Z 355 - ## file ## 356 + ## file => renamed-file ## 357 Z@@ 358 Z 1 359 Z 2 360 3: $(test_oid t3) ! 3: $(test_oid n3) s/11/B/ 361 @@ Metadata 362 Z ## Commit message ## 363 Z s/11/B/ 364 Z 365 - ## file ## 366 -@@ file: A 367 + ## renamed-file ## 368 +@@ renamed-file: A 369 Z 8 370 Z 9 371 Z 10 372 4: $(test_oid t4) ! 4: $(test_oid n4) s/12/B/ 373 @@ Metadata 374 Z ## Commit message ## 375 Z s/12/B/ 376 Z 377 - ## file ## 378 -@@ file: A 379 + ## renamed-file ## 380 +@@ renamed-file: A 381 Z 9 382 Z 10 383 Z B 384 EOF 385 test_cmp expect actual 386 ' 387 388 test_expect_success 'file with mode only change' ' 389 git range-diff --no-color --submodule=log topic...mode-only-change >actual && 390 sed s/Z/\ /g >expect <<-EOF && 391 1: $(test_oid t2) ! 1: $(test_oid o1) s/4/A/ 392 @@ Metadata 393 ZAuthor: Thomas Rast 394 Z 395 Z ## Commit message ## 396 - s/4/A/ 397 + s/4/A/ + add other-file 398 Z 399 Z ## file ## 400 Z@@ 401 @@ file 402 Z A 403 Z 6 404 Z 7 405 + 406 + ## other-file (new) ## 407 2: $(test_oid t3) ! 2: $(test_oid o2) s/11/B/ 408 @@ Metadata 409 ZAuthor: Thomas Rast 410 Z 411 Z ## Commit message ## 412 - s/11/B/ 413 + s/11/B/ + mode change other-file 414 Z 415 Z ## file ## 416 Z@@ file: A 417 @@ file: A 418 Z 12 419 Z 13 420 Z 14 421 + 422 + ## other-file (mode change 100644 => 100755) ## 423 3: $(test_oid t4) = 3: $(test_oid o3) s/12/B/ 424 EOF 425 test_cmp expect actual 426 ' 427 428 test_expect_success 'file added and later removed' ' 429 git range-diff --no-color --submodule=log topic...added-removed >actual && 430 sed s/Z/\ /g >expect <<-EOF && 431 1: $(test_oid t1) = 1: $(test_oid s1) s/5/A/ 432 2: $(test_oid t2) ! 2: $(test_oid s2) s/4/A/ 433 @@ Metadata 434 ZAuthor: Thomas Rast 435 Z 436 Z ## Commit message ## 437 - s/4/A/ 438 + s/4/A/ + new-file 439 Z 440 Z ## file ## 441 Z@@ 442 @@ file 443 Z A 444 Z 6 445 Z 7 446 + 447 + ## new-file (new) ## 448 3: $(test_oid t3) ! 3: $(test_oid s3) s/11/B/ 449 @@ Metadata 450 ZAuthor: Thomas Rast 451 Z 452 Z ## Commit message ## 453 - s/11/B/ 454 + s/11/B/ + remove file 455 Z 456 Z ## file ## 457 Z@@ file: A 458 @@ file: A 459 Z 12 460 Z 13 461 Z 14 462 + 463 + ## new-file (deleted) ## 464 4: $(test_oid t4) = 4: $(test_oid s4) s/12/B/ 465 EOF 466 test_cmp expect actual 467 ' 468 469 test_expect_success 'no commits on one side' ' 470 git commit --amend -m "new message" && 471 git range-diff main HEAD@{1} HEAD 472 ' 473 474 test_expect_success 'changed message' ' 475 git range-diff --no-color topic...changed-message >actual && 476 sed s/Z/\ /g >expect <<-EOF && 477 1: $(test_oid t1) = 1: $(test_oid m1) s/5/A/ 478 2: $(test_oid t2) ! 2: $(test_oid m2) s/4/A/ 479 @@ Metadata 480 Z ## Commit message ## 481 Z s/4/A/ 482 Z 483 + Also a silly comment here! 484 + 485 Z ## file ## 486 Z@@ 487 Z 1 488 3: $(test_oid t3) = 3: $(test_oid m3) s/11/B/ 489 4: $(test_oid t4) = 4: $(test_oid m4) s/12/B/ 490 EOF 491 test_cmp expect actual 492 ' 493 494 test_expect_success 'dual-coloring' ' 495 sed -e "s|^:||" >expect <<-EOF && 496 :1: $(test_oid c1) = 1: $(test_oid m1) s/5/A/ 497 :2: $(test_oid c2) ! 2: $(test_oid m2) s/4/A/ 498 : @@ Metadata 499 : ## Commit message ## 500 : s/4/A/ 501 : 502 : + Also a silly comment here! 503 : + 504 : ## file ## 505 : @@ 506 : 1 507 :3: $(test_oid c3) ! 3: $(test_oid m3) s/11/B/ 508 : @@ file: A 509 : 9 510 : 10 511 : -11 512 : -+BB 513 : ++B 514 : 12 515 : 13 516 : 14 517 :4: $(test_oid c4) ! 4: $(test_oid m4) s/12/B/ 518 : @@ file 519 : @@ file: A 520 : 9 521 : 10 522 : - BB 523 : + B 524 : -12 525 : +B 526 : 13 527 EOF 528 git range-diff changed...changed-message --color --dual-color >actual.raw && 529 test_decode_color >actual actual && 539 test_line_count = 5 actual && 540 test_grep "^Range-diff:$" 0000-* && 541 test_grep "= 1: .* s/5/A" 0000-* && 542 test_grep "= 2: .* s/4/A" 0000-* && 543 test_grep "= 3: .* s/11/B" 0000-* && 544 test_grep "= 4: .* s/12/B" 0000-* 545 ' 546 done 547 548 test_expect_success "--range-diff implies --cover-letter for multi-patch series" ' 549 test_when_finished "rm -f v2-000?-*" && 550 git format-patch -v2 --range-diff=topic main..unmodified && 551 test_grep "^Range-diff against v1:$" v2-0000-cover-letter.patch 552 ' 553 554 test_expect_success "explicit --no-cover-letter defeats implied --cover-letter" ' 555 test_when_finished "rm -f v2-000?-*" && 556 test_must_fail git format-patch --no-cover-letter \ 557 -v2 --range-diff=topic main..unmodified && 558 test_must_fail git -c format.coverLetter=no format-patch \ 559 -v2 --range-diff=topic main..unmodified 560 ' 561 562 test_expect_success 'format-patch --range-diff as commentary' ' 563 test_when_finished "rm -f 0001-*" && 564 git format-patch --range-diff=HEAD~1 HEAD~1 >actual && 565 test_line_count = 1 actual && 566 test_grep "^Range-diff:$" 0001-* && 567 test_grep "> 1: .* new message" 0001-* 568 ' 569 570 test_expect_success 'format-patch --range-diff reroll-count with a non-integer' ' 571 test_when_finished "rm -f v2.9-0001-*" && 572 git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual && 573 test_line_count = 1 actual && 574 test_grep "^Range-diff:$" v2.9-0001-* && 575 test_grep "> 1: .* new message" v2.9-0001-* 576 ' 577 578 test_expect_success 'format-patch --range-diff reroll-count with a integer' ' 579 test_when_finished "rm -f v2-0001-*" && 580 git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual && 581 test_line_count = 1 actual && 582 test_grep "^Range-diff ..* v1:$" v2-0001-* && 583 test_grep "> 1: .* new message" v2-0001-* 584 ' 585 586 test_expect_success 'format-patch --range-diff with v0' ' 587 test_when_finished "rm -f v0-0001-*" && 588 git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual && 589 test_line_count = 1 actual && 590 test_grep "^Range-diff:$" v0-0001-* && 591 test_grep "> 1: .* new message" v0-0001-* 592 ' 593 594 test_expect_success 'range-diff overrides diff.noprefix internally' ' 595 git -c diff.noprefix=true range-diff HEAD^... 596 ' 597 598 test_expect_success 'basic with modified format.pretty with suffix' ' 599 git -c format.pretty="format:commit %H%d%n" range-diff \ 600 main..topic main..unmodified 601 ' 602 603 test_expect_success 'basic with modified format.pretty without "commit "' ' 604 git -c format.pretty="format:%H%n" range-diff \ 605 main..topic main..unmodified 606 ' 607 608 test_expect_success 'range-diff compares notes by default' ' 609 test_when_finished "git notes remove topic unmodified || :" && 610 git notes add -m "topic note" topic && 611 git notes add -m "unmodified note" unmodified && 612 git range-diff --no-color main..topic main..unmodified \ 613 >actual && 614 sed s/Z/\ /g >expect <<-EOF && 615 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ 616 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ 617 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ 618 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/ 619 @@ Commit message 620 Z 621 Z 622 Z ## Notes ## 623 - topic note 624 + unmodified note 625 Z 626 Z ## file ## 627 Z@@ file: A 628 EOF 629 test_cmp expect actual 630 ' 631 632 test_expect_success 'range-diff with --no-notes' ' 633 test_when_finished "git notes remove topic unmodified || :" && 634 git notes add -m "topic note" topic && 635 git notes add -m "unmodified note" unmodified && 636 git range-diff --no-color --no-notes main..topic main..unmodified \ 637 >actual && 638 cat >expect <<-EOF && 639 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ 640 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ 641 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ 642 4: $(test_oid t4) = 4: $(test_oid u4) s/12/B/ 643 EOF 644 test_cmp expect actual 645 ' 646 647 test_expect_success 'range-diff with multiple --notes' ' 648 test_when_finished "git notes --ref=note1 remove topic unmodified || :" && 649 git notes --ref=note1 add -m "topic note1" topic && 650 git notes --ref=note1 add -m "unmodified note1" unmodified && 651 test_when_finished "git notes --ref=note2 remove topic unmodified || :" && 652 git notes --ref=note2 add -m "topic note2" topic && 653 git notes --ref=note2 add -m "unmodified note2" unmodified && 654 git range-diff --no-color --notes=note1 --notes=note2 main..topic main..unmodified \ 655 >actual && 656 sed s/Z/\ /g >expect <<-EOF && 657 1: $(test_oid t1) = 1: $(test_oid u1) s/5/A/ 658 2: $(test_oid t2) = 2: $(test_oid u2) s/4/A/ 659 3: $(test_oid t3) = 3: $(test_oid u3) s/11/B/ 660 4: $(test_oid t4) ! 4: $(test_oid u4) s/12/B/ 661 @@ Commit message 662 Z 663 Z 664 Z ## Notes (note1) ## 665 - topic note1 666 + unmodified note1 667 Z 668 Z 669 Z ## Notes (note2) ## 670 - topic note2 671 + unmodified note2 672 Z 673 Z ## file ## 674 Z@@ file: A 675 EOF 676 test_cmp expect actual 677 ' 678 679 # `range-diff` should act like `log` with regards to notes 680 test_expect_success 'range-diff with --notes=custom does not show default notes' ' 681 test_when_finished "git notes remove topic unmodified || :" && 682 git notes add -m "topic note" topic && 683 git notes add -m "unmodified note" unmodified && 684 test_when_finished "git notes --ref=custom remove topic unmodified || :" && 685 git notes --ref=custom add -m "topic note" topic && 686 git notes --ref=custom add -m "unmodified note" unmodified && 687 git range-diff --notes=custom main..topic main..unmodified \ 688 >actual && 689 test_grep ! "## Notes ##" actual && 690 test_grep "## Notes (custom) ##" actual 691 ' 692 693 test_expect_success 'format-patch --range-diff does not compare notes by default' ' 694 test_when_finished "git notes remove topic unmodified || :" && 695 git notes add -m "topic note" topic && 696 git notes add -m "unmodified note" unmodified && 697 test_when_finished "rm -f 000?-*" && 698 git format-patch --cover-letter --range-diff=$prev \ 699 main..unmodified >actual && 700 test_line_count = 5 actual && 701 test_grep "^Range-diff:$" 0000-* && 702 test_grep "= 1: .* s/5/A" 0000-* && 703 test_grep "= 2: .* s/4/A" 0000-* && 704 test_grep "= 3: .* s/11/B" 0000-* && 705 test_grep "= 4: .* s/12/B" 0000-* && 706 test_grep ! "Notes" 0000-* && 707 test_grep ! "note" 0000-* 708 ' 709 710 test_expect_success 'format-patch --notes=custom --range-diff --cover-letter only compares custom notes' ' 711 test_when_finished "git notes remove topic unmodified || :" && 712 git notes add -m "topic note" topic && 713 git notes add -m "unmodified note" unmodified && 714 test_when_finished "git notes --ref=custom remove topic unmodified || :" && 715 git notes --ref=custom add -m "topic note (custom)" topic && 716 git notes --ref=custom add -m "unmodified note (custom)" unmodified && 717 test_when_finished "rm -f 000?-*" && 718 git format-patch --notes=custom --cover-letter --range-diff=$prev \ 719 main..unmodified >actual && 720 test_grep "## Notes (custom) ##" 0000-* && 721 test_grep ! "## Notes ##" 0000-* 722 ' 723 724 # --range-diff on a single commit requires --no-cover-letter 725 test_expect_success 'format-patch --notes=custom --range-diff on single commit only compares custom notes' ' 726 test_when_finished "git notes remove HEAD unmodified || :" && 727 git notes add -m "topic note" HEAD && 728 test_when_finished "git notes --ref=custom remove HEAD unmodified || :" && 729 git notes add -m "unmodified note" unmodified && 730 git notes --ref=custom add -m "topic note (custom)" HEAD && 731 git notes --ref=custom add -m "unmodified note (custom)" unmodified && 732 git format-patch --notes=custom --range-diff=$prev \ 733 -1 --stdout >actual && 734 test_grep "## Notes (custom) ##" actual && 735 test_grep ! "## Notes ##" actual 736 ' 737 738 test_expect_success 'format-patch --range-diff with --no-notes' ' 739 test_when_finished "git notes remove topic unmodified || :" && 740 git notes add -m "topic note" topic && 741 git notes add -m "unmodified note" unmodified && 742 test_when_finished "rm -f 000?-*" && 743 git format-patch --no-notes --cover-letter --range-diff=$prev \ 744 main..unmodified >actual && 745 test_line_count = 5 actual && 746 test_grep "^Range-diff:$" 0000-* && 747 test_grep "= 1: .* s/5/A" 0000-* && 748 test_grep "= 2: .* s/4/A" 0000-* && 749 test_grep "= 3: .* s/11/B" 0000-* && 750 test_grep "= 4: .* s/12/B" 0000-* && 751 test_grep ! "Notes" 0000-* && 752 test_grep ! "note" 0000-* 753 ' 754 755 test_expect_success 'format-patch --range-diff with --notes' ' 756 test_when_finished "git notes remove topic unmodified || :" && 757 git notes add -m "topic note" topic && 758 git notes add -m "unmodified note" unmodified && 759 test_when_finished "rm -f 000?-*" && 760 git format-patch --notes --cover-letter --range-diff=$prev \ 761 main..unmodified >actual && 762 test_line_count = 5 actual && 763 test_grep "^Range-diff:$" 0000-* && 764 test_grep "= 1: .* s/5/A" 0000-* && 765 test_grep "= 2: .* s/4/A" 0000-* && 766 test_grep "= 3: .* s/11/B" 0000-* && 767 test_grep "! 4: .* s/12/B" 0000-* && 768 sed s/Z/\ /g >expect <<-EOF && 769 @@ Commit message 770 Z 771 Z 772 Z ## Notes ## 773 - topic note 774 + unmodified note 775 Z 776 Z ## file ## 777 Z@@ file: A 778 EOF 779 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && 780 test_cmp expect actual 781 ' 782 783 test_expect_success 'format-patch --range-diff with format.notes config' ' 784 test_when_finished "git notes remove topic unmodified || :" && 785 git notes add -m "topic note" topic && 786 git notes add -m "unmodified note" unmodified && 787 test_config format.notes true && 788 test_when_finished "rm -f 000?-*" && 789 git format-patch --cover-letter --range-diff=$prev \ 790 main..unmodified >actual && 791 test_line_count = 5 actual && 792 test_grep "^Range-diff:$" 0000-* && 793 test_grep "= 1: .* s/5/A" 0000-* && 794 test_grep "= 2: .* s/4/A" 0000-* && 795 test_grep "= 3: .* s/11/B" 0000-* && 796 test_grep "! 4: .* s/12/B" 0000-* && 797 sed s/Z/\ /g >expect <<-EOF && 798 @@ Commit message 799 Z 800 Z 801 Z ## Notes ## 802 - topic note 803 + unmodified note 804 Z 805 Z ## file ## 806 Z@@ file: A 807 EOF 808 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && 809 test_cmp expect actual 810 ' 811 812 test_expect_success 'format-patch --range-diff with multiple notes' ' 813 test_when_finished "git notes --ref=note1 remove topic unmodified || :" && 814 git notes --ref=note1 add -m "topic note1" topic && 815 git notes --ref=note1 add -m "unmodified note1" unmodified && 816 test_when_finished "git notes --ref=note2 remove topic unmodified || :" && 817 git notes --ref=note2 add -m "topic note2" topic && 818 git notes --ref=note2 add -m "unmodified note2" unmodified && 819 test_when_finished "rm -f 000?-*" && 820 git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \ 821 main..unmodified >actual && 822 test_line_count = 5 actual && 823 test_grep "^Range-diff:$" 0000-* && 824 test_grep "= 1: .* s/5/A" 0000-* && 825 test_grep "= 2: .* s/4/A" 0000-* && 826 test_grep "= 3: .* s/11/B" 0000-* && 827 test_grep "! 4: .* s/12/B" 0000-* && 828 sed s/Z/\ /g >expect <<-EOF && 829 @@ Commit message 830 Z 831 Z 832 Z ## Notes (note1) ## 833 - topic note1 834 + unmodified note1 835 Z 836 Z 837 Z ## Notes (note2) ## 838 - topic note2 839 + unmodified note2 840 Z 841 Z ## file ## 842 Z@@ file: A 843 EOF 844 sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual && 845 test_cmp expect actual 846 ' 847 848 # Unlike '--notes', '--range-diff-notes' requires a value 849 test_expect_success 'format-patch --range-diff-notes requires a value' ' 850 cat >expect <<-EOF && 851 error: option \`range-diff-notes${SQ} requires a value 852 EOF 853 test_must_fail git format-patch --range-diff=main..topic \ 854 --cover-letter --range-diff-notes 2>actual && 855 test_cmp expect actual 856 ' 857 858 # The '--range-diff-notes' has no effect but is allowed 859 test_expect_success 'format-patch --range-diff-notes=not-a-note (no --range-diff)' ' 860 test_when_finished "rm -f 000?-*" && 861 git format-patch --range-diff-notes=not-a-note --cover-letter \ 862 main..unmodified && 863 test_file_not_empty 0000-cover-letter* && 864 test_grep ! "^Range-diff:" 0000-cover-letter* && 865 test_grep ! "## Notes " 0000-cover-letter* 866 ' 867 868 test_expect_success 'format-patch --range-diff --notes=custom --no-range-diff-notes' ' 869 test_when_finished "git notes --ref=custom remove topic unmodified || :" && 870 git notes --ref=custom add -m "topic note1" topic && 871 git notes --ref=custom add -m "unmodified note1" unmodified && 872 test_when_finished "rm -f 000?-*" && 873 git format-patch --range-diff=main..topic --notes=custom \ 874 --no-range-diff-notes --cover-letter \ 875 main..unmodified && 876 test_grep "^Notes (custom):" 0004-* && 877 test_grep "^Range-diff:" 0000-cover-letter* && 878 test_grep ! "## Notes (custom) ##" 0000-cover-letter* 879 ' 880 881 test_expect_success 'format-patch --range-diff --no-notes --range-diff-notes=custom' ' 882 test_when_finished "git notes --ref=custom remove topic unmodified || :" && 883 git notes --ref=custom add -m "topic note1" topic && 884 git notes --ref=custom add -m "unmodified note1" unmodified && 885 test_when_finished "rm -f 000?-*" && 886 git format-patch --range-diff=main..topic --no-notes \ 887 --range-diff-notes=custom --cover-letter \ 888 main..unmodified && 889 test_grep ! "^Notes (custom):" 0004-* && 890 test_grep "^Range-diff:" 0000-cover-letter* && 891 test_grep "## Notes (custom) ##" 0000-cover-letter* 892 ' 893 894 test_expect_success 'format-patch --range-diff --notes=patch --range-diff-notes=rdiff' ' 895 test_when_finished "git notes --ref=patch remove topic unmodified || :" && 896 git notes --ref=patch add -m "only for patch 1" topic && 897 git notes --ref=patch add -m "only for patch 2" unmodified && 898 test_when_finished "git notes --ref=rdiff remove topic unmodified || :" && 899 git notes --ref=rdiff add -m "only for range diff 1" topic && 900 git notes --ref=rdiff add -m "only for range diff 2" unmodified && 901 test_when_finished "rm -f 000?-*" && 902 git format-patch --range-diff=main..topic --notes=patch \ 903 --range-diff-notes=rdiff --cover-letter \ 904 main..unmodified && 905 test_grep "^Notes (patch):" 0004-* && 906 test_grep ! "^Notes (rdiff):" 0004-* && 907 test_grep "^Range-diff:" 0000-cover-letter* && 908 test_grep "## Notes (rdiff) ##" 0000-cover-letter* && 909 test_grep ! "## Notes (patch) ##" 0000-cover-letter* 910 ' 911 912 test_expect_success 'format-patch --range-diff --no-range-diff-notes on single patch' ' 913 test_when_finished "git notes --ref=custom remove HEAD unmodified || :" && 914 git notes --ref=custom add -m "topic note (custom)" HEAD && 915 git notes --ref=custom add -m "unmodified note (custom)" unmodified && 916 git format-patch --notes=custom --range-diff=main..topic \ 917 --no-range-diff-notes -1 --stdout >actual && 918 test_grep "Notes (custom):" actual && 919 test_grep "^Range-diff:" actual && 920 test_grep ! "## Notes (custom) ##" actual 921 ' 922 923 test_expect_success 'format-patch --range-diff --range-diff-notes=custom on single patch' ' 924 test_when_finished "git notes --ref=custom remove HEAD unmodified || :" && 925 git notes --ref=custom add -m "topic note (custom)" HEAD && 926 git notes --ref=custom add -m "unmodified note (custom)" unmodified && 927 git format-patch --range-diff=main..topic \ 928 --range-diff-notes=custom -1 --stdout >actual && 929 test_grep ! "Notes (custom):" actual && 930 test_grep "^Range-diff:" actual && 931 test_grep "## Notes (custom) ##" actual 932 ' 933 934 test_expect_success '--left-only/--right-only' ' 935 git switch --orphan left-right && 936 test_commit first && 937 test_commit unmatched && 938 test_commit common && 939 git switch -C left-right first && 940 git cherry-pick common && 941 942 git range-diff -s --left-only ...common >actual && 943 head_oid=$(git rev-parse --short HEAD) && 944 common_oid=$(git rev-parse --short common) && 945 echo "1: $head_oid = 2: $common_oid common" >expect && 946 test_cmp expect actual 947 ' 948 949 test_expect_success 'ranges with pathspecs' ' 950 git range-diff topic...mode-only-change -- other-file >actual && 951 test_line_count = 2 actual && 952 topic_oid=$(git rev-parse --short topic) && 953 mode_change_oid=$(git rev-parse --short mode-only-change^) && 954 file_change_oid=$(git rev-parse --short mode-only-change) && 955 test_grep "$mode_change_oid" actual && 956 test_grep ! "$file_change_oid" actual && 957 test_grep ! "$topic_oid" actual 958 ' 959 960 test_expect_success 'submodule changes are shown irrespective of diff.submodule' ' 961 git init sub-repo && 962 test_commit -C sub-repo sub-first && 963 sub_oid1=$(git -C sub-repo rev-parse HEAD) && 964 test_commit -C sub-repo sub-second && 965 sub_oid2=$(git -C sub-repo rev-parse HEAD) && 966 test_commit -C sub-repo sub-third && 967 sub_oid3=$(git -C sub-repo rev-parse HEAD) && 968 969 git checkout -b main-sub topic && 970 git -c protocol.file.allow=always submodule add ./sub-repo sub && 971 git -C sub checkout --detach sub-first && 972 git commit -m "add sub" sub && 973 sup_oid1=$(git rev-parse --short HEAD) && 974 git checkout -b topic-sub && 975 git -C sub checkout sub-second && 976 git commit -m "change sub" sub && 977 sup_oid2=$(git rev-parse --short HEAD) && 978 git checkout -b modified-sub main-sub && 979 git -C sub checkout sub-third && 980 git commit -m "change sub" sub && 981 sup_oid3=$(git rev-parse --short HEAD) && 982 sup_oid0=$(test_oid __) && 983 984 test_config diff.submodule log && 985 git range-diff topic topic-sub modified-sub >actual && 986 cat >expect <<-EOF && 987 1: $sup_oid1 = 1: $sup_oid1 add sub 988 2: $sup_oid2 < -: $sup_oid0 change sub 989 -: $sup_oid0 > 2: $sup_oid3 change sub 990 EOF 991 test_cmp expect actual && 992 test_config diff.submodule diff && 993 git range-diff topic topic-sub modified-sub >actual && 994 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && 995 cat >expect <<-EOF && 996 1: $sup_oid1 = 1: $sup_oid1 add sub 997 2: $sup_oid2 ! 2: $sup_oid3 change sub 998 @@ Commit message 999 ## sub ## 1000 @@ 1001 -Subproject commit $sub_oid1 1002 -+Subproject commit $sub_oid2 1003 ++Subproject commit $sub_oid3 1004 EOF 1005 test_cmp expect actual && 1006 test_config diff.submodule diff && 1007 git range-diff --creation-factor=100 topic topic-sub modified-sub >actual && 1008 test_cmp expect actual 1009 ' 1010 1011 test_expect_success '--diff-merges' ' 1012 renamed_oid=$(git rev-parse --short renamed-file) && 1013 tree=$(git merge-tree unmodified renamed-file) && 1014 clean=$(git commit-tree -m merge -p unmodified -p renamed-file $tree) && 1015 clean_oid=$(git rev-parse --short $clean) && 1016 conflict=$(git commit-tree -m merge -p unmodified -p renamed-file^ $tree) && 1017 conflict_oid=$(git rev-parse --short $conflict) && 1018 1019 git range-diff --diff-merges=1 $clean...$conflict >actual && 1020 cat >expect <<-EOF && 1021 1: $renamed_oid < -: ------- s/12/B/ 1022 2: $clean_oid = 1: $conflict_oid merge 1023 EOF 1024 test_cmp expect actual 1025 ' 1026 1027 test_done