Skip to content
TypeScript

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

Dara Adedejid9068d38099f
diff --git a/apps/server/src/vcs/GitVcsDriverCore.test.ts b/apps/server/src/vcs/GitVcsDriverCore.test.ts
index c6e24caa625..1238477d4cb 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.test.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.test.ts
@@ -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");
diff --git a/apps/server/src/vcs/GitVcsDriverCore.ts b/apps/server/src/vcs/GitVcsDriverCore.ts
index 140786cce0a..16932533096 100644
--- a/apps/server/src/vcs/GitVcsDriverCore.ts
+++ b/apps/server/src/vcs/GitVcsDriverCore.ts
@@ -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");
}