Skip to content

Commit c146ea7

Browse files
committed
fix(windows): normalize worktree comparison for checkpoints on Windows (short/long path and case-insensitive) to stabilize tests
1 parent 896cf9d commit c146ea7

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/services/checkpoints/ShadowCheckpointService.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,26 @@ export abstract class ShadowCheckpointService extends EventEmitter {
9090
this.log(`[${this.constructor.name}#initShadowGit] shadow git repo already exists at ${this.dotGitDir}`)
9191
const worktree = await this.getShadowGitConfigWorktree(git)
9292

93-
if (worktree !== this.workspaceDir) {
93+
// Normalize and compare paths in a cross-platform safe way (handles:
94+
// - Windows path separators
95+
// - Case-insensitivity
96+
// - Short (8.3) vs long paths via realpath fallback)
97+
const normalizeFsPath = (p: string) => {
98+
const normalized = path.normalize(p)
99+
return process.platform === "win32" ? normalized.toLowerCase() : normalized
100+
}
101+
const pathsEqual = async (a?: string, b?: string) => {
102+
if (!a || !b) return false
103+
try {
104+
const [ra, rb] = await Promise.all([fs.realpath(a), fs.realpath(b)])
105+
return normalizeFsPath(ra) === normalizeFsPath(rb)
106+
} catch {
107+
return normalizeFsPath(a) === normalizeFsPath(b)
108+
}
109+
}
110+
111+
const sameWorkspace = await pathsEqual(worktree, this.workspaceDir)
112+
if (!sameWorkspace) {
94113
throw new Error(
95114
`Checkpoints can only be used in the original workspace: ${worktree} !== ${this.workspaceDir}`,
96115
)

0 commit comments

Comments
 (0)