@@ -365,13 +365,14 @@ export const layer: Layer.Layer< |
365 | 365 | } |
366 | 366 |
|
367 | 367 | const remove = Effect.fn("Worktree.remove")(function* (input: RemoveInput) { |
368 | | - if (Instance.project.vcs !== "git") { |
| 368 | + const ctx = yield* InstanceState.context |
| 369 | + if (ctx.project.vcs !== "git") { |
369 | 370 | throw new NotGitError({ message: "Worktrees are only supported for git projects" }) |
370 | 371 | } |
371 | 372 |
|
372 | 373 | const directory = yield* canonical(input.directory) |
373 | 374 |
|
374 | | - const list = yield* git(["worktree", "list", "--porcelain"], { cwd: Instance.worktree }) |
| 375 | + const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree }) |
375 | 376 | if (list.code !== 0) { |
376 | 377 | throw new RemoveFailedError({ message: list.stderr || list.text || "Failed to read git worktrees" }) |
377 | 378 | } |
@@ -389,9 +390,9 @@ export const layer: Layer.Layer< |
389 | 390 | } |
390 | 391 |
|
391 | 392 | yield* stopFsmonitor(entry.path) |
392 | | - const removed = yield* git(["worktree", "remove", "--force", entry.path], { cwd: Instance.worktree }) |
| 393 | + const removed = yield* git(["worktree", "remove", "--force", entry.path], { cwd: ctx.worktree }) |
393 | 394 | if (removed.code !== 0) { |
394 | | - const next = yield* git(["worktree", "list", "--porcelain"], { cwd: Instance.worktree }) |
| 395 | + const next = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree }) |
395 | 396 | if (next.code !== 0) { |
396 | 397 | throw new RemoveFailedError({ |
397 | 398 | message: removed.stderr || removed.text || next.stderr || next.text || "Failed to remove git worktree", |
@@ -408,7 +409,7 @@ export const layer: Layer.Layer< |
408 | 409 |
|
409 | 410 | const branch = entry.branch?.replace(/^refs\/heads\//, "") |
410 | 411 | if (branch) { |
411 | | - const deleted = yield* git(["branch", "-D", branch], { cwd: Instance.worktree }) |
| 412 | + const deleted = yield* git(["branch", "-D", branch], { cwd: ctx.worktree }) |
412 | 413 | if (deleted.code !== 0) { |
413 | 414 | throw new RemoveFailedError({ |
414 | 415 | message: deleted.stderr || deleted.text || "Failed to delete worktree branch", |
@@ -498,17 +499,18 @@ export const layer: Layer.Layer< |
498 | 499 | }) |
499 | 500 |
|
500 | 501 | const reset = Effect.fn("Worktree.reset")(function* (input: ResetInput) { |
501 | | - if (Instance.project.vcs !== "git") { |
| 502 | + const ctx = yield* InstanceState.context |
| 503 | + if (ctx.project.vcs !== "git") { |
502 | 504 | throw new NotGitError({ message: "Worktrees are only supported for git projects" }) |
503 | 505 | } |
504 | 506 |
|
505 | 507 | const directory = yield* canonical(input.directory) |
506 | | - const primary = yield* canonical(Instance.worktree) |
| 508 | + const primary = yield* canonical(ctx.worktree) |
507 | 509 | if (directory === primary) { |
508 | 510 | throw new ResetFailedError({ message: "Cannot reset the primary workspace" }) |
509 | 511 | } |
510 | 512 |
|
511 | | - const list = yield* git(["worktree", "list", "--porcelain"], { cwd: Instance.worktree }) |
| 513 | + const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree }) |
512 | 514 | if (list.code !== 0) { |
513 | 515 | throw new ResetFailedError({ message: list.stderr || list.text || "Failed to read git worktrees" }) |
514 | 516 | } |
@@ -520,7 +522,7 @@ export const layer: Layer.Layer< |
520 | 522 |
|
521 | 523 | const worktreePath = entry.path |
522 | 524 |
|
523 | | - const base = yield* gitSvc.defaultBranch(Instance.worktree) |
| 525 | + const base = yield* gitSvc.defaultBranch(ctx.worktree) |
524 | 526 | if (!base) { |
525 | 527 | throw new ResetFailedError({ message: "Default branch not found" }) |
526 | 528 | } |
@@ -531,7 +533,7 @@ export const layer: Layer.Layer< |
531 | 533 | const branch = base.ref.slice(sep + 1) |
532 | 534 | yield* gitExpect( |
533 | 535 | ["fetch", remote, branch], |
534 | | - { cwd: Instance.worktree }, |
| 536 | + { cwd: ctx.worktree }, |
535 | 537 | (r) => new ResetFailedError({ message: r.stderr || r.text || `Failed to fetch ${base.ref}` }), |
536 | 538 | ) |
537 | 539 | } |
@@ -574,7 +576,7 @@ export const layer: Layer.Layer< |
574 | 576 | throw new ResetFailedError({ message: `Worktree reset left local changes:\n${status.text.trim()}` }) |
575 | 577 | } |
576 | 578 |
|
577 | | - yield* runStartScripts(worktreePath, { projectID: Instance.project.id }).pipe( |
| 579 | + yield* runStartScripts(worktreePath, { projectID: ctx.project.id }).pipe( |
578 | 580 | Effect.catchCause((cause) => Effect.sync(() => log.error("worktree start task failed", { cause }))), |
579 | 581 | Effect.forkIn(scope), |
580 | 582 | ) |
|