-
-
Notifications
You must be signed in to change notification settings - Fork 541
Fix change reviews in repositories without HEAD #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
286a16c
c6330c4
f156069
b695812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -238,27 +238,59 @@ test("a concurrent review rejects a different root after initialization", async | |
| } | ||
| }); | ||
|
|
||
| test("an unborn repository becomes reviewable after its first commit", async (t) => { | ||
| test("an unborn repository is reviewable without creating a HEAD commit", async (t) => { | ||
| const root = await unbornRepository(t); | ||
| await writeFile(join(root, "existing.txt"), "present at open\n"); | ||
| const manager = createReviewCheckpointManager(); | ||
|
|
||
| await manager.initializeWorkspace({ workspaceId: "ws_unborn", root }); | ||
| await assert.rejects( | ||
| () => manager.reviewChanges({ workspaceId: "ws_unborn", root }), | ||
| /repository has no HEAD commit/, | ||
| ); | ||
| const availability = await manager.initializeWorkspace({ workspaceId: "ws_unborn", root }); | ||
| assert.deepEqual(availability, { available: true }); | ||
| await assert.rejects(() => git(root, ["rev-parse", "--verify", "HEAD^{commit}"])); | ||
|
|
||
| await writeFile(join(root, "README.md"), "first commit\n"); | ||
| await git(root, ["add", "README.md"]); | ||
| await git(root, ["commit", "-m", "Initial commit"]); | ||
| await writeFile(join(root, "created-after-open.txt"), "new file\n"); | ||
|
|
||
| const afterFirstCommit = await manager.reviewChanges({ | ||
| const review = await manager.reviewChanges({ | ||
| workspaceId: "ws_unborn", | ||
| root, | ||
| markReviewed: false, | ||
| }); | ||
| assert.equal(afterFirstCommit.summary.files, 0); | ||
| assert.equal(afterFirstCommit.patch, ""); | ||
| assert.deepEqual(review.files.map((file) => file.path), ["created-after-open.txt"]); | ||
| assert.equal(review.files[0]?.type, "new"); | ||
| assert.match(review.patch, /new file/); | ||
|
Comment on lines
251
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The regression test performs only one unmarked review while the repository is unborn. Add coverage that creates the first user commit and then reviews or advances the checkpoint again, so regressions in the new parentless checkpoint lifecycle are detected. Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| }); | ||
|
|
||
| test("a broken HEAD is not treated as an unborn repository", async (t) => { | ||
| const root = await committedRepository(t); | ||
| const head = await gitOutput(root, ["rev-parse", "HEAD"]); | ||
| await rm(join(root, ".git", "objects", head.slice(0, 2), head.slice(2))); | ||
| const manager = createReviewCheckpointManager(); | ||
|
|
||
| const availability = await manager.initializeWorkspace({ workspaceId: "ws_broken_head", root }); | ||
|
|
||
| assert.equal(availability.available, false); | ||
| }); | ||
|
|
||
| test("an unborn review baseline survives the first user commit", async (t) => { | ||
| const root = await unbornRepository(t); | ||
| await writeFile(join(root, "existing.txt"), "present at open\n"); | ||
| const manager = createReviewCheckpointManager(); | ||
|
|
||
| await manager.initializeWorkspace({ workspaceId: "ws_first_commit", root }); | ||
| await writeFile(join(root, "before-first-commit.txt"), "reviewed before commit\n"); | ||
| await manager.reviewChanges({ workspaceId: "ws_first_commit", root }); | ||
|
|
||
| await git(root, ["add", "-A"]); | ||
| await git(root, ["commit", "-m", "Initial commit"]); | ||
| await writeFile(join(root, "after-first-commit.txt"), "created after commit\n"); | ||
|
|
||
| const review = await manager.reviewChanges({ | ||
| workspaceId: "ws_first_commit", | ||
| root, | ||
| markReviewed: false, | ||
| }); | ||
| assert.deepEqual(review.files.map((file) => file.path), ["after-first-commit.txt"]); | ||
| assert.match(review.patch, /created after commit/); | ||
| assert.doesNotMatch(review.patch, /reviewed before commit/); | ||
| }); | ||
|
|
||
| async function committedRepository(t: TestContext): Promise<string> { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.