@carlosstenzel/opencode-git-sidebar 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README-pt-br.md +120 -0
- package/README.md +19 -5
- package/dist/gui-experimental.cjs +129 -7
- package/docs/images/git-sidebar-diff.svg +58 -0
- package/docs/images/git-sidebar-files.svg +99 -0
- package/docs/images/git-sidebar-overview.svg +79 -0
- package/package.json +8 -2
- package/src/commit-selected.ts +165 -0
- package/src/git-exec.ts +105 -0
- package/src/git-parse.ts +121 -0
- package/src/git-read.ts +225 -0
- package/src/graph-canvas.tsx +174 -0
- package/src/graph-theme.ts +27 -0
- package/src/graph.ts +191 -0
- package/src/gui-load.ts +151 -0
- package/src/gui.tsx +436 -149
- package/src/index.ts +38 -342
- package/src/rpc.ts +4 -1
- package/src/style.ts +125 -3
- package/src/ui-helpers.ts +43 -0
package/src/index.ts
CHANGED
|
@@ -1,49 +1,29 @@
|
|
|
1
|
-
import { execFile } from "node:child_process"
|
|
2
|
-
import { lstat, readFile } from "node:fs/promises"
|
|
3
|
-
import { basename, join } from "node:path"
|
|
4
|
-
import { promisify } from "node:util"
|
|
5
1
|
import { Plugin } from "@opencode/plugin"
|
|
2
|
+
import {
|
|
3
|
+
diffBase,
|
|
4
|
+
errorMessage,
|
|
5
|
+
repoRoot,
|
|
6
|
+
run,
|
|
7
|
+
runOptional,
|
|
8
|
+
runRaw,
|
|
9
|
+
safePath,
|
|
10
|
+
safeRef,
|
|
11
|
+
} from "./git-exec.js"
|
|
12
|
+
|
|
13
|
+
import { commitSelectedPaths } from "./commit-selected.js"
|
|
14
|
+
|
|
15
|
+
import { readBranches, readChanges, readCommits, readStatus, type Branch, type Commit } from "./git-read.js"
|
|
6
16
|
import { Git } from "./rpc.js"
|
|
7
17
|
|
|
8
|
-
const exec = promisify(execFile)
|
|
9
|
-
|
|
10
18
|
type DirectoryInput = { directory: string }
|
|
11
19
|
type LimitInput = { directory: string; limit?: number }
|
|
20
|
+
type CommitsInput = LimitInput & { all?: boolean }
|
|
12
21
|
type PrInput = { directory: string; title?: string }
|
|
13
22
|
type BranchActionInput = { directory: string; action: "checkout" | "create" | "delete" | "merge"; name: string }
|
|
14
23
|
type CommitInput = { directory: string; message: string }
|
|
15
24
|
type CommitSelectedInput = { directory: string; message: string; files: string[] }
|
|
16
25
|
type DiffInput = { directory: string; path: string; from?: string }
|
|
17
26
|
|
|
18
|
-
type Status = {
|
|
19
|
-
repo: string
|
|
20
|
-
branch: string
|
|
21
|
-
dirty: boolean
|
|
22
|
-
changes: number
|
|
23
|
-
ahead: number
|
|
24
|
-
behind: number
|
|
25
|
-
upstream: string
|
|
26
|
-
}
|
|
27
|
-
type Branch = {
|
|
28
|
-
name: string
|
|
29
|
-
current: boolean
|
|
30
|
-
upstream: string
|
|
31
|
-
ahead: number
|
|
32
|
-
behind: number
|
|
33
|
-
hash: string
|
|
34
|
-
subject: string
|
|
35
|
-
date: string
|
|
36
|
-
}
|
|
37
|
-
type Commit = {
|
|
38
|
-
hash: string
|
|
39
|
-
short: string
|
|
40
|
-
subject: string
|
|
41
|
-
author: string
|
|
42
|
-
date: string
|
|
43
|
-
files: string[]
|
|
44
|
-
}
|
|
45
|
-
type Stat = { additions: number; deletions: number; binary: boolean }
|
|
46
|
-
type Change = { status: string; path: string; from?: string } & Partial<Stat>
|
|
47
27
|
type Pull = {
|
|
48
28
|
number: number
|
|
49
29
|
title: string
|
|
@@ -62,143 +42,9 @@ type Issue = {
|
|
|
62
42
|
}
|
|
63
43
|
type Result = { ok: boolean; text: string }
|
|
64
44
|
|
|
65
|
-
async function run(command: string, args: string[], directory: string, signal?: AbortSignal) {
|
|
66
|
-
const { stdout } = await exec(command, args, {
|
|
67
|
-
cwd: directory,
|
|
68
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
69
|
-
signal,
|
|
70
|
-
})
|
|
71
|
-
return stdout.trim()
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async function runOptional(command: string, args: string[], directory: string, signal?: AbortSignal) {
|
|
75
|
-
try {
|
|
76
|
-
return await run(command, args, directory, signal)
|
|
77
|
-
} catch {
|
|
78
|
-
return ""
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// Like `run`, but keeps stdout as git wrote it (no trim) and returns what was printed even when the command exits
|
|
83
|
-
// non-zero, as `git diff --no-index` does when the files differ.
|
|
84
|
-
async function runRaw(command: string, args: string[], directory: string, signal?: AbortSignal) {
|
|
85
|
-
try {
|
|
86
|
-
const { stdout } = await exec(command, args, {
|
|
87
|
-
cwd: directory,
|
|
88
|
-
maxBuffer: 10 * 1024 * 1024,
|
|
89
|
-
signal,
|
|
90
|
-
})
|
|
91
|
-
return stdout
|
|
92
|
-
} catch (error: any) {
|
|
93
|
-
return String(error?.stdout ?? "")
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
45
|
const DIFF_ARGS = ["-c", "core.quotePath=false", "diff", "--no-color", "--no-ext-diff"]
|
|
98
|
-
const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
|
|
99
|
-
const UNTRACKED_STAT_FILES = 400
|
|
100
|
-
const UNTRACKED_STAT_BYTES = 512 * 1024
|
|
101
46
|
const UNTRACKED_DIFF_FILES = 100
|
|
102
47
|
|
|
103
|
-
// `git status --porcelain` paths are relative to the repository root, so path commands run from there.
|
|
104
|
-
async function repoRoot(directory: string, signal?: AbortSignal) {
|
|
105
|
-
return (await runOptional("git", ["rev-parse", "--show-toplevel"], directory, signal)) || directory
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// What the working tree is compared against: HEAD, or the empty tree in a repository without commits.
|
|
109
|
-
async function diffBase(directory: string, signal?: AbortSignal) {
|
|
110
|
-
if (await runOptional("git", ["rev-parse", "--verify", "--quiet", "HEAD"], directory, signal)) return "HEAD"
|
|
111
|
-
return (await runOptional("git", ["hash-object", "-t", "tree", "/dev/null"], directory, signal)) || EMPTY_TREE
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Parses `git status --porcelain -z`: `XY path\0`, with the original path as an extra field after a rename or copy.
|
|
115
|
-
function parseStatus(raw: string) {
|
|
116
|
-
const fields = raw.split("\0")
|
|
117
|
-
const changes: Change[] = []
|
|
118
|
-
for (let index = 0; index < fields.length; index++) {
|
|
119
|
-
const field = fields[index]
|
|
120
|
-
if (field.length < 4) continue
|
|
121
|
-
const code = field.slice(0, 2)
|
|
122
|
-
const change: Change = { status: code.trim(), path: field.slice(3) }
|
|
123
|
-
if (code.includes("R") || code.includes("C")) {
|
|
124
|
-
const from = fields[++index]
|
|
125
|
-
if (from) change.from = from
|
|
126
|
-
}
|
|
127
|
-
changes.push(change)
|
|
128
|
-
}
|
|
129
|
-
return changes
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Parses `git diff --numstat -z`: `added\tdeleted\tpath\0`, or `added\tdeleted\t\0old\0new\0` for a rename.
|
|
133
|
-
function parseNumstat(raw: string) {
|
|
134
|
-
const stats = new Map<string, Stat>()
|
|
135
|
-
const fields = raw.split("\0")
|
|
136
|
-
for (let index = 0; index < fields.length; index++) {
|
|
137
|
-
const match = /^(-|\d+)\t(-|\d+)\t([\s\S]*)$/.exec(fields[index])
|
|
138
|
-
if (!match) continue
|
|
139
|
-
let path = match[3]
|
|
140
|
-
if (!path) {
|
|
141
|
-
index += 2
|
|
142
|
-
path = fields[index] ?? ""
|
|
143
|
-
}
|
|
144
|
-
if (!path) continue
|
|
145
|
-
const binary = match[1] === "-" || match[2] === "-"
|
|
146
|
-
stats.set(path, {
|
|
147
|
-
additions: binary ? 0 : Number(match[1]) || 0,
|
|
148
|
-
deletions: binary ? 0 : Number(match[2]) || 0,
|
|
149
|
-
binary,
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
return stats
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// Lines an untracked file would add. Undefined when it is not a regular file or is too large to count cheaply.
|
|
156
|
-
async function untrackedStat(file: string): Promise<Stat | undefined> {
|
|
157
|
-
try {
|
|
158
|
-
const info = await lstat(file)
|
|
159
|
-
if (!info.isFile() || info.size > UNTRACKED_STAT_BYTES) return undefined
|
|
160
|
-
const bytes = await readFile(file)
|
|
161
|
-
if (bytes.subarray(0, 8000).includes(0)) return { additions: 0, deletions: 0, binary: true }
|
|
162
|
-
let lines = 0
|
|
163
|
-
for (const byte of bytes) if (byte === 10) lines++
|
|
164
|
-
if (bytes.length > 0 && bytes[bytes.length - 1] !== 10) lines++
|
|
165
|
-
return { additions: lines, deletions: 0, binary: false }
|
|
166
|
-
} catch {
|
|
167
|
-
return undefined
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// Stats of the untracked entries of `git status`: a file, or a directory git lists as one entry (`dir/`).
|
|
172
|
-
async function untrackedStats(entries: Change[], root: string, signal?: AbortSignal) {
|
|
173
|
-
const stats = new Map<string, Stat>()
|
|
174
|
-
if (!entries.length) return stats
|
|
175
|
-
const raw = await runRaw("git", ["ls-files", "--others", "--exclude-standard", "-z"], root, signal)
|
|
176
|
-
const files = raw.split("\0").filter(Boolean)
|
|
177
|
-
if (files.length > UNTRACKED_STAT_FILES) return stats
|
|
178
|
-
const counted = new Map<string, Stat | undefined>()
|
|
179
|
-
for (let start = 0; start < files.length; start += 16) {
|
|
180
|
-
const batch = files.slice(start, start + 16)
|
|
181
|
-
const results = await Promise.all(batch.map((file) => untrackedStat(join(root, file))))
|
|
182
|
-
batch.forEach((file, index) => counted.set(file, results[index]))
|
|
183
|
-
}
|
|
184
|
-
for (const entry of entries) {
|
|
185
|
-
const inside = entry.path.endsWith("/") ? files.filter((file) => file.startsWith(entry.path)) : [entry.path]
|
|
186
|
-
const parts = inside.map((file) => counted.get(file))
|
|
187
|
-
if (!parts.length || parts.some((part) => !part)) continue
|
|
188
|
-
const known = parts as Stat[]
|
|
189
|
-
stats.set(entry.path, {
|
|
190
|
-
additions: known.reduce((sum, part) => sum + part.additions, 0),
|
|
191
|
-
deletions: 0,
|
|
192
|
-
binary: known.every((part) => part.binary),
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
return stats
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function errorMessage(error: unknown) {
|
|
199
|
-
return error instanceof Error ? error.message : String(error)
|
|
200
|
-
}
|
|
201
|
-
|
|
202
48
|
function parseChecks(rollup: unknown): Pull["checks"] {
|
|
203
49
|
const checks = Array.isArray(rollup) ? rollup : []
|
|
204
50
|
if (!checks.length) return "none"
|
|
@@ -214,71 +60,13 @@ function parseChecks(rollup: unknown): Pull["checks"] {
|
|
|
214
60
|
return success ? "success" : "none"
|
|
215
61
|
}
|
|
216
62
|
|
|
217
|
-
function safeRef(name: string) {
|
|
218
|
-
return /^[A-Za-z0-9._/-]+$/.test(name) && !name.startsWith("-") && !name.includes("..")
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
function safePath(path: string) {
|
|
222
|
-
return (
|
|
223
|
-
!!path &&
|
|
224
|
-
!path.startsWith("/") &&
|
|
225
|
-
!path.startsWith("-") &&
|
|
226
|
-
!path.includes("\n") &&
|
|
227
|
-
!path.includes("\r") &&
|
|
228
|
-
!path.split("/").includes("..")
|
|
229
|
-
)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
async function counts(upstream: string, ref: string, directory: string, signal?: AbortSignal) {
|
|
233
|
-
const raw = await runOptional(
|
|
234
|
-
"git",
|
|
235
|
-
["rev-list", "--left-right", "--count", `${upstream}...${ref}`],
|
|
236
|
-
directory,
|
|
237
|
-
signal,
|
|
238
|
-
)
|
|
239
|
-
const [behind, ahead] = raw.split(/\s+/).map((value) => Number(value) || 0)
|
|
240
|
-
return { ahead, behind }
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
function splitRecord(line: string) {
|
|
244
|
-
const parts = line.split("\x1f")
|
|
245
|
-
return {
|
|
246
|
-
hash: parts[0] ?? "",
|
|
247
|
-
short: parts[1] ?? "",
|
|
248
|
-
subject: parts[2] ?? "",
|
|
249
|
-
author: parts[3] ?? "",
|
|
250
|
-
date: parts[4] ?? "",
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
63
|
export default Plugin.define({
|
|
255
64
|
id: "git-sidebar",
|
|
256
65
|
async setup(ctx) {
|
|
257
66
|
await ctx.rpc.register(Git, {
|
|
258
67
|
status: async (input, context) => {
|
|
259
68
|
const { directory } = input as DirectoryInput
|
|
260
|
-
|
|
261
|
-
(await runOptional("git", ["rev-parse", "--abbrev-ref", "HEAD"], directory, context.signal)) ||
|
|
262
|
-
"(desanexado)"
|
|
263
|
-
const root = await runOptional("git", ["rev-parse", "--show-toplevel"], directory, context.signal)
|
|
264
|
-
const porcelain = await runOptional("git", ["status", "--porcelain"], directory, context.signal)
|
|
265
|
-
const changes = porcelain ? porcelain.split("\n").filter(Boolean).length : 0
|
|
266
|
-
const upstream = await runOptional(
|
|
267
|
-
"git",
|
|
268
|
-
["rev-parse", "--abbrev-ref", "@{upstream}"],
|
|
269
|
-
directory,
|
|
270
|
-
context.signal,
|
|
271
|
-
)
|
|
272
|
-
const { ahead, behind } = upstream ? await counts(upstream, "HEAD", directory, context.signal) : { ahead: 0, behind: 0 }
|
|
273
|
-
return {
|
|
274
|
-
repo: root ? basename(root) : basename(directory),
|
|
275
|
-
branch,
|
|
276
|
-
dirty: changes > 0,
|
|
277
|
-
changes,
|
|
278
|
-
ahead,
|
|
279
|
-
behind,
|
|
280
|
-
upstream,
|
|
281
|
-
} satisfies Status
|
|
69
|
+
return readStatus(directory, context.signal)
|
|
282
70
|
},
|
|
283
71
|
|
|
284
72
|
pulls: async (input, context) => {
|
|
@@ -295,7 +83,7 @@ export default Plugin.define({
|
|
|
295
83
|
"number,title,url,headRefName,statusCheckRollup",
|
|
296
84
|
],
|
|
297
85
|
directory,
|
|
298
|
-
context.signal,
|
|
86
|
+
{ signal: context.signal },
|
|
299
87
|
)
|
|
300
88
|
const pulls = JSON.parse(raw || "[]")
|
|
301
89
|
return (Array.isArray(pulls) ? pulls : []).map((pull: any): Pull => ({
|
|
@@ -326,7 +114,7 @@ export default Plugin.define({
|
|
|
326
114
|
"number,title,url,author,labels,comments,createdAt",
|
|
327
115
|
],
|
|
328
116
|
directory,
|
|
329
|
-
context.signal,
|
|
117
|
+
{ signal: context.signal },
|
|
330
118
|
)
|
|
331
119
|
const issues = JSON.parse(raw || "[]")
|
|
332
120
|
return (Array.isArray(issues) ? issues : []).map((issue: any): Issue => ({
|
|
@@ -347,92 +135,17 @@ export default Plugin.define({
|
|
|
347
135
|
|
|
348
136
|
branches: async (input, context) => {
|
|
349
137
|
const { directory, limit } = input as LimitInput
|
|
350
|
-
|
|
351
|
-
const format = "%(refname:short)\t%(objectname:short)\t%(upstream:short)\t%(contents:subject)\t%(committerdate:iso-strict)"
|
|
352
|
-
const local = await runOptional(
|
|
353
|
-
"git",
|
|
354
|
-
["for-each-ref", `--format=${format}`, "refs/heads"],
|
|
355
|
-
directory,
|
|
356
|
-
context.signal,
|
|
357
|
-
)
|
|
358
|
-
const remote = await runOptional(
|
|
359
|
-
"git",
|
|
360
|
-
["for-each-ref", `--format=${format}`, "refs/remotes"],
|
|
361
|
-
directory,
|
|
362
|
-
context.signal,
|
|
363
|
-
)
|
|
364
|
-
const lines = [local, remote].filter(Boolean).join("\n").split("\n").filter(Boolean)
|
|
365
|
-
const result: Branch[] = []
|
|
366
|
-
for (const line of lines) {
|
|
367
|
-
const [name, hash, upstream, subject, date] = line.split("\t")
|
|
368
|
-
if (!name || name.endsWith("/HEAD")) continue
|
|
369
|
-
const position = await counts(upstream, name, directory, context.signal)
|
|
370
|
-
result.push({
|
|
371
|
-
name,
|
|
372
|
-
current: name === current,
|
|
373
|
-
upstream: upstream || "",
|
|
374
|
-
ahead: upstream ? position.ahead : 0,
|
|
375
|
-
behind: upstream ? position.behind : 0,
|
|
376
|
-
hash: hash || "",
|
|
377
|
-
subject: subject || "",
|
|
378
|
-
date: date || "",
|
|
379
|
-
})
|
|
380
|
-
if (result.length >= (limit || 60)) break
|
|
381
|
-
}
|
|
382
|
-
return result
|
|
138
|
+
return readBranches(directory, limit, context.signal)
|
|
383
139
|
},
|
|
384
140
|
|
|
385
141
|
commits: async (input, context) => {
|
|
386
|
-
const { directory, limit } = input as
|
|
387
|
-
|
|
388
|
-
"git",
|
|
389
|
-
[
|
|
390
|
-
"log",
|
|
391
|
-
`--max-count=${limit || 20}`,
|
|
392
|
-
"--date=iso-strict",
|
|
393
|
-
"--pretty=format:%H%x1f%h%x1f%s%x1f%an%x1f%ad",
|
|
394
|
-
],
|
|
395
|
-
directory,
|
|
396
|
-
context.signal,
|
|
397
|
-
)
|
|
398
|
-
const commits: Commit[] = []
|
|
399
|
-
for (const line of raw.split("\n").filter(Boolean)) {
|
|
400
|
-
const record = splitRecord(line)
|
|
401
|
-
if (!record.hash) continue
|
|
402
|
-
const filesRaw = await runOptional(
|
|
403
|
-
"git",
|
|
404
|
-
["diff-tree", "--no-commit-id", "--name-only", "-r", record.hash],
|
|
405
|
-
directory,
|
|
406
|
-
context.signal,
|
|
407
|
-
)
|
|
408
|
-
commits.push({
|
|
409
|
-
...record,
|
|
410
|
-
files: filesRaw.split("\n").filter(Boolean),
|
|
411
|
-
})
|
|
412
|
-
}
|
|
413
|
-
return commits
|
|
142
|
+
const { directory, limit, all } = input as CommitsInput
|
|
143
|
+
return readCommits(directory, limit, context.signal, all)
|
|
414
144
|
},
|
|
415
145
|
|
|
416
146
|
changes: async (input, context) => {
|
|
417
147
|
const { directory } = input as DirectoryInput
|
|
418
|
-
|
|
419
|
-
const raw = await runRaw("git", ["status", "--porcelain", "-z"], directory, context.signal)
|
|
420
|
-
const changes = parseStatus(raw)
|
|
421
|
-
if (!changes.length) return changes
|
|
422
|
-
const root = await repoRoot(directory, context.signal)
|
|
423
|
-
const base = await diffBase(root, context.signal)
|
|
424
|
-
const [tracked, untracked] = await Promise.all([
|
|
425
|
-
runRaw("git", [...DIFF_ARGS, "--numstat", "-z", "-M", base, "--"], root, context.signal).then(parseNumstat),
|
|
426
|
-
untrackedStats(
|
|
427
|
-
changes.filter((change) => change.status === "??"),
|
|
428
|
-
root,
|
|
429
|
-
context.signal,
|
|
430
|
-
),
|
|
431
|
-
])
|
|
432
|
-
return changes.map((change): Change => ({
|
|
433
|
-
...change,
|
|
434
|
-
...(change.status === "??" ? untracked.get(change.path) : tracked.get(change.path)),
|
|
435
|
-
}))
|
|
148
|
+
return readChanges(directory, context.signal)
|
|
436
149
|
},
|
|
437
150
|
|
|
438
151
|
branchAction: async (input, context) => {
|
|
@@ -445,7 +158,7 @@ export default Plugin.define({
|
|
|
445
158
|
merge: ["merge", name, "--no-edit"],
|
|
446
159
|
}
|
|
447
160
|
try {
|
|
448
|
-
const text = await run("git", commands[action], directory, context.signal)
|
|
161
|
+
const text = await run("git", commands[action], directory, { signal: context.signal })
|
|
449
162
|
return { ok: true, text: text || `branch ${action} concluído` } satisfies Result
|
|
450
163
|
} catch (error) {
|
|
451
164
|
return { ok: false, text: errorMessage(error) } satisfies Result
|
|
@@ -455,7 +168,7 @@ export default Plugin.define({
|
|
|
455
168
|
pull: async (input, context) => {
|
|
456
169
|
const { directory } = input as DirectoryInput
|
|
457
170
|
try {
|
|
458
|
-
const text = await run("git", ["pull", "--ff-only"], directory, context.signal)
|
|
171
|
+
const text = await run("git", ["pull", "--ff-only"], directory, { signal: context.signal })
|
|
459
172
|
return { ok: true, text: text || "pull concluído" } satisfies Result
|
|
460
173
|
} catch (error) {
|
|
461
174
|
return { ok: false, text: errorMessage(error) } satisfies Result
|
|
@@ -465,7 +178,7 @@ export default Plugin.define({
|
|
|
465
178
|
push: async (input, context) => {
|
|
466
179
|
const { directory } = input as DirectoryInput
|
|
467
180
|
try {
|
|
468
|
-
const text = await run("git", ["push", "-u", "origin", "HEAD"], directory, context.signal)
|
|
181
|
+
const text = await run("git", ["push", "-u", "origin", "HEAD"], directory, { signal: context.signal })
|
|
469
182
|
return { ok: true, text: text || "push concluído" } satisfies Result
|
|
470
183
|
} catch (error) {
|
|
471
184
|
return { ok: false, text: errorMessage(error) } satisfies Result
|
|
@@ -476,8 +189,8 @@ export default Plugin.define({
|
|
|
476
189
|
const { directory, message } = input as CommitInput
|
|
477
190
|
if (!message.trim()) return { ok: false, text: "Mensagem vazia" } satisfies Result
|
|
478
191
|
try {
|
|
479
|
-
await run("git", ["add", "-A"], directory, context.signal)
|
|
480
|
-
const text = await run("git", ["commit", "-m", message], directory, context.signal)
|
|
192
|
+
await run("git", ["add", "-A"], directory, { signal: context.signal })
|
|
193
|
+
const text = await run("git", ["commit", "-m", message], directory, { signal: context.signal })
|
|
481
194
|
return { ok: true, text: text || "commit criado" } satisfies Result
|
|
482
195
|
} catch (error) {
|
|
483
196
|
return { ok: false, text: errorMessage(error) } satisfies Result
|
|
@@ -489,30 +202,7 @@ export default Plugin.define({
|
|
|
489
202
|
if (!message.trim()) return { ok: false, text: "Mensagem vazia" } satisfies Result
|
|
490
203
|
const clean = files.filter(safePath)
|
|
491
204
|
if (!clean.length) return { ok: false, text: "Nenhum arquivo válido selecionado" } satisfies Result
|
|
492
|
-
|
|
493
|
-
// The paths come from `git status --porcelain`, which is relative to the repository root.
|
|
494
|
-
const root = await repoRoot(directory, context.signal)
|
|
495
|
-
const stagedDeleted = new Set(
|
|
496
|
-
(
|
|
497
|
-
await runOptional(
|
|
498
|
-
"git",
|
|
499
|
-
["diff", "--cached", "--name-only", "--diff-filter=D", "-z", "--"],
|
|
500
|
-
root,
|
|
501
|
-
context.signal,
|
|
502
|
-
)
|
|
503
|
-
)
|
|
504
|
-
.split("\0")
|
|
505
|
-
.filter(Boolean),
|
|
506
|
-
)
|
|
507
|
-
const stageable = clean.filter((path) => !stagedDeleted.has(path))
|
|
508
|
-
if (stageable.length) {
|
|
509
|
-
await run("git", ["add", "-A", "--", ...stageable], root, context.signal)
|
|
510
|
-
}
|
|
511
|
-
const text = await run("git", ["commit", "-m", message], directory, context.signal)
|
|
512
|
-
return { ok: true, text: text || "commit criado" } satisfies Result
|
|
513
|
-
} catch (error) {
|
|
514
|
-
return { ok: false, text: errorMessage(error) } satisfies Result
|
|
515
|
-
}
|
|
205
|
+
return await commitSelectedPaths(directory, message, clean, context.signal)
|
|
516
206
|
},
|
|
517
207
|
|
|
518
208
|
fileDiff: async (input, context) => {
|
|
@@ -521,7 +211,9 @@ export default Plugin.define({
|
|
|
521
211
|
const root = await repoRoot(directory, context.signal)
|
|
522
212
|
// Untracked: a file, or every file of a directory git lists as one entry.
|
|
523
213
|
const others = (
|
|
524
|
-
await runRaw("git", ["ls-files", "--others", "--exclude-standard", "-z", "--", path], root,
|
|
214
|
+
await runRaw("git", ["ls-files", "--others", "--exclude-standard", "-z", "--", path], root, {
|
|
215
|
+
signal: context.signal,
|
|
216
|
+
})
|
|
525
217
|
)
|
|
526
218
|
.split("\0")
|
|
527
219
|
.filter(Boolean)
|
|
@@ -530,7 +222,9 @@ export default Plugin.define({
|
|
|
530
222
|
const parts: string[] = []
|
|
531
223
|
for (const file of shown) {
|
|
532
224
|
parts.push(
|
|
533
|
-
await runRaw("git", [...DIFF_ARGS, "--no-index", "--", "/dev/null", file], root,
|
|
225
|
+
await runRaw("git", [...DIFF_ARGS, "--no-index", "--", "/dev/null", file], root, {
|
|
226
|
+
signal: context.signal,
|
|
227
|
+
}),
|
|
534
228
|
)
|
|
535
229
|
}
|
|
536
230
|
const text = parts
|
|
@@ -541,7 +235,9 @@ export default Plugin.define({
|
|
|
541
235
|
}
|
|
542
236
|
const base = await diffBase(root, context.signal)
|
|
543
237
|
const paths = from && from !== path ? [from, path] : [path]
|
|
544
|
-
const text = await runRaw("git", [...DIFF_ARGS, "-M", base, "--", ...paths], root,
|
|
238
|
+
const text = await runRaw("git", [...DIFF_ARGS, "-M", base, "--", ...paths], root, {
|
|
239
|
+
signal: context.signal,
|
|
240
|
+
})
|
|
545
241
|
return { text: text.replace(/\n+$/, "") }
|
|
546
242
|
},
|
|
547
243
|
|
|
@@ -550,7 +246,7 @@ export default Plugin.define({
|
|
|
550
246
|
try {
|
|
551
247
|
const args = ["pr", "create", "--fill"]
|
|
552
248
|
if (title) args.push("--title", title)
|
|
553
|
-
const text = await run("gh", args, directory, context.signal)
|
|
249
|
+
const text = await run("gh", args, directory, { signal: context.signal })
|
|
554
250
|
return { ok: true, text: text || "PR criado" } satisfies Result
|
|
555
251
|
} catch (error) {
|
|
556
252
|
return { ok: false, text: errorMessage(error) } satisfies Result
|
package/src/rpc.ts
CHANGED
|
@@ -49,8 +49,10 @@ const commitOutput = {
|
|
|
49
49
|
author: { type: "string" },
|
|
50
50
|
date: { type: "string" },
|
|
51
51
|
files: { type: "array", items: { type: "string" } },
|
|
52
|
+
parents: { type: "array", items: { type: "string" } },
|
|
53
|
+
refs: { type: "array", items: { type: "string" } },
|
|
52
54
|
},
|
|
53
|
-
required: ["hash", "short", "subject", "author", "date", "files"],
|
|
55
|
+
required: ["hash", "short", "subject", "author", "date", "files", "parents", "refs"],
|
|
54
56
|
additionalProperties: false,
|
|
55
57
|
} as const
|
|
56
58
|
|
|
@@ -183,6 +185,7 @@ export const Git = Rpc.define({
|
|
|
183
185
|
properties: {
|
|
184
186
|
directory: { type: "string" },
|
|
185
187
|
limit: { type: "number" },
|
|
188
|
+
all: { type: "boolean" },
|
|
186
189
|
},
|
|
187
190
|
required: ["directory"],
|
|
188
191
|
additionalProperties: false,
|
package/src/style.ts
CHANGED
|
@@ -55,16 +55,110 @@ export const css = `
|
|
|
55
55
|
.gs-tabs {
|
|
56
56
|
display: flex;
|
|
57
57
|
gap: 4px;
|
|
58
|
+
min-width: 0;
|
|
59
|
+
flex-wrap: nowrap;
|
|
60
|
+
overflow-x: auto;
|
|
61
|
+
overflow-y: hidden;
|
|
62
|
+
scrollbar-width: thin;
|
|
63
|
+
scrollbar-color: color-mix(in srgb, currentColor 28%, transparent) transparent;
|
|
64
|
+
}
|
|
65
|
+
.gs-tabs::-webkit-scrollbar {
|
|
66
|
+
height: 4px;
|
|
67
|
+
}
|
|
68
|
+
.gs-tabs::-webkit-scrollbar-thumb {
|
|
69
|
+
border-radius: 999px;
|
|
70
|
+
background: color-mix(in srgb, currentColor 22%, transparent);
|
|
71
|
+
}
|
|
72
|
+
.gs-tabs::-webkit-scrollbar-track {
|
|
73
|
+
background: transparent;
|
|
58
74
|
}
|
|
59
75
|
.gs-tab {
|
|
60
|
-
flex:
|
|
76
|
+
flex-shrink: 0;
|
|
77
|
+
white-space: nowrap;
|
|
61
78
|
}
|
|
62
79
|
.gs-toolbar {
|
|
63
80
|
display: flex;
|
|
64
|
-
|
|
81
|
+
align-items: center;
|
|
82
|
+
gap: 3px 4px;
|
|
65
83
|
flex-wrap: wrap;
|
|
66
84
|
}
|
|
85
|
+
.gs-branchbar {
|
|
86
|
+
display: flex;
|
|
87
|
+
align-items: center;
|
|
88
|
+
gap: 4px;
|
|
89
|
+
min-width: 0;
|
|
90
|
+
}
|
|
91
|
+
.gs-branchfilter {
|
|
92
|
+
flex: 1;
|
|
93
|
+
min-width: 0;
|
|
94
|
+
}
|
|
95
|
+
.gs-graph {
|
|
96
|
+
/* Lane hues picked to clear 3:1 against both a white and a near-black row
|
|
97
|
+
background; hosts can retune them with these custom properties. */
|
|
98
|
+
--gs-lane-0: #2563eb;
|
|
99
|
+
--gs-lane-1: #0d9488;
|
|
100
|
+
--gs-lane-2: #8b5cf6;
|
|
101
|
+
--gs-lane-3: #c2410c;
|
|
102
|
+
--gs-lane-4: #db2777;
|
|
103
|
+
}
|
|
104
|
+
/* One canvas for the whole list: absolutely positioned and inert, it can never
|
|
105
|
+
change a row's height (which would feed the ResizeObserver back into layout). */
|
|
106
|
+
.gs-graph {
|
|
107
|
+
position: absolute;
|
|
108
|
+
top: 0;
|
|
109
|
+
left: 8px;
|
|
110
|
+
pointer-events: none;
|
|
111
|
+
z-index: 0;
|
|
112
|
+
}
|
|
113
|
+
.gs-graph svg {
|
|
114
|
+
display: block;
|
|
115
|
+
overflow: visible;
|
|
116
|
+
}
|
|
117
|
+
/* Rows reserve the graph column through their left padding and paint above it. */
|
|
118
|
+
.gs-graphrow {
|
|
119
|
+
position: relative;
|
|
120
|
+
z-index: 1;
|
|
121
|
+
}
|
|
122
|
+
.gs-ref {
|
|
123
|
+
font-size: 11px;
|
|
124
|
+
padding: 0 4px;
|
|
125
|
+
border: 1px dashed color-mix(in srgb, currentColor 35%, transparent);
|
|
126
|
+
border-radius: 999px;
|
|
127
|
+
max-width: 90px;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
text-overflow: ellipsis;
|
|
130
|
+
white-space: nowrap;
|
|
131
|
+
}
|
|
132
|
+
.gs-viewtoggle {
|
|
133
|
+
display: inline-flex;
|
|
134
|
+
border: 1px solid color-mix(in srgb, currentColor 22%, transparent);
|
|
135
|
+
border-radius: 999px;
|
|
136
|
+
overflow: hidden;
|
|
137
|
+
}
|
|
138
|
+
.gs-viewtoggle button {
|
|
139
|
+
appearance: none;
|
|
140
|
+
border: 0;
|
|
141
|
+
background: transparent;
|
|
142
|
+
color: inherit;
|
|
143
|
+
font: inherit;
|
|
144
|
+
font-size: 11px;
|
|
145
|
+
padding: 3px 9px;
|
|
146
|
+
cursor: pointer;
|
|
147
|
+
}
|
|
148
|
+
.gs-viewtoggle button[aria-selected="true"] {
|
|
149
|
+
background: color-mix(in srgb, currentColor 14%, transparent);
|
|
150
|
+
}
|
|
151
|
+
.gs-viewtoggle button:disabled {
|
|
152
|
+
cursor: default;
|
|
153
|
+
opacity: 0.5;
|
|
154
|
+
}
|
|
155
|
+
.gs-viewtoggle button:focus-visible {
|
|
156
|
+
outline: 1px solid currentColor;
|
|
157
|
+
outline-offset: -1px;
|
|
158
|
+
}
|
|
67
159
|
.gs-scroll {
|
|
160
|
+
/* Absolute GraphCanvas children (and row offsetTop) anchor here. */
|
|
161
|
+
position: relative;
|
|
68
162
|
display: flex;
|
|
69
163
|
flex: 1;
|
|
70
164
|
min-height: 0;
|
|
@@ -85,6 +179,17 @@ export const css = `
|
|
|
85
179
|
border-color: color-mix(in srgb, currentColor 14%, transparent);
|
|
86
180
|
background: color-mix(in srgb, currentColor 6%, transparent);
|
|
87
181
|
}
|
|
182
|
+
.gs-row-static,
|
|
183
|
+
.gs-row-static:hover {
|
|
184
|
+
cursor: default;
|
|
185
|
+
border-color: transparent;
|
|
186
|
+
background: transparent;
|
|
187
|
+
}
|
|
188
|
+
.gs-row:focus-visible {
|
|
189
|
+
outline: 1px solid currentColor;
|
|
190
|
+
outline-offset: -1px;
|
|
191
|
+
border-color: color-mix(in srgb, currentColor 24%, transparent);
|
|
192
|
+
}
|
|
88
193
|
.gs-row-main {
|
|
89
194
|
display: flex;
|
|
90
195
|
flex: 1;
|
|
@@ -115,6 +220,23 @@ export const css = `
|
|
|
115
220
|
align-items: center;
|
|
116
221
|
gap: 2px;
|
|
117
222
|
flex-shrink: 0;
|
|
223
|
+
opacity: 0.35;
|
|
224
|
+
transition: opacity 120ms ease;
|
|
225
|
+
}
|
|
226
|
+
.gs-row:hover .gs-actions,
|
|
227
|
+
.gs-actions:focus-within,
|
|
228
|
+
.gs-row:focus-within .gs-actions {
|
|
229
|
+
opacity: 1;
|
|
230
|
+
}
|
|
231
|
+
@media (hover: none) {
|
|
232
|
+
.gs-actions {
|
|
233
|
+
opacity: 1;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
@media (prefers-reduced-motion: reduce) {
|
|
237
|
+
.gs-actions {
|
|
238
|
+
transition: none;
|
|
239
|
+
}
|
|
118
240
|
}
|
|
119
241
|
.gs-empty {
|
|
120
242
|
padding: 18px 8px;
|
|
@@ -249,7 +371,7 @@ export const css = `
|
|
|
249
371
|
background: color-mix(in srgb, currentColor 6%, transparent);
|
|
250
372
|
}
|
|
251
373
|
.gs-gtoggle:focus-visible {
|
|
252
|
-
outline: 1px solid
|
|
374
|
+
outline: 1px solid currentColor;
|
|
253
375
|
outline-offset: 1px;
|
|
254
376
|
}
|
|
255
377
|
.gs-gchevron {
|