Skip to content

Commit c20f53c

Browse files
SunkenInTimeclaude
andcommitted
fix(server): removing a worktree keeps files hidden by showUntrackedFiles=no
Git refuses to remove a worktree that has untracked files unless forced, but that check honors status.showUntrackedFiles. With it set to no, git status reports new files as clean and `git worktree remove` deletes them, which automatic cleanup does without --force. removeWorktree now runs Git with status.showUntrackedFiles=normal so its own check sees them. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent fe417df commit c20f53c

2 files changed

Lines changed: 33 additions & 4 deletions

File tree

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
10781078
_tag: "GitCommandError",
10791079
operation: "GitVcsDriver.removeWorktree",
10801080
command: "git",
1081-
argumentCount: 3,
1081+
argumentCount: 5,
10821082
cwd,
10831083
});
10841084
assert.notProperty(error, "cause");
@@ -2883,6 +2883,34 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
28832883
}),
28842884
);
28852885

2886+
it.effect("keeps a worktree whose untracked files status is configured to hide", () =>
2887+
Effect.gen(function* () {
2888+
const cwd = yield* makeTmpDir();
2889+
const { initialBranch } = yield* initRepoWithCommit(cwd);
2890+
const pathService = yield* Path.Path;
2891+
const worktreePath = pathService.join(yield* makeTmpDir("git-worktrees-"), "hidden");
2892+
const driver = yield* GitVcsDriver.GitVcsDriver;
2893+
yield* driver.createWorktree({
2894+
cwd,
2895+
path: worktreePath,
2896+
refName: initialBranch,
2897+
newRefName: "feature/hidden",
2898+
});
2899+
yield* git(cwd, ["config", "status.showUntrackedFiles", "no"]);
2900+
yield* writeTextFile(worktreePath, "notes.txt", "draft\n");
2901+
assert.equal(yield* git(worktreePath, ["status", "--porcelain"]), "");
2902+
2903+
const result = yield* Effect.result(driver.removeWorktree({ cwd, path: worktreePath }));
2904+
2905+
assert.isTrue(Result.isFailure(result));
2906+
const fileSystem = yield* FileSystem.FileSystem;
2907+
assert.equal(
2908+
yield* fileSystem.readFileString(pathService.join(worktreePath, "notes.txt")),
2909+
"draft\n",
2910+
);
2911+
}),
2912+
);
2913+
28862914
it.effect("allows worktree removal to run longer than the default command timeout", () =>
28872915
Effect.gen(function* () {
28882916
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -2891,8 +2919,7 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
28912919
Effect.gen(function* () {
28922920
if (
28932921
ChildProcess.isStandardCommand(command) &&
2894-
command.args[0] === "worktree" &&
2895-
command.args[1] === "remove"
2922+
command.args.join(" ").includes("worktree remove")
28962923
) {
28972924
yield* Deferred.succeed(removalStarted, undefined);
28982925
yield* Effect.sleep("31 seconds");

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3649,7 +3649,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
36493649
const removeWorktree: GitVcsDriver.GitVcsDriver["Service"]["removeWorktree"] = Effect.fn(
36503650
"removeWorktree",
36513651
)(function* (input) {
3652-
const args = ["worktree", "remove"];
3652+
// Git refuses to remove a worktree with untracked files unless forced, but
3653+
// its check honors `status.showUntrackedFiles=no` and would delete them.
3654+
const args = ["-c", "status.showUntrackedFiles=normal", "worktree", "remove"];
36533655
if (input.force) {
36543656
args.push("--force");
36553657
}

0 commit comments

Comments
 (0)