-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New checkpoints algorithm #939
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,12 @@ export type CheckpointServiceOptions = { | |||||
| log?: (message: string) => void | ||||||
| } | ||||||
|
|
||||||
| export type StagedFile = { | ||||||
| path: string | ||||||
| isStaged: boolean | ||||||
| isPartiallyStaged: boolean | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * The CheckpointService provides a mechanism for storing a snapshot of the | ||||||
| * current VSCode workspace each time a Roo Code tool is executed. It uses Git | ||||||
|
|
@@ -23,11 +29,11 @@ export type CheckpointServiceOptions = { | |||||
| * - A hidden branch for storing checkpoints. | ||||||
| * | ||||||
| * Saving a checkpoint: | ||||||
| * - Current changes are stashed (including untracked files). | ||||||
| * - A temporary branch is created to store the current state. | ||||||
| * - All changes (including untracked files) are staged and committed on the temp branch. | ||||||
| * - The hidden branch is reset to match main. | ||||||
| * - Stashed changes are applied and committed as a checkpoint on the hidden | ||||||
| * branch. | ||||||
| * - We return to the main branch with the original state restored. | ||||||
| * - The temporary branch commit is cherry-picked onto the hidden branch. | ||||||
| * - The workspace is restored to its original state and the temp branch is deleted. | ||||||
| * | ||||||
| * Restoring a checkpoint: | ||||||
| * - The workspace is restored to the state of the specified checkpoint using | ||||||
|
|
@@ -37,6 +43,7 @@ export type CheckpointServiceOptions = { | |||||
| * - Non-destructive version control (main branch remains untouched). | ||||||
| * - Preservation of the full history of checkpoints. | ||||||
| * - Safe restoration to any previous checkpoint. | ||||||
| * - Atomic checkpoint operations with proper error recovery. | ||||||
| * | ||||||
| * NOTES | ||||||
| * | ||||||
|
|
@@ -51,6 +58,8 @@ export type CheckpointServiceOptions = { | |||||
| export class CheckpointService { | ||||||
| private static readonly USER_NAME = "Roo Code" | ||||||
| private static readonly USER_EMAIL = "[email protected]" | ||||||
| private static readonly CHECKPOINT_BRANCH = "roo-code-checkpoints" | ||||||
| private static readonly STASH_BRANCH = "roo-code-stash" | ||||||
|
|
||||||
| private _currentCheckpoint?: string | ||||||
|
|
||||||
|
|
@@ -72,39 +81,6 @@ export class CheckpointService { | |||||
| private readonly log: (message: string) => void, | ||||||
| ) {} | ||||||
|
|
||||||
| private async pushStash() { | ||||||
| const status = await this.git.status() | ||||||
|
|
||||||
| if (status.files.length > 0) { | ||||||
| await this.git.stash(["-u"]) // Includes tracked and untracked files. | ||||||
| return true | ||||||
| } | ||||||
|
|
||||||
| return false | ||||||
| } | ||||||
|
|
||||||
| private async applyStash() { | ||||||
| const stashList = await this.git.stashList() | ||||||
|
|
||||||
| if (stashList.all.length > 0) { | ||||||
| await this.git.stash(["apply"]) // Applies the most recent stash only. | ||||||
| return true | ||||||
| } | ||||||
|
|
||||||
| return false | ||||||
| } | ||||||
|
|
||||||
| private async popStash() { | ||||||
| const stashList = await this.git.stashList() | ||||||
|
|
||||||
| if (stashList.all.length > 0) { | ||||||
| await this.git.stash(["pop", "--index"]) // Pops the most recent stash only. | ||||||
| return true | ||||||
| } | ||||||
|
|
||||||
| return false | ||||||
| } | ||||||
|
|
||||||
| private async ensureBranch(expectedBranch: string) { | ||||||
| const branch = await this.git.revparse(["--abbrev-ref", "HEAD"]) | ||||||
|
|
||||||
|
|
@@ -153,88 +129,188 @@ export class CheckpointService { | |||||
| return result | ||||||
| } | ||||||
|
|
||||||
| private async restoreMain({ | ||||||
| branch, | ||||||
| stashSha, | ||||||
| force = false, | ||||||
| }: { | ||||||
| branch: string | ||||||
| stashSha: string | ||||||
| force?: boolean | ||||||
| }) { | ||||||
| if (force) { | ||||||
| await this.git.checkout(["-f", this.mainBranch]) | ||||||
| } else { | ||||||
| await this.git.checkout(this.mainBranch) | ||||||
| } | ||||||
|
|
||||||
| if (stashSha) { | ||||||
| console.log(`[restoreMain] applying stash ${stashSha}`) | ||||||
|
||||||
| console.log(`[restoreMain] applying stash ${stashSha}`) | |
| this.log(`[restoreMain] applying stash ${stashSha}`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.