Skip to content

Commit f8a308f

Browse files
fix(dev): worktree setup never deletes a real env file (#15845)
Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 01f894e commit f8a308f

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎scripts/setup-worktree.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,22 @@ const install = NodeChildProcess.spawnSync("vp i", {
2626
});
2727
if (install.status !== 0) process.exit(install.status ?? 1);
2828

29-
// In the main checkout itself, relinking would replace the real env files.
30-
if (NodeFS.realpathSync(projectRoot) !== NodeFS.realpathSync(worktree)) {
31-
for (const file of ENV_FILES) {
32-
const source = NodePath.join(projectRoot, file);
33-
if (!NodeFS.existsSync(source)) continue;
34-
const target = NodePath.join(worktree, file);
35-
NodeFS.rmSync(target, { force: true });
36-
NodeFS.symlinkSync(source, target);
29+
// Env files live as real files in the main checkout; worktrees only get
30+
// symlinks to them. Only a symlink is ever replaced, so a real env file is
31+
// never deleted, including when this runs in the main checkout itself.
32+
for (const file of ENV_FILES) {
33+
const source = NodePath.join(projectRoot, file);
34+
const sourceStat = NodeFS.lstatSync(source, { throwIfNoEntry: false });
35+
if (!sourceStat) continue;
36+
if (!sourceStat.isFile()) {
37+
console.warn(`Skipping ${file}: ${source} is not a regular file.`);
38+
continue;
3739
}
40+
const target = NodePath.join(worktree, file);
41+
const existing = NodeFS.lstatSync(target, { throwIfNoEntry: false });
42+
if (existing && !existing.isSymbolicLink()) continue;
43+
if (existing) NodeFS.rmSync(target);
44+
NodeFS.symlinkSync(source, target);
3845
}
3946

4047
const warm = NodeChildProcess.spawnSync(

0 commit comments

Comments
 (0)