mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-09-05 08:10:14 +00:00
fix: remove git clean and reset --hard from checkpoint restore
- Removed dangerous git clean command that was deleting untracked files - Replaced git reset --hard with a safer approach that only restores tracked files - Preserves untracked files during checkpoint restoration to prevent data loss - Fixes #6209
This commit is contained in:
parent
342ee70fb4
commit
ae00f6e0c2
1 changed files with 25 additions and 2 deletions
|
|
@ -247,8 +247,31 @@ export abstract class ShadowCheckpointService extends EventEmitter {
|
|||
}
|
||||
|
||||
const start = Date.now()
|
||||
await this.git.clean("f", ["-d", "-f"])
|
||||
await this.git.reset(["--hard", commitHash])
|
||||
|
||||
// Get list of files in the target commit
|
||||
const filesInCommit = await this.git.raw(["ls-tree", "-r", "--name-only", commitHash])
|
||||
const files = filesInCommit
|
||||
.trim()
|
||||
.split("\n")
|
||||
.filter((f) => f.length > 0)
|
||||
|
||||
if (files.length > 0) {
|
||||
// If there are files in the commit, checkout only those files
|
||||
// This restores tracked files without affecting untracked files
|
||||
await this.git.checkout([commitHash, "--", ...files])
|
||||
}
|
||||
|
||||
// Remove files that exist in working directory but not in the target commit
|
||||
const currentFiles = await this.git.raw(["ls-files"])
|
||||
const currentFilesList = currentFiles
|
||||
.trim()
|
||||
.split("\n")
|
||||
.filter((f) => f.length > 0)
|
||||
const filesToRemove = currentFilesList.filter((f) => !files.includes(f))
|
||||
|
||||
if (filesToRemove.length > 0) {
|
||||
await this.git.rm(filesToRemove)
|
||||
}
|
||||
|
||||
// Remove all checkpoints after the specified commitHash.
|
||||
const checkpointIndex = this._checkpoints.indexOf(commitHash)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue