Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/core/checkpoints/__tests__/checkpoint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe("Checkpoint functionality", () => {
]
})

it("should show diff for full mode", async () => {
it("should show diff for to-current mode", async () => {
const mockChanges = [
{
paths: { absolute: "/test/file.ts", relative: "file.ts" },
Expand All @@ -295,7 +295,7 @@ describe("Checkpoint functionality", () => {
await checkpointDiff(mockTask, {
ts: 4,
commitHash: "commit2",
mode: "full",
mode: "to-current",
})

expect(mockCheckpointService.getDiff).toHaveBeenCalledWith({
Expand All @@ -304,7 +304,7 @@ describe("Checkpoint functionality", () => {
})
expect(vscode.commands.executeCommand).toHaveBeenCalledWith(
"vscode.changes",
"Changes since task started",
"errors.checkpoint_diff_to_current",
expect.any(Array),
)
})
Expand All @@ -329,7 +329,7 @@ describe("Checkpoint functionality", () => {
})
expect(vscode.commands.executeCommand).toHaveBeenCalledWith(
"vscode.changes",
"Changes compare with next checkpoint",
"errors.checkpoint_diff_with_next",
expect.any(Array),
)
})
Expand Down Expand Up @@ -361,10 +361,10 @@ describe("Checkpoint functionality", () => {
await checkpointDiff(mockTask, {
ts: 4,
commitHash: "commit2",
mode: "full",
mode: "to-current",
})

expect(vscode.window.showInformationMessage).toHaveBeenCalledWith("No changes found.")
expect(vscode.window.showInformationMessage).toHaveBeenCalledWith("errors.checkpoint_no_changes")
expect(vscode.commands.executeCommand).not.toHaveBeenCalled()
})

Expand All @@ -374,7 +374,7 @@ describe("Checkpoint functionality", () => {
await checkpointDiff(mockTask, {
ts: 4,
commitHash: "commit2",
mode: "full",
mode: "to-current",
})

expect(mockTask.enableCheckpoints).toBe(false)
Expand Down
63 changes: 48 additions & 15 deletions src/core/checkpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,16 @@ export async function checkpointRestore(
}

export type CheckpointDiffOptions = {
ts: number
ts?: number
previousCommitHash?: string
commitHash: string
mode: "full" | "checkpoint"
/**
* from-init: Compare from the first checkpoint to the selected checkpoint.
* checkpoint: Compare the selected checkpoint to the next checkpoint.
* to-current: Compare the selected checkpoint to the current workspace.
* full: Compare from the first checkpoint to the current workspace.
*/
mode: "from-init" | "checkpoint" | "to-current" | "full"
}

export async function checkpointDiff(task: Task, { ts, previousCommitHash, commitHash, mode }: CheckpointDiffOptions) {
Expand All @@ -285,30 +291,57 @@ export async function checkpointDiff(task: Task, { ts, previousCommitHash, commi

TelemetryService.instance.captureCheckpointDiffed(task.taskId)

let prevHash = commitHash
let nextHash: string | undefined = undefined
let fromHash: string | undefined
let toHash: string | undefined
let title: string

if (mode !== "full") {
const checkpoints = task.clineMessages.filter(({ say }) => say === "checkpoint_saved").map(({ text }) => text!)
const idx = checkpoints.indexOf(commitHash)
if (idx !== -1 && idx < checkpoints.length - 1) {
nextHash = checkpoints[idx + 1]
} else {
nextHash = undefined
}
const checkpoints = task.clineMessages.filter(({ say }) => say === "checkpoint_saved").map(({ text }) => text!)

if (["from-init", "full"].includes(mode) && checkpoints.length < 1) {
vscode.window.showInformationMessage(t("common:errors.checkpoint_no_first"))
return
}

const idx = checkpoints.indexOf(commitHash)
switch (mode) {
case "checkpoint":
fromHash = commitHash
toHash = idx !== -1 && idx < checkpoints.length - 1 ? checkpoints[idx + 1] : undefined
title = t("common:errors.checkpoint_diff_with_next")
break
case "from-init":
fromHash = checkpoints[0]
toHash = commitHash
title = t("common:errors.checkpoint_diff_since_first")
break
case "to-current":
fromHash = commitHash
toHash = undefined
title = t("common:errors.checkpoint_diff_to_current")
break
case "full":
fromHash = checkpoints[0]
toHash = undefined
title = t("common:errors.checkpoint_diff_since_first")
break
}

if (!fromHash) {
vscode.window.showInformationMessage(t("common:errors.checkpoint_no_previous"))
return
}

try {
const changes = await service.getDiff({ from: prevHash, to: nextHash })
const changes = await service.getDiff({ from: fromHash, to: toHash })

if (!changes?.length) {
vscode.window.showInformationMessage("No changes found.")
vscode.window.showInformationMessage(t("common:errors.checkpoint_no_changes"))
return
}

await vscode.commands.executeCommand(
"vscode.changes",
mode === "full" ? "Changes since task started" : "Changes compare with next checkpoint",
title,
changes.map((change) => [
vscode.Uri.file(change.paths.absolute),
vscode.Uri.parse(`${DIFF_VIEW_URI_SCHEME}:${change.paths.relative}`).with({
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/locales/ca/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/de/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
"checkpoint_timeout": "Timed out when attempting to restore checkpoint.",
"checkpoint_failed": "Failed to restore checkpoint.",
"git_not_installed": "Git is required for the checkpoints feature. Please install Git to enable checkpoints.",
"checkpoint_no_first": "No first checkpoint to compare.",
"checkpoint_no_previous": "No previous checkpoint to compare.",
"checkpoint_no_changes": "No changes found.",
"checkpoint_diff_with_next": "Changes compared with next checkpoint",
"checkpoint_diff_since_first": "Changes since first checkpoint",
"checkpoint_diff_to_current": "Changes to current workspace",
"nested_git_repos_warning": "Checkpoints are disabled because a nested git repository was detected at: {{path}}. To use checkpoints, please remove or relocate this nested git repository.",
"no_workspace": "Please open a project folder first",
"update_support_prompt": "Failed to update support prompt",
Expand Down
6 changes: 6 additions & 0 deletions src/i18n/locales/es/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/fr/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/i18n/locales/hi/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/id/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/it/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/ja/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/ko/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/i18n/locales/nl/common.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading