ignore: git slop
This commit is contained in:
parent
5eb4080947
commit
5fc91fdadc
5 changed files with 39 additions and 44 deletions
|
|
@ -11,7 +11,7 @@ import { createWrapper } from "@parcel/watcher/wrapper"
|
||||||
import { lazy } from "@/util/lazy"
|
import { lazy } from "@/util/lazy"
|
||||||
import { withTimeout } from "@/util/timeout"
|
import { withTimeout } from "@/util/timeout"
|
||||||
import type ParcelWatcher from "@parcel/watcher"
|
import type ParcelWatcher from "@parcel/watcher"
|
||||||
import { $ } from "bun"
|
import { gitText } from "../util/git"
|
||||||
import { Flag } from "@/flag/flag"
|
import { Flag } from "@/flag/flag"
|
||||||
import { readdir } from "fs/promises"
|
import { readdir } from "fs/promises"
|
||||||
|
|
||||||
|
|
@ -88,11 +88,7 @@ export namespace FileWatcher {
|
||||||
if (sub) subs.push(sub)
|
if (sub) subs.push(sub)
|
||||||
}
|
}
|
||||||
|
|
||||||
const vcsDir = await $`git rev-parse --git-dir`
|
const vcsDir = await gitText(["rev-parse", "--git-dir"], Instance.worktree)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(Instance.worktree)
|
|
||||||
.text()
|
|
||||||
.then((x) => path.resolve(Instance.worktree, x.trim()))
|
.then((x) => path.resolve(Instance.worktree, x.trim()))
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) {
|
if (vcsDir && !cfgIgnores.includes(".git") && !cfgIgnores.includes(vcsDir)) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import z from "zod"
|
||||||
import fs from "fs/promises"
|
import fs from "fs/promises"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { $ } from "bun"
|
import { gitText } from "../util/git"
|
||||||
import { Storage } from "../storage/storage"
|
import { Storage } from "../storage/storage"
|
||||||
import { Log } from "../util/log"
|
import { Log } from "../util/log"
|
||||||
import { Flag } from "@/flag/flag"
|
import { Flag } from "@/flag/flag"
|
||||||
|
|
@ -55,15 +55,15 @@ export namespace Project {
|
||||||
|
|
||||||
const { id, sandbox, worktree, vcs } = await iife(async () => {
|
const { id, sandbox, worktree, vcs } = await iife(async () => {
|
||||||
const matches = Filesystem.up({ targets: [".git"], start: directory })
|
const matches = Filesystem.up({ targets: [".git"], start: directory })
|
||||||
const git = await matches.next().then((x) => x.value)
|
const gitdir = await matches.next().then((x) => x.value)
|
||||||
await matches.return()
|
await matches.return()
|
||||||
if (git) {
|
if (gitdir) {
|
||||||
let sandbox = path.dirname(git)
|
let sandbox = path.dirname(gitdir)
|
||||||
|
|
||||||
const gitBinary = Bun.which("git")
|
const gitBinary = Bun.which("git")
|
||||||
|
|
||||||
// cached id calculation
|
// cached id calculation
|
||||||
let id = await Bun.file(path.join(git, "opencode"))
|
let id = await Bun.file(path.join(gitdir, "opencode"))
|
||||||
.text()
|
.text()
|
||||||
.then((x) => x.trim())
|
.then((x) => x.trim())
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
|
|
@ -79,11 +79,7 @@ export namespace Project {
|
||||||
|
|
||||||
// generate id from root commit
|
// generate id from root commit
|
||||||
if (!id) {
|
if (!id) {
|
||||||
const roots = await $`git rev-list --max-parents=0 --all`
|
const roots = await gitText(["rev-list", "--max-parents=0", "--all"], sandbox)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(sandbox)
|
|
||||||
.text()
|
|
||||||
.then((x) =>
|
.then((x) =>
|
||||||
x
|
x
|
||||||
.split("\n")
|
.split("\n")
|
||||||
|
|
@ -104,7 +100,7 @@ export namespace Project {
|
||||||
|
|
||||||
id = roots[0]
|
id = roots[0]
|
||||||
if (id) {
|
if (id) {
|
||||||
void Bun.file(path.join(git, "opencode"))
|
void Bun.file(path.join(gitdir, "opencode"))
|
||||||
.write(id)
|
.write(id)
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
}
|
}
|
||||||
|
|
@ -119,11 +115,7 @@ export namespace Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const top = await $`git rev-parse --show-toplevel`
|
const top = await gitText(["rev-parse", "--show-toplevel"], sandbox)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(sandbox)
|
|
||||||
.text()
|
|
||||||
.then((x) => path.resolve(sandbox, x.trim()))
|
.then((x) => path.resolve(sandbox, x.trim()))
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
|
|
||||||
|
|
@ -138,11 +130,7 @@ export namespace Project {
|
||||||
|
|
||||||
sandbox = top
|
sandbox = top
|
||||||
|
|
||||||
const worktree = await $`git rev-parse --git-common-dir`
|
const worktree = await gitText(["rev-parse", "--git-common-dir"], sandbox)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(sandbox)
|
|
||||||
.text()
|
|
||||||
.then((x) => {
|
.then((x) => {
|
||||||
const dirname = path.dirname(x.trim())
|
const dirname = path.dirname(x.trim())
|
||||||
if (dirname === ".") return sandbox
|
if (dirname === ".") return sandbox
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { BusEvent } from "@/bus/bus-event"
|
import { BusEvent } from "@/bus/bus-event"
|
||||||
import { Bus } from "@/bus"
|
import { Bus } from "@/bus"
|
||||||
import { $ } from "bun"
|
import { gitText } from "../util/git"
|
||||||
import path from "path"
|
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
import { Log } from "@/util/log"
|
import { Log } from "@/util/log"
|
||||||
import { Instance } from "./instance"
|
import { Instance } from "./instance"
|
||||||
|
|
@ -29,11 +28,7 @@ export namespace Vcs {
|
||||||
export type Info = z.infer<typeof Info>
|
export type Info = z.infer<typeof Info>
|
||||||
|
|
||||||
async function currentBranch() {
|
async function currentBranch() {
|
||||||
return $`git rev-parse --abbrev-ref HEAD`
|
return gitText(["rev-parse", "--abbrev-ref", "HEAD"], Instance.worktree)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(Instance.worktree)
|
|
||||||
.text()
|
|
||||||
.then((x) => x.trim())
|
.then((x) => x.trim())
|
||||||
.catch(() => undefined)
|
.catch(() => undefined)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import { Global } from "../global"
|
||||||
import { Filesystem } from "../util/filesystem"
|
import { Filesystem } from "../util/filesystem"
|
||||||
import { lazy } from "../util/lazy"
|
import { lazy } from "../util/lazy"
|
||||||
import { Lock } from "../util/lock"
|
import { Lock } from "../util/lock"
|
||||||
import { $ } from "bun"
|
import { gitText } from "../util/git"
|
||||||
import { NamedError } from "@opencode-ai/util/error"
|
import { NamedError } from "@opencode-ai/util/error"
|
||||||
import z from "zod"
|
import z from "zod"
|
||||||
|
|
||||||
|
|
@ -45,18 +45,18 @@ export namespace Storage {
|
||||||
}
|
}
|
||||||
if (!worktree) continue
|
if (!worktree) continue
|
||||||
if (!(await Filesystem.isDir(worktree))) continue
|
if (!(await Filesystem.isDir(worktree))) continue
|
||||||
const [id] = await $`git rev-list --max-parents=0 --all`
|
const roots = await gitText(["rev-list", "--max-parents=0", "--all"], worktree)
|
||||||
.quiet()
|
|
||||||
.nothrow()
|
|
||||||
.cwd(worktree)
|
|
||||||
.text()
|
|
||||||
.then((x) =>
|
.then((x) =>
|
||||||
x
|
x
|
||||||
.split("\n")
|
? x
|
||||||
.filter(Boolean)
|
.split("\n")
|
||||||
.map((x) => x.trim())
|
.filter(Boolean)
|
||||||
.toSorted(),
|
.map((x) => x.trim())
|
||||||
|
.toSorted()
|
||||||
|
: undefined,
|
||||||
)
|
)
|
||||||
|
.catch(() => undefined)
|
||||||
|
const id = roots?.[0]
|
||||||
if (!id) continue
|
if (!id) continue
|
||||||
projectID = id
|
projectID = id
|
||||||
|
|
||||||
|
|
|
||||||
16
packages/opencode/src/util/git.ts
Normal file
16
packages/opencode/src/util/git.ts
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
import { $ } from "bun"
|
||||||
|
|
||||||
|
function env() {
|
||||||
|
return {
|
||||||
|
...process.env,
|
||||||
|
GIT_TERMINAL_PROMPT: "0",
|
||||||
|
GIT_ASKPASS: "echo",
|
||||||
|
GIT_PAGER: "cat",
|
||||||
|
PAGER: "",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function gitText(args: string[], cwd: string): Promise<string> {
|
||||||
|
const input = new Response("")
|
||||||
|
return $`git ${args} < ${input}`.env(env()).cwd(cwd).quiet().nothrow().text()
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue