Skip to content

Commit fe4dfb9

Browse files
authored
refactor(git): remove runtime facade wrappers (#21982)
1 parent 5e3dc80 commit fe4dfb9

3 files changed

Lines changed: 26 additions & 22 deletions

File tree

packages/opencode/src/cli/cmd/github.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Provider } from "../../provider/provider"
2929
import { Bus } from "../../bus"
3030
import { MessageV2 } from "../../session/message-v2"
3131
import { SessionPrompt } from "@/session/prompt"
32+
import { AppRuntime } from "@/effect/app-runtime"
3233
import { Git } from "@/git"
3334
import { setTimeout as sleep } from "node:timers/promises"
3435
import { Process } from "@/util/process"
@@ -258,7 +259,9 @@ export const GithubInstallCommand = cmd({
258259
}
259260

260261
// Get repo info
261-
const info = (await Git.run(["remote", "get-url", "origin"], { cwd: Instance.worktree })).text().trim()
262+
const info = await AppRuntime.runPromise(
263+
Git.Service.use((git) => git.run(["remote", "get-url", "origin"], { cwd: Instance.worktree })),
264+
).then((x) => x.text().trim())
262265
const parsed = parseGitHubRemote(info)
263266
if (!parsed) {
264267
prompts.log.error(`Could not find git repository. Please run this command from a git repository.`)
@@ -497,20 +500,21 @@ export const GithubRunCommand = cmd({
497500
: "issue"
498501
: undefined
499502
const gitText = async (args: string[]) => {
500-
const result = await Git.run(args, { cwd: Instance.worktree })
503+
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
501504
if (result.exitCode !== 0) {
502505
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
503506
}
504507
return result.text().trim()
505508
}
506509
const gitRun = async (args: string[]) => {
507-
const result = await Git.run(args, { cwd: Instance.worktree })
510+
const result = await AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
508511
if (result.exitCode !== 0) {
509512
throw new Process.RunFailedError(["git", ...args], result.exitCode, result.stdout, result.stderr)
510513
}
511514
return result
512515
}
513-
const gitStatus = (args: string[]) => Git.run(args, { cwd: Instance.worktree })
516+
const gitStatus = (args: string[]) =>
517+
AppRuntime.runPromise(Git.Service.use((git) => git.run(args, { cwd: Instance.worktree })))
514518
const commitChanges = async (summary: string, actor?: string) => {
515519
const args = ["commit", "-m", summary]
516520
if (actor) args.push("-m", `Co-authored-by: ${actor} <${actor}@users.noreply.github.com>`)

packages/opencode/src/cli/cmd/pr.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { UI } from "../ui"
22
import { cmd } from "./cmd"
3+
import { AppRuntime } from "@/effect/app-runtime"
34
import { Git } from "@/git"
45
import { Instance } from "@/project/instance"
56
import { Process } from "@/util/process"
@@ -67,19 +68,29 @@ export const PrCommand = cmd({
6768
const remoteName = forkOwner
6869

6970
// Check if remote already exists
70-
const remotes = (await Git.run(["remote"], { cwd: Instance.worktree })).text().trim()
71+
const remotes = await AppRuntime.runPromise(
72+
Git.Service.use((git) => git.run(["remote"], { cwd: Instance.worktree })),
73+
).then((x) => x.text().trim())
7174
if (!remotes.split("\n").includes(remoteName)) {
72-
await Git.run(["remote", "add", remoteName, `https://github.com/${forkOwner}/${forkName}.git`], {
73-
cwd: Instance.worktree,
74-
})
75+
await AppRuntime.runPromise(
76+
Git.Service.use((git) =>
77+
git.run(["remote", "add", remoteName, `https://github.com/${forkOwner}/${forkName}.git`], {
78+
cwd: Instance.worktree,
79+
}),
80+
),
81+
)
7582
UI.println(`Added fork remote: ${remoteName}`)
7683
}
7784

7885
// Set upstream to the fork so pushes go there
7986
const headRefName = prInfo.headRefName
80-
await Git.run(["branch", `--set-upstream-to=${remoteName}/${headRefName}`, localBranchName], {
81-
cwd: Instance.worktree,
82-
})
87+
await AppRuntime.runPromise(
88+
Git.Service.use((git) =>
89+
git.run(["branch", `--set-upstream-to=${remoteName}/${headRefName}`, localBranchName], {
90+
cwd: Instance.worktree,
91+
}),
92+
),
93+
)
8394
}
8495

8596
// Check for opencode session link in PR body

packages/opencode/src/git/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as CrossSpawnSpawner from "@/effect/cross-spawn-spawner"
22
import { Effect, Layer, Context, Stream } from "effect"
33
import { ChildProcess, ChildProcessSpawner } from "effect/unstable/process"
4-
import { makeRuntime } from "@/effect/run-service"
54

65
export namespace Git {
76
const cfg = [
@@ -258,14 +257,4 @@ export namespace Git {
258257
)
259258

260259
export const defaultLayer = layer.pipe(Layer.provide(CrossSpawnSpawner.defaultLayer))
261-
262-
const { runPromise } = makeRuntime(Service, defaultLayer)
263-
264-
export async function run(args: string[], opts: Options) {
265-
return runPromise((git) => git.run(args, opts))
266-
}
267-
268-
export async function defaultBranch(cwd: string) {
269-
return runPromise((git) => git.defaultBranch(cwd))
270-
}
271260
}

0 commit comments

Comments
 (0)