|
1 | 1 | import { setupTest } from "../../../tests/setup-tests"; |
| 2 | +import { IS_E2E } from "../../../tests/options"; |
| 3 | +import { CommitParser } from "../../commit-parser/commit-parser"; |
2 | 4 | import { Git } from "../git"; |
3 | 5 |
|
4 | 6 | describe("git", () => { |
@@ -402,7 +404,7 @@ system so we'll see what happens.`, |
402 | 404 | expect(email).toBe(""); |
403 | 405 | }); |
404 | 406 |
|
405 | | - it("should read commits with and any tags", async () => { |
| 407 | + it("should read commits and tags", async () => { |
406 | 408 | const { config, create } = await setupTest("execute-file"); |
407 | 409 | const git = new Git(config); |
408 | 410 |
|
@@ -450,4 +452,95 @@ system so we'll see what happens.`, |
450 | 452 | expect(ref).toBe(" (tag: v1.0.0)"); |
451 | 453 | } |
452 | 454 | }); |
| 455 | + |
| 456 | + it("should handle out of order commits", { timeout: 10_000, skip: !IS_E2E }, async () => { |
| 457 | + const { config, create, execGit, sleep } = await setupTest("execute-file"); |
| 458 | + const git = new Git(config); |
| 459 | + |
| 460 | + create.directory("src"); |
| 461 | + create.file("File 1 content", "src", "file1.txt").add(); |
| 462 | + await git.commit("-m", "feat: initial commit"); |
| 463 | + await git.tag("v1.0.0"); |
| 464 | + |
| 465 | + await sleep(1000); |
| 466 | + |
| 467 | + // Create a long lived branch and commit to it, but don't merge it yet so that the commit is out of order in the git log |
| 468 | + await execGit.raw("checkout", "-b", "long-lived-feature-branch"); |
| 469 | + create.file("File 2 content", "src", "file2.txt").add(); |
| 470 | + await git.commit("-m", "feat: add file2"); |
| 471 | + await execGit.raw("checkout", "main"); |
| 472 | + |
| 473 | + await sleep(1000); |
| 474 | + |
| 475 | + // Create two short lived branches and merge them in quick succession to create out of order commits in the git log |
| 476 | + await execGit.raw("checkout", "-b", "quick-feature-branch"); |
| 477 | + create.file("File 3 content", "src", "file3.txt").add(); |
| 478 | + await git.commit("-m", "feat: add file3"); |
| 479 | + await execGit.raw("checkout", "main"); |
| 480 | + |
| 481 | + await sleep(1000); |
| 482 | + |
| 483 | + await execGit.raw("merge", "quick-feature-branch", "--no-ff"); |
| 484 | + await git.tag("v1.1.0"); |
| 485 | + |
| 486 | + await sleep(1000); |
| 487 | + |
| 488 | + await execGit.raw("checkout", "-b", "quick-bugfix-branch"); |
| 489 | + create.file("File 4 content", "src", "file4.txt").add(); |
| 490 | + await git.commit("-m", "fix: add file4"); |
| 491 | + await execGit.raw("checkout", "main"); |
| 492 | + |
| 493 | + await sleep(1000); |
| 494 | + |
| 495 | + await execGit.raw("merge", "quick-bugfix-branch", "--no-ff"); |
| 496 | + await git.tag("v1.1.1"); |
| 497 | + |
| 498 | + await sleep(1000); |
| 499 | + |
| 500 | + // Merge the long lived branch last so that its commit is out of order in the git log |
| 501 | + await execGit.raw("merge", "long-lived-feature-branch", "--no-ff"); |
| 502 | + await git.tag("v1.2.0"); |
| 503 | + |
| 504 | + const commits = await git.getCommits(); |
| 505 | + |
| 506 | + const commitParser = new CommitParser(); |
| 507 | + const parsedCommits = commits.map(commitParser.parseRawCommit); |
| 508 | + |
| 509 | + expect(parsedCommits.length).toBe(7); |
| 510 | + { |
| 511 | + const { subject, refNames } = parsedCommits[0]; |
| 512 | + expect(subject).toBe("Merge branch 'long-lived-feature-branch'"); |
| 513 | + expect(refNames).toBe("(HEAD -> main, tag: v1.2.0)"); |
| 514 | + } |
| 515 | + { |
| 516 | + const { subject, refNames } = parsedCommits[1]; |
| 517 | + expect(subject).toBe("Merge branch 'quick-bugfix-branch'"); |
| 518 | + expect(refNames).toBe("(tag: v1.1.1)"); |
| 519 | + } |
| 520 | + { |
| 521 | + const { subject, refNames } = parsedCommits[2]; |
| 522 | + expect(subject).toBe("fix: add file4"); |
| 523 | + expect(refNames).toBe("(quick-bugfix-branch)"); |
| 524 | + } |
| 525 | + { |
| 526 | + const { subject, refNames } = parsedCommits[3]; |
| 527 | + expect(subject).toBe("Merge branch 'quick-feature-branch'"); |
| 528 | + expect(refNames).toBe("(tag: v1.1.0)"); |
| 529 | + } |
| 530 | + { |
| 531 | + const { subject, refNames } = parsedCommits[4]; |
| 532 | + expect(subject).toBe("feat: add file3"); |
| 533 | + expect(refNames).toBe("(quick-feature-branch)"); |
| 534 | + } |
| 535 | + { |
| 536 | + const { subject, refNames } = parsedCommits[5]; |
| 537 | + expect(subject).toBe("feat: add file2"); |
| 538 | + expect(refNames).toBe("(long-lived-feature-branch)"); |
| 539 | + } |
| 540 | + { |
| 541 | + const { subject, refNames } = parsedCommits[6]; |
| 542 | + expect(subject).toBe("feat: initial commit"); |
| 543 | + expect(refNames).toBe("(tag: v1.0.0)"); |
| 544 | + } |
| 545 | + }); |
453 | 546 | }); |
0 commit comments