@@ -9,6 +9,7 @@ import {
99 import { tmpdir } from "node:os";
1010 import { join } from "node:path";
1111 import {
12+ applyParentChanges,
1213 cleanupBranch,
1314 createWorktree,
1415 hasDirtyWorkingTree,
@@ -189,4 +190,63 @@ describe("worktree helpers", () => {
189190 await cleanupBranch(repoDir, branch1);
190191 await cleanupBranch(repoDir, branch2);
191192 });
193+
194+ test("applyParentChanges propagates unstaged tracked changes", async () => {
195+ const { branch, wtPath } = makeWorktreeDir("apply-unstaged");
196+ await createWorktree(repoDir, branch, wtPath);
197+
198+ writeFileSync(join(repoDir, "README.md"), "unstaged change\n");
199+
200+ await applyParentChanges(repoDir, wtPath);
201+
202+ expect(await Bun.file(join(wtPath, "README.md")).text()).toBe(
203+ "unstaged change\n",
204+ );
205+
206+ await removeWorktree(repoDir, wtPath);
207+ await cleanupBranch(repoDir, branch);
208+ });
209+
210+ test("applyParentChanges propagates staged changes", async () => {
211+ const { branch, wtPath } = makeWorktreeDir("apply-staged");
212+ await createWorktree(repoDir, branch, wtPath);
213+
214+ writeFileSync(join(repoDir, "README.md"), "staged change\n");
215+ git(repoDir, ["add", "README.md"]);
216+
217+ await applyParentChanges(repoDir, wtPath);
218+
219+ expect(await Bun.file(join(wtPath, "README.md")).text()).toBe(
220+ "staged change\n",
221+ );
222+
223+ await removeWorktree(repoDir, wtPath);
224+ await cleanupBranch(repoDir, branch);
225+ });
226+
227+ test("applyParentChanges copies untracked new files", async () => {
228+ const { branch, wtPath } = makeWorktreeDir("apply-untracked");
229+ await createWorktree(repoDir, branch, wtPath);
230+
231+ writeFileSync(join(repoDir, "new-file.ts"), "export const x = 1;\n");
232+
233+ await applyParentChanges(repoDir, wtPath);
234+
235+ expect(await Bun.file(join(wtPath, "new-file.ts")).text()).toBe(
236+ "export const x = 1;\n",
237+ );
238+
239+ await removeWorktree(repoDir, wtPath);
240+ await cleanupBranch(repoDir, branch);
241+ });
242+
243+ test("applyParentChanges no-ops cleanly on a clean tree", async () => {
244+ const { branch, wtPath } = makeWorktreeDir("apply-clean");
245+ await createWorktree(repoDir, branch, wtPath);
246+
247+ await expect(applyParentChanges(repoDir, wtPath)).resolves.toBeUndefined();
248+
249+ await removeWorktree(repoDir, wtPath);
250+ await cleanupBranch(repoDir, branch);
251+ });
192252 });