GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — refactor: use InstanceState context in worktree cleanup paths (#23019) · anomalyco/opencode@471b9f4

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • packages/opencode/src/worktree
    • index.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎packages/opencode/src/worktree/index.ts‎

Copy file name to clipboardExpand all lines: packages/opencode/src/worktree/index.ts
+13-11Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -365,13 +365,14 @@ export const layer: Layer.Layer<
365365
}
366366

367367
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") {
369370
throw new NotGitError({ message: "Worktrees are only supported for git projects" })
370371
}
371372

372373
const directory = yield* canonical(input.directory)
373374

374-
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: Instance.worktree })
375+
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree })
375376
if (list.code !== 0) {
376377
throw new RemoveFailedError({ message: list.stderr || list.text || "Failed to read git worktrees" })
377378
}
@@ -389,9 +390,9 @@ export const layer: Layer.Layer<
389390
}
390391

391392
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 })
393394
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 })
395396
if (next.code !== 0) {
396397
throw new RemoveFailedError({
397398
message: removed.stderr || removed.text || next.stderr || next.text || "Failed to remove git worktree",
@@ -408,7 +409,7 @@ export const layer: Layer.Layer<
408409

409410
const branch = entry.branch?.replace(/^refs\/heads\//, "")
410411
if (branch) {
411-
const deleted = yield* git(["branch", "-D", branch], { cwd: Instance.worktree })
412+
const deleted = yield* git(["branch", "-D", branch], { cwd: ctx.worktree })
412413
if (deleted.code !== 0) {
413414
throw new RemoveFailedError({
414415
message: deleted.stderr || deleted.text || "Failed to delete worktree branch",
@@ -498,17 +499,18 @@ export const layer: Layer.Layer<
498499
})
499500

500501
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") {
502504
throw new NotGitError({ message: "Worktrees are only supported for git projects" })
503505
}
504506

505507
const directory = yield* canonical(input.directory)
506-
const primary = yield* canonical(Instance.worktree)
508+
const primary = yield* canonical(ctx.worktree)
507509
if (directory === primary) {
508510
throw new ResetFailedError({ message: "Cannot reset the primary workspace" })
509511
}
510512

511-
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: Instance.worktree })
513+
const list = yield* git(["worktree", "list", "--porcelain"], { cwd: ctx.worktree })
512514
if (list.code !== 0) {
513515
throw new ResetFailedError({ message: list.stderr || list.text || "Failed to read git worktrees" })
514516
}
@@ -520,7 +522,7 @@ export const layer: Layer.Layer<
520522

521523
const worktreePath = entry.path
522524

523-
const base = yield* gitSvc.defaultBranch(Instance.worktree)
525+
const base = yield* gitSvc.defaultBranch(ctx.worktree)
524526
if (!base) {
525527
throw new ResetFailedError({ message: "Default branch not found" })
526528
}
@@ -531,7 +533,7 @@ export const layer: Layer.Layer<
531533
const branch = base.ref.slice(sep + 1)
532534
yield* gitExpect(
533535
["fetch", remote, branch],
534-
{ cwd: Instance.worktree },
536+
{ cwd: ctx.worktree },
535537
(r) => new ResetFailedError({ message: r.stderr || r.text || `Failed to fetch ${base.ref}` }),
536538
)
537539
}
@@ -574,7 +576,7 @@ export const layer: Layer.Layer<
574576
throw new ResetFailedError({ message: `Worktree reset left local changes:\n${status.text.trim()}` })
575577
}
576578

577-
yield* runStartScripts(worktreePath, { projectID: Instance.project.id }).pipe(
579+
yield* runStartScripts(worktreePath, { projectID: ctx.project.id }).pipe(
578580
Effect.catchCause((cause) => Effect.sync(() => log.error("worktree start task failed", { cause }))),
579581
Effect.forkIn(scope),
580582
)

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.