fix(server): removing a worktree no longer deletes what its junctions point to #17076
Closedsheehanmunim(GitHub profile, opens in a new tab)wants to merge 1 commit into
main fromrefs/pull/17076/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
- @@ -3791,3 +3823,17 @@37913823 args.push("--force");37923824 }37933825 args.push(input.path);3826+ // Git for Windows before 2.54 follows junctions while removing a worktree3827+ // and deletes what they point to, such as the main checkout's node_modules.3828+ // Later versions skip them but leave the worktree directory behind. Git3829+ // elsewhere only unlinks links. Only a linked worktree has a `.git` file,3830+ // so the main checkout is never touched.3831+ const worktreePath = path.resolve(input.cwd, input.path);3832+ if (3833+ hostPlatform === "win32" &&3834+ (yield* fileSystem.stat(path.join(worktreePath, ".git")).pipe(3835+ Effect.map((info) => info.type === "File"),3836+ Effect.orElseSucceed(() => false),3837+ ))3838+ ) {3839+ yield* unlinkDirectoryLinks(worktreePath).pipe(
coderabbitai[bot](GitHub profile, opens in a new tab) requested changes
@@ -3783,0 +3791,21 @@3791+ * tracked one doesn't make a clean worktree look modified.3792+ */3793+ const unlinkDirectoryLinks = Effect.fnUntraced(function* (3794+ directory: string,3795+ ): Effect.fn.Return<void, Cause.UnknownError | PlatformError.PlatformError> {3796+ // Typed entries tell links from directories without a stat per file, which3797+ // matters in a large node_modules.3798+ const entries = yield* Effect.tryPromise(() =>3799+ NodeFSP.readdir(directory, { withFileTypes: true }),3800+ );3801+ for (const entry of entries) {3802+ const entryPath = path.join(directory, entry.name);3803+ if (entry.isDirectory()) {3804+ if (entry.name !== ".git") {3805+ yield* unlinkDirectoryLinks(entryPath);3806+ }3807+ } else if (entry.isSymbolicLink()) {3808+ const target = yield* fileSystem.stat(entryPath).pipe(Effect.option);3809+ if (Option.isNone(target) || target.value.type === "Directory") {3810+ yield* fileSystem.remove(entryPath);3811+ }juliusmarminge added labelsmacroscope-review
juliusmarminge closed this
Sign in to join this conversation.
copilot-pull-request-reviewer[bot](GitHub profile, opens in a new tab) reviewed
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.