Skip to content
Closed
Changes from all 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
27 changes: 25 additions & 2 deletions src/services/checkpoints/ShadowCheckpointService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down