fix(server): worktree cleanup no longer deletes files hidden by showUntrackedFiles=no (#15834)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
This commit is contained in:
Dara AdedejiandClaude Opus 5.5 authored and GitHub committed 2026-10-07 10:21:38 -07:00
1 parent db46c42744
commit d9068d3809
2 files changed
+33 -4

No files matched your search

+30 -3
View File
@@ -1351,7 +1351,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
_tag: "GitCommandError",
operation: "GitVcsDriver.removeWorktree",
command: "git",
argumentCount: 3,
argumentCount: 5,
cwd,
});
assert.notProperty(error, "cause");
@@ -3217,6 +3217,34 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
}),
);
it.effect("keeps a worktree whose untracked files status is configured to hide", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const { initialBranch } = yield* initRepoWithCommit(cwd);
const pathService = yield* Path.Path;
const worktreePath = pathService.join(yield* makeTmpDir("git-worktrees-"), "hidden");
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* driver.createWorktree({
cwd,
path: worktreePath,
refName: initialBranch,
newRefName: "feature/hidden",
});
yield* git(cwd, ["config", "status.showUntrackedFiles", "no"]);
yield* writeTextFile(worktreePath, "notes.txt", "draft\n");
assert.equal(yield* git(worktreePath, ["status", "--porcelain"]), "");
const result = yield* Effect.result(driver.removeWorktree({ cwd, path: worktreePath }));
assert.isTrue(Result.isFailure(result));
const fileSystem = yield* FileSystem.FileSystem;
assert.equal(
yield* fileSystem.readFileString(pathService.join(worktreePath, "notes.txt")),
"draft\n",
);
}),
);
it.effect("allows worktree removal to run longer than the default command timeout", () =>
Effect.gen(function* () {
const delegate = yield* ChildProcessSpawner.ChildProcessSpawner;
@@ -3225,8 +3253,7 @@ it.layer(layerTest)("GitVcsDriver core integration", (it) => {
Effect.gen(function* () {
if (
ChildProcess.isStandardCommand(command) &&
command.args[0] === "worktree" &&
command.args[1] === "remove"
command.args.join(" ").includes("worktree remove")
) {
yield* Deferred.succeed(removalStarted, undefined);
yield* Effect.sleep("31 seconds");
+3 -1
View File
@@ -3743,7 +3743,9 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const removeWorktree: GitVcsDriver.GitVcsDriver["Service"]["removeWorktree"] = Effect.fn(
"removeWorktree",
)(function* (input) {
const args = ["worktree", "remove"];
// Git refuses to remove a worktree with untracked files unless forced, but
// its check honors `status.showUntrackedFiles=no` and would delete them.
const args = ["-c", "status.showUntrackedFiles=normal", "worktree", "remove"];
if (input.force) {
args.push("--force");
}