@carlosstenzel/opencode-git-sidebar 0.0.0-stage → 0.1.1

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/src/gui.tsx ADDED
@@ -0,0 +1,1462 @@
1
+ import {
2
+ Command,
3
+ ComposerPill,
4
+ type ComposerPillView,
5
+ MenuItem,
6
+ Panel,
7
+ Plugin,
8
+ Slot,
9
+ Style,
10
+ type SessionPanelMenuItem,
11
+ } from "@opencode/plugin/gui"
12
+ import { createEffect, createMemo, createSignal, For, onCleanup, onMount, Show } from "solid-js"
13
+ import {
14
+ CHANGE_KINDS,
15
+ type ChangeKind,
16
+ type ChangeTone,
17
+ classify,
18
+ type DiffRow,
19
+ type ParsedDiff,
20
+ parseDiff,
21
+ splitPath,
22
+ statBlocks,
23
+ } from "./diff"
24
+ import { Git } from "./rpc"
25
+ import { css } from "./style"
26
+
27
+ type Status = {
28
+ repo: string
29
+ branch: string
30
+ dirty: boolean
31
+ changes: number
32
+ ahead: number
33
+ behind: number
34
+ upstream: string
35
+ }
36
+
37
+ type Branch = {
38
+ name: string
39
+ current: boolean
40
+ upstream: string
41
+ ahead: number
42
+ behind: number
43
+ hash: string
44
+ subject: string
45
+ date: string
46
+ }
47
+
48
+ type Commit = {
49
+ hash: string
50
+ short: string
51
+ subject: string
52
+ author: string
53
+ date: string
54
+ files: string[]
55
+ }
56
+
57
+ type Change = {
58
+ status: string
59
+ path: string
60
+ from?: string
61
+ additions?: number
62
+ deletions?: number
63
+ binary?: boolean
64
+ }
65
+
66
+ type FileItem = {
67
+ change: Change
68
+ kind: ChangeKind
69
+ tone: ChangeTone
70
+ letter: string
71
+ name: string
72
+ dir: string
73
+ }
74
+
75
+ type Stats = { additions: number; deletions: number; binary?: boolean }
76
+ type DiffState = { text: string; parsed: ParsedDiff; truncated: boolean; error?: string }
77
+
78
+ // Rows the diff viewer renders at once; a longer diff shows the rest on demand.
79
+ const DIFF_PAGE = 2000
80
+
81
+ function sumStats(items: FileItem[]): Stats | undefined {
82
+ let additions = 0
83
+ let deletions = 0
84
+ let known = false
85
+ for (const item of items) {
86
+ if (item.change.additions === undefined && item.change.deletions === undefined) continue
87
+ known = true
88
+ additions += item.change.additions ?? 0
89
+ deletions += item.change.deletions ?? 0
90
+ }
91
+ return known ? { additions, deletions } : undefined
92
+ }
93
+
94
+ type Pull = {
95
+ number: number
96
+ title: string
97
+ url: string
98
+ branch: string
99
+ checks: "success" | "failure" | "none"
100
+ }
101
+
102
+ type Issue = {
103
+ number: number
104
+ title: string
105
+ url: string
106
+ author: string
107
+ labels: string[]
108
+ comments: number
109
+ date: string
110
+ }
111
+
112
+ type Result = { ok: boolean; text: string }
113
+ type Tab = "branches" | "commits" | "pulls" | "issues" | "files"
114
+ type BranchAction = "checkout" | "create" | "delete" | "merge"
115
+
116
+ function relative(iso: string) {
117
+ if (!iso) return ""
118
+ const date = new Date(iso)
119
+ const diff = Date.now() - date.getTime()
120
+ if (!Number.isFinite(diff)) return ""
121
+ if (diff < 60_000) return "agora"
122
+ const minutes = Math.floor(diff / 60_000)
123
+ if (minutes < 60) return `${minutes}m`
124
+ const hours = Math.floor(minutes / 60)
125
+ if (hours < 24) return `${hours}h`
126
+ const days = Math.floor(hours / 24)
127
+ if (days < 30) return `${days}d`
128
+ return new Date(iso).toLocaleDateString()
129
+ }
130
+
131
+ export default Plugin.define({
132
+ i18n: {
133
+ en: {
134
+ "git.title": "Git",
135
+ "git.repo": "Repository",
136
+ "git.branch": "Branch",
137
+ "git.clean": "Clean tree",
138
+ "git.changes": "{{count}} changes",
139
+ "git.ahead": "↑ {{count}}",
140
+ "git.behind": "↓ {{count}}",
141
+ "git.refresh": "Refresh",
142
+ "git.push": "Push",
143
+ "git.pull": "Pull",
144
+ "git.pr": "New PR",
145
+ "git.commit": "Commit all",
146
+ "git.commit.selected": "Commit selected",
147
+ "git.commit.selected.confirm": "Commit {{count}} selected files?",
148
+ "git.commit.selected.detail": "Only the checked files will be added and committed.",
149
+ "git.files.selectAll": "Select all",
150
+ "git.files.clear": "Clear",
151
+ "git.files.empty": "No changes in this repository.",
152
+ "git.files.diff": "View diff",
153
+ "git.files.diff.empty": "No visible diff for this file.",
154
+ "git.files.noneSelected": "Select at least one file first.",
155
+ "git.files.count.one": "{{count}} change",
156
+ "git.files.count.other": "{{count}} changes",
157
+ "git.files.selected.one": "{{count}} of {{total}} selected",
158
+ "git.files.selected.other": "{{count}} of {{total}} selected",
159
+ "git.files.selectHint": "Select files to commit",
160
+ "git.files.select": "Select {{name}}",
161
+ "git.files.review": "Review selected diffs",
162
+ "git.files.binary": "binary",
163
+ "git.files.renamedFrom": "Renamed from {{name}}",
164
+ "git.files.group.conflict": "Conflicts",
165
+ "git.files.group.modified": "Modified",
166
+ "git.files.group.added": "Added",
167
+ "git.files.group.deleted": "Deleted",
168
+ "git.files.group.untracked": "Untracked",
169
+ "git.files.group.select": "Select all in {{name}}",
170
+ "git.files.group.clear": "Deselect all in {{name}}",
171
+ "git.files.status.conflict": "Conflict",
172
+ "git.files.status.modified": "Modified",
173
+ "git.files.status.renamed": "Renamed",
174
+ "git.files.status.added": "Added",
175
+ "git.files.status.deleted": "Deleted",
176
+ "git.files.status.untracked": "Untracked",
177
+ "git.diff.label": "Diff of {{name}}",
178
+ "git.diff.previous": "Previous file",
179
+ "git.diff.next": "Next file",
180
+ "git.diff.position": "{{index}} / {{count}}",
181
+ "git.diff.position.selected": "{{index}} / {{count}} selected",
182
+ "git.diff.copy": "Copy diff",
183
+ "git.diff.copied": "Diff copied",
184
+ "git.diff.copyFailed": "Could not copy the diff",
185
+ "git.diff.wrap": "Wrap long lines",
186
+ "git.diff.include": "Include in commit",
187
+ "git.diff.loading": "Loading diff…",
188
+ "git.diff.binary": "Binary file: there is no text diff to show.",
189
+ "git.diff.more": "Show {{count}} more lines",
190
+ "git.diff.truncated": "This folder has more files than the viewer shows.",
191
+ "git.branch.checkout.confirm": "Checkout {{name}}?",
192
+ "git.branch.checkout.detail": "Your local changes would be overwritten. Commit or stash them first, then try again.",
193
+ "git.command.commitSelected": "Git: commit selected files",
194
+ "git.tab.branches": "Branches",
195
+ "git.tab.commits": "Commits",
196
+ "git.tab.pulls": "PRs",
197
+ "git.tab.issues": "Issues",
198
+ "git.tab.files": "Files",
199
+ "git.filter": "Filter branches",
200
+ "git.filter.placeholder": "name or commit",
201
+ "git.files": "files",
202
+ "git.noRepo": "No Git repository in this session directory.",
203
+ "git.branches.empty": "No branches match this filter.",
204
+ "git.commits.empty": "No commits yet.",
205
+ "git.pulls.empty": "No open pull requests.",
206
+ "git.issues.empty": "No open issues.",
207
+ "git.issues": "{{count}} issues",
208
+ "git.error": "Git error",
209
+ "git.done": "Done",
210
+ "git.failed": "Failed",
211
+ "git.branch.create": "New branch",
212
+ "git.branch.create.placeholder": "feature/my-change",
213
+ "git.branch.checkout": "Checkout branch",
214
+ "git.branch.delete": "Delete branch",
215
+ "git.branch.delete.confirm": "Delete branch {{name}}?",
216
+ "git.branch.delete.detail": "This only deletes the local branch. Make sure its commits are merged or pushed.",
217
+ "git.branch.merge": "Merge into current branch",
218
+ "git.branch.merge.confirm": "Merge {{name}}?",
219
+ "git.commit.title": "Commit message",
220
+ "git.commit.placeholder": "Describe this change",
221
+ "git.commit.confirm": "Commit {{count}} changed files?",
222
+ "git.commit.detail": "All current changes will be staged and committed.",
223
+ "git.menu.open": "Open Git panel",
224
+ "git.command.open": "Git: open panel",
225
+ "git.command.push": "Git: push branch",
226
+ "git.command.pull": "Git: pull",
227
+ "git.command.pr": "Git: create pull request",
228
+ "git.command.commit": "Git: commit all changes",
229
+ "git.pulls": "{{count}} open PRs",
230
+ "git.open": "Open Git panel",
231
+ },
232
+ pt: {
233
+ "git.title": "Git",
234
+ "git.repo": "Repositório",
235
+ "git.branch": "Branch",
236
+ "git.clean": "Árvore limpa",
237
+ "git.changes": "{{count}} alterações",
238
+ "git.ahead": "↑ {{count}}",
239
+ "git.behind": "↓ {{count}}",
240
+ "git.refresh": "Atualizar",
241
+ "git.push": "Enviar",
242
+ "git.pull": "Puxar",
243
+ "git.pr": "Novo PR",
244
+ "git.commit": "Commit tudo",
245
+ "git.commit.selected": "Commit selecionados",
246
+ "git.commit.selected.confirm": "Fazer commit de {{count}} arquivos selecionados?",
247
+ "git.commit.selected.detail": "Somente os arquivos marcados serão adicionados e commitados.",
248
+ "git.files.selectAll": "Selecionar todos",
249
+ "git.files.clear": "Limpar",
250
+ "git.files.empty": "Sem alterações neste repositório.",
251
+ "git.files.diff": "Ver diff",
252
+ "git.files.diff.empty": "Sem diff visível para este arquivo.",
253
+ "git.files.noneSelected": "Selecione ao menos um arquivo.",
254
+ "git.files.count.one": "{{count}} alteração",
255
+ "git.files.count.other": "{{count}} alterações",
256
+ "git.files.selected.one": "{{count}} de {{total}} selecionado",
257
+ "git.files.selected.other": "{{count}} de {{total}} selecionados",
258
+ "git.files.selectHint": "Selecione arquivos para o commit",
259
+ "git.files.select": "Selecionar {{name}}",
260
+ "git.files.review": "Revisar diffs dos selecionados",
261
+ "git.files.binary": "binário",
262
+ "git.files.renamedFrom": "Renomeado de {{name}}",
263
+ "git.files.group.conflict": "Conflitos",
264
+ "git.files.group.modified": "Modificados",
265
+ "git.files.group.added": "Adicionados",
266
+ "git.files.group.deleted": "Removidos",
267
+ "git.files.group.untracked": "Não rastreados",
268
+ "git.files.group.select": "Selecionar todos em {{name}}",
269
+ "git.files.group.clear": "Desmarcar todos em {{name}}",
270
+ "git.files.status.conflict": "Conflito",
271
+ "git.files.status.modified": "Modificado",
272
+ "git.files.status.renamed": "Renomeado",
273
+ "git.files.status.added": "Adicionado",
274
+ "git.files.status.deleted": "Removido",
275
+ "git.files.status.untracked": "Não rastreado",
276
+ "git.diff.label": "Diff de {{name}}",
277
+ "git.diff.previous": "Arquivo anterior",
278
+ "git.diff.next": "Próximo arquivo",
279
+ "git.diff.position": "{{index}} / {{count}}",
280
+ "git.diff.position.selected": "{{index}} / {{count}} selecionados",
281
+ "git.diff.copy": "Copiar diff",
282
+ "git.diff.copied": "Diff copiado",
283
+ "git.diff.copyFailed": "Não foi possível copiar o diff",
284
+ "git.diff.wrap": "Quebrar linhas longas",
285
+ "git.diff.include": "Incluir no commit",
286
+ "git.diff.loading": "Carregando diff…",
287
+ "git.diff.binary": "Arquivo binário: não há diff de texto para mostrar.",
288
+ "git.diff.more": "Mostrar mais {{count}} linhas",
289
+ "git.diff.truncated": "Esta pasta tem mais arquivos do que o visualizador mostra.",
290
+ "git.branch.checkout.confirm": "Trocar para {{name}}?",
291
+ "git.branch.checkout.detail": "Suas alterações locais seriam sobrescritas. Faça commit ou stash antes de trocar.",
292
+ "git.command.commitSelected": "Git: fazer commit dos arquivos selecionados",
293
+ "git.tab.branches": "Branches",
294
+ "git.tab.commits": "Commits",
295
+ "git.tab.pulls": "PRs",
296
+ "git.tab.issues": "Issues",
297
+ "git.tab.files": "Arquivos",
298
+ "git.filter": "Filtrar branches",
299
+ "git.filter.placeholder": "nome ou commit",
300
+ "git.files": "arquivos",
301
+ "git.noRepo": "Sem repositório Git neste diretório da sessão.",
302
+ "git.branches.empty": "Nenhuma branch corresponde ao filtro.",
303
+ "git.commits.empty": "Ainda não há commits.",
304
+ "git.pulls.empty": "Nenhum PR aberto.",
305
+ "git.issues.empty": "Nenhuma issue aberta.",
306
+ "git.issues": "{{count}} issues",
307
+ "git.error": "Erro no Git",
308
+ "git.done": "Concluído",
309
+ "git.failed": "Falhou",
310
+ "git.branch.create": "Nova branch",
311
+ "git.branch.create.placeholder": "feature/minha-mudanca",
312
+ "git.branch.checkout": "Trocar para branch",
313
+ "git.branch.delete": "Excluir branch",
314
+ "git.branch.delete.confirm": "Excluir a branch {{name}}?",
315
+ "git.branch.delete.detail": "Isso só exclui a branch local. Confirme que os commits foram mesclados ou enviados.",
316
+ "git.branch.merge": "Mesclar na branch atual",
317
+ "git.branch.merge.confirm": "Mesclar {{name}}?",
318
+ "git.commit.title": "Mensagem do commit",
319
+ "git.commit.placeholder": "Descreva esta mudança",
320
+ "git.commit.confirm": "Fazer commit de {{count}} arquivos alterados?",
321
+ "git.commit.detail": "Todas as alterações atuais serão adicionadas e commitadas.",
322
+ "git.menu.open": "Abrir painel Git",
323
+ "git.command.open": "Git: abrir painel",
324
+ "git.command.push": "Git: enviar branch",
325
+ "git.command.pull": "Git: puxar",
326
+ "git.command.pr": "Git: criar pull request",
327
+ "git.command.commit": "Git: fazer commit das alterações",
328
+ "git.pulls": "{{count}} PRs abertos",
329
+ "git.open": "Abrir painel Git",
330
+ },
331
+ },
332
+
333
+ setup(ctx) {
334
+ const ui = ctx.ui
335
+ const panelKey = () => `${ctx.id}:main`
336
+ const directory = () => ctx.sessions.current()?.directory
337
+
338
+ const [status, setStatus] = createSignal<Status>()
339
+ const [pulls, setPulls] = createSignal<Pull[]>([])
340
+ const [issues, setIssues] = createSignal<Issue[]>([])
341
+ const [branches, setBranches] = createSignal<Branch[]>([])
342
+ const [commits, setCommits] = createSignal<Commit[]>([])
343
+ const [changes, setChanges] = createSignal<Change[]>([])
344
+ const [busy, setBusy] = createSignal(false)
345
+ const [error, setError] = createSignal<string>()
346
+ const [tab, setTab] = createSignal<Tab>("branches")
347
+ const [filter, setFilter] = createSignal("")
348
+ const [expanded, setExpanded] = createSignal<string>()
349
+ const [selected, setSelected] = createSignal<Set<string>>(new Set())
350
+ const [collapsed, setCollapsed] = createSignal<ReadonlySet<ChangeKind>>(new Set())
351
+
352
+ const filteredBranches = createMemo(() => {
353
+ const query = filter().trim().toLowerCase()
354
+ if (!query) return branches()
355
+ return branches().filter(
356
+ (branch) =>
357
+ branch.name.toLowerCase().includes(query) || branch.subject.toLowerCase().includes(query),
358
+ )
359
+ })
360
+
361
+ const fileItems = createMemo<FileItem[]>(() =>
362
+ changes().map((change) => ({ change, ...classify(change.status), ...splitPath(change.path) })),
363
+ )
364
+ const fileGroups = createMemo(() =>
365
+ CHANGE_KINDS.map((kind) => ({ kind, items: fileItems().filter((item) => item.kind === kind) })).filter(
366
+ (group) => group.items.length > 0,
367
+ ),
368
+ )
369
+ // The files in the order the tab lists them, which is the order the diff viewer walks.
370
+ const orderedFiles = createMemo(() => fileGroups().flatMap((group) => group.items))
371
+ const selectedFiles = createMemo(() => orderedFiles().filter((item) => selected().has(item.change.path)))
372
+ const totalStats = createMemo(() => sumStats(fileItems()))
373
+ const selectedStats = createMemo(() => sumStats(selectedFiles()))
374
+
375
+ function toggleFile(path: string, checked: boolean) {
376
+ const next = new Set(selected())
377
+ if (checked) next.add(path)
378
+ else next.delete(path)
379
+ setSelected(next)
380
+ }
381
+
382
+ function toggleFiles(items: FileItem[], checked: boolean) {
383
+ const next = new Set(selected())
384
+ for (const item of items) {
385
+ if (checked) next.add(item.change.path)
386
+ else next.delete(item.change.path)
387
+ }
388
+ setSelected(next)
389
+ }
390
+
391
+ function selectAllFiles() {
392
+ setSelected(new Set(changes().map((change) => change.path)))
393
+ }
394
+
395
+ function clearFiles() {
396
+ setSelected(new Set<string>())
397
+ }
398
+
399
+ function toggleGroup(kind: ChangeKind) {
400
+ const next = new Set(collapsed())
401
+ if (!next.delete(kind)) next.add(kind)
402
+ setCollapsed(next)
403
+ }
404
+
405
+ // Opens the diff viewer on a file. It walks the selected files when the file is one of several selected (or when
406
+ // asked to), and every changed file otherwise.
407
+ function openDiff(path: string, onlySelected = false) {
408
+ const dir = directory()
409
+ if (!dir) return
410
+ const chosen = selectedFiles()
411
+ const scoped = onlySelected || (chosen.length > 1 && selected().has(path))
412
+ const items = scoped ? chosen : orderedFiles()
413
+ const start = items.findIndex((item) => item.change.path === path)
414
+ if (start < 0) return
415
+ ctx.dialogs.open((dialog) => (
416
+ <DiffDialog directory={dir} items={items} start={start} scoped={scoped} close={() => dialog.close()} />
417
+ ))
418
+ }
419
+
420
+ function reviewSelected() {
421
+ const first = selectedFiles()[0]
422
+ if (first) openDiff(first.change.path, true)
423
+ }
424
+
425
+ function StatView(props: { stats?: Stats; blocks?: boolean }) {
426
+ return (
427
+ <Show when={props.stats}>
428
+ {(stats) => (
429
+ <Show
430
+ when={!stats().binary}
431
+ fallback={<span class="gs-stat gs-stat-muted">{ctx.t("git.files.binary")}</span>}
432
+ >
433
+ <span class="gs-stat">
434
+ <Show when={stats().additions > 0}>
435
+ <span class="gs-stat-add">+{stats().additions}</span>
436
+ </Show>
437
+ <Show when={stats().deletions > 0}>
438
+ <span class="gs-stat-del">−{stats().deletions}</span>
439
+ </Show>
440
+ <Show when={props.blocks && stats().additions + stats().deletions > 0}>
441
+ <span class="gs-blocks" aria-hidden="true">
442
+ <For each={statBlocks(stats().additions, stats().deletions)}>
443
+ {(block) => <span class={`gs-block gs-block-${block}`} />}
444
+ </For>
445
+ </span>
446
+ </Show>
447
+ </span>
448
+ </Show>
449
+ )}
450
+ </Show>
451
+ )
452
+ }
453
+
454
+ function Badge(props: { item: FileItem }) {
455
+ return (
456
+ <span
457
+ class={`gs-badge gs-tone-${props.item.tone}`}
458
+ title={ctx.t(`git.files.status.${props.item.tone}`)}
459
+ >
460
+ {props.item.letter}
461
+ </span>
462
+ )
463
+ }
464
+
465
+ function fileStats(change: Change): Stats | undefined {
466
+ if (change.binary) return { additions: 0, deletions: 0, binary: true }
467
+ if (change.additions === undefined && change.deletions === undefined) return undefined
468
+ return { additions: change.additions ?? 0, deletions: change.deletions ?? 0 }
469
+ }
470
+
471
+ function FileRow(props: { item: FileItem }) {
472
+ const item = props.item
473
+ const path = item.change.path
474
+ const checked = () => selected().has(path)
475
+ const hint = item.change.from ? `${path}\n${ctx.t("git.files.renamedFrom", { name: item.change.from })}` : path
476
+ return (
477
+ <div class={`gs-frow gs-frow-${item.kind}`} classList={{ "gs-frow-on": checked() }}>
478
+ <span class="gs-fswitch">
479
+ <ui.Switch
480
+ label={ctx.t("git.files.select", { name: path })}
481
+ hideLabel
482
+ checked={checked()}
483
+ onChange={(next) => toggleFile(path, next)}
484
+ />
485
+ </span>
486
+ <Badge item={item} />
487
+ <div class="gs-fmain" title={hint} onClick={() => openDiff(path)}>
488
+ <span class="gs-fname">{item.name}</span>
489
+ <Show when={item.dir}>
490
+ <span class="gs-fdir">{item.dir}</span>
491
+ </Show>
492
+ </div>
493
+ <StatView stats={fileStats(item.change)} />
494
+ <ui.Tooltip value={ctx.t("git.files.diff")}>
495
+ <ui.IconButton
496
+ icon="eye"
497
+ label={`${ctx.t("git.files.diff")}: ${path}`}
498
+ size="small"
499
+ onClick={() => openDiff(path)}
500
+ />
501
+ </ui.Tooltip>
502
+ </div>
503
+ )
504
+ }
505
+
506
+ function FileGroup(props: { kind: ChangeKind; items: FileItem[] }) {
507
+ const title = () => ctx.t(`git.files.group.${props.kind}`)
508
+ const closed = () => collapsed().has(props.kind)
509
+ const picked = () => props.items.filter((item) => selected().has(item.change.path)).length
510
+ const full = () => picked() === props.items.length
511
+ const action = () => ctx.t(full() ? "git.files.group.clear" : "git.files.group.select", { name: title() })
512
+ return (
513
+ <section class={`gs-group gs-tone-${props.kind}`}>
514
+ <div class="gs-ghead">
515
+ <div
516
+ class="gs-gtoggle"
517
+ role="button"
518
+ tabindex="0"
519
+ aria-expanded={!closed()}
520
+ onClick={() => toggleGroup(props.kind)}
521
+ onKeyDown={(event) => {
522
+ if (event.key !== "Enter" && event.key !== " ") return
523
+ event.preventDefault()
524
+ toggleGroup(props.kind)
525
+ }}
526
+ >
527
+ <ui.Icon name={closed() ? "chevron-right" : "chevron-down"} size="small" class="gs-gchevron" />
528
+ <span class="gs-gdot" />
529
+ <span class="gs-gtitle">{title()}</span>
530
+ <span class="gs-gcount" classList={{ "gs-gcount-on": picked() > 0 }}>
531
+ {picked() > 0 ? `${picked()}/${props.items.length}` : props.items.length}
532
+ </span>
533
+ </div>
534
+ <StatView stats={sumStats(props.items)} />
535
+ <ui.Tooltip value={action()}>
536
+ <ui.IconButton
537
+ icon="checklist"
538
+ label={action()}
539
+ size="small"
540
+ pressed={full()}
541
+ onClick={() => toggleFiles(props.items, !full())}
542
+ />
543
+ </ui.Tooltip>
544
+ </div>
545
+ <Show when={!closed()}>
546
+ <div class="gs-gbody">
547
+ <For each={props.items}>{(item) => <FileRow item={item} />}</For>
548
+ </div>
549
+ </Show>
550
+ </section>
551
+ )
552
+ }
553
+
554
+ function FilesPane() {
555
+ const total = () => fileItems().length
556
+ const count = () => selectedFiles().length
557
+ return (
558
+ <div class="gs-fpane">
559
+ <Show
560
+ when={total() > 0}
561
+ fallback={
562
+ <div class="gs-fempty">
563
+ <ui.Icon name="circle-check" size="large" />
564
+ <span>{ctx.t("git.files.empty")}</span>
565
+ </div>
566
+ }
567
+ >
568
+ <div class="gs-fbar">
569
+ <div class="gs-fbar-info">
570
+ <span class="gs-fbar-title">{ctx.plural("git.files.count", total())}</span>
571
+ <StatView stats={totalStats()} blocks />
572
+ </div>
573
+ <div class="gs-fbar-actions">
574
+ <ui.Button size="small" variant="ghost" disabled={count() === total()} onClick={() => selectAllFiles()}>
575
+ {ctx.t("git.files.selectAll")}
576
+ </ui.Button>
577
+ <ui.Button size="small" variant="ghost" disabled={count() === 0} onClick={() => clearFiles()}>
578
+ {ctx.t("git.files.clear")}
579
+ </ui.Button>
580
+ </div>
581
+ </div>
582
+ <div class="gs-flist">
583
+ <For each={fileGroups()}>{(group) => <FileGroup kind={group.kind} items={group.items} />}</For>
584
+ </div>
585
+ <div class="gs-commitbar" classList={{ "gs-commitbar-on": count() > 0 }}>
586
+ <div class="gs-progress" aria-hidden="true">
587
+ <div class="gs-progress-fill" style={{ width: `${(count() / total()) * 100}%` }} />
588
+ </div>
589
+ <div class="gs-commitbar-row">
590
+ <div class="gs-commitbar-info">
591
+ <span class="gs-commitbar-count">
592
+ {count() > 0
593
+ ? ctx.plural("git.files.selected", count(), { total: total() })
594
+ : ctx.t("git.files.selectHint")}
595
+ </span>
596
+ <Show when={count() > 0}>
597
+ <StatView stats={selectedStats()} />
598
+ </Show>
599
+ </div>
600
+ <div class="gs-commitbar-actions">
601
+ <ui.Tooltip value={ctx.t("git.files.review")}>
602
+ <ui.IconButton
603
+ icon="eye"
604
+ label={ctx.t("git.files.review")}
605
+ size="small"
606
+ disabled={count() === 0}
607
+ onClick={() => reviewSelected()}
608
+ />
609
+ </ui.Tooltip>
610
+ <ui.Button
611
+ size="small"
612
+ variant="contrast"
613
+ icon="check"
614
+ busy={busy()}
615
+ disabled={count() === 0}
616
+ onClick={() => void actSelected()}
617
+ >
618
+ {ctx.t("git.commit.selected")} ({count()})
619
+ </ui.Button>
620
+ </div>
621
+ </div>
622
+ </div>
623
+ </Show>
624
+ </div>
625
+ )
626
+ }
627
+
628
+ function DiffLineView(props: { row: DiffRow }) {
629
+ const row = props.row
630
+ if (row.kind === "file")
631
+ return (
632
+ <div class="gs-dl gs-dl-file">
633
+ <ui.Icon name="file-document" size="small" />
634
+ <span>{row.text}</span>
635
+ </div>
636
+ )
637
+ if (row.kind === "hunk")
638
+ return (
639
+ <div class="gs-dl gs-dl-hunk">
640
+ <span class="gs-dl-range">{row.range}</span>
641
+ <span class="gs-dl-scope">{row.text}</span>
642
+ </div>
643
+ )
644
+ if (row.kind === "meta") return <div class="gs-dl gs-dl-meta">{row.text}</div>
645
+ return (
646
+ <div class={`gs-dl gs-dl-line gs-dl-${row.kind}`}>
647
+ <span class="gs-dl-num">{row.before ?? ""}</span>
648
+ <span class="gs-dl-num">{row.after ?? ""}</span>
649
+ <span class="gs-dl-sign">{row.kind === "add" ? "+" : row.kind === "del" ? "-" : ""}</span>
650
+ <span class="gs-dl-code">
651
+ <Show when={row.parts} fallback={row.text}>
652
+ {(parts) => (
653
+ <For each={parts()}>
654
+ {(part) => (part.emph ? <mark class="gs-dl-emph">{part.text}</mark> : part.text)}
655
+ </For>
656
+ )}
657
+ </Show>
658
+ </span>
659
+ </div>
660
+ )
661
+ }
662
+
663
+ function DiffDialog(props: {
664
+ directory: string
665
+ items: FileItem[]
666
+ start: number
667
+ scoped: boolean
668
+ close: () => void
669
+ }) {
670
+ const [index, setIndex] = createSignal(props.start)
671
+ const [wrap, setWrap] = createSignal(true)
672
+ const [copied, setCopied] = createSignal(false)
673
+ const [limit, setLimit] = createSignal(DIFF_PAGE)
674
+ const [loaded, setLoaded] = createSignal<DiffState>()
675
+ const cache = new Map<string, DiffState>()
676
+ const item = () => props.items[index()]
677
+ const path = () => item().change.path
678
+ const rows = () => loaded()?.parsed.rows ?? []
679
+ const visible = createMemo(() => (rows().length > limit() ? rows().slice(0, limit()) : rows()))
680
+ const stats = (): Stats | undefined => {
681
+ const state = loaded()
682
+ if (!state || state.error) return fileStats(item().change)
683
+ return {
684
+ additions: state.parsed.additions,
685
+ deletions: state.parsed.deletions,
686
+ binary: state.parsed.binary && state.parsed.additions + state.parsed.deletions === 0,
687
+ }
688
+ }
689
+ let viewport: HTMLDivElement | undefined
690
+ let request = 0
691
+ let copyTimer: ReturnType<typeof setTimeout> | undefined
692
+
693
+ createEffect(() => {
694
+ const target = item().change
695
+ const id = ++request
696
+ setLimit(DIFF_PAGE)
697
+ setCopied(false)
698
+ if (viewport) viewport.scrollTop = 0
699
+ const cacheKey = `${target.path}\u0000${target.from ?? ""}`
700
+ const hit = cache.get(cacheKey)
701
+ setLoaded(hit)
702
+ if (hit) return
703
+ ctx.client
704
+ .rpc(Git)
705
+ .fileDiff({ directory: props.directory, path: target.path, ...(target.from ? { from: target.from } : {}) })
706
+ .then(
707
+ (result): DiffState => {
708
+ const { text, truncated } = result as { text: string; truncated?: boolean }
709
+ return { text, parsed: parseDiff(text), truncated: !!truncated }
710
+ },
711
+ (cause): DiffState => ({
712
+ text: "",
713
+ parsed: parseDiff(""),
714
+ truncated: false,
715
+ error: cause instanceof Error ? cause.message : String(cause),
716
+ }),
717
+ )
718
+ .then((state) => {
719
+ if (!state.error) cache.set(cacheKey, state)
720
+ if (id === request) setLoaded(state)
721
+ })
722
+ })
723
+
724
+ onMount(() => viewport?.focus({ preventScroll: true }))
725
+ onCleanup(() => clearTimeout(copyTimer))
726
+
727
+ function go(step: number) {
728
+ const next = index() + step
729
+ if (next >= 0 && next < props.items.length) setIndex(next)
730
+ }
731
+
732
+ async function copy() {
733
+ const text = loaded()?.text
734
+ if (!text) return
735
+ try {
736
+ await ctx.system.copy(text)
737
+ setCopied(true)
738
+ clearTimeout(copyTimer)
739
+ copyTimer = setTimeout(() => setCopied(false), 1600)
740
+ } catch (cause) {
741
+ ctx.toast.show({
742
+ title: ctx.t("git.diff.copyFailed"),
743
+ description: cause instanceof Error ? cause.message : String(cause),
744
+ variant: "error",
745
+ })
746
+ }
747
+ }
748
+
749
+ function onKeyDown(event: KeyboardEvent) {
750
+ if (event.ctrlKey || event.metaKey || event.altKey || props.items.length < 2) return
751
+ const key = event.key.toLowerCase()
752
+ if (key !== "j" && key !== "k") return
753
+ event.preventDefault()
754
+ go(key === "j" ? 1 : -1)
755
+ }
756
+
757
+ return (
758
+ <ui.Dialog
759
+ title={item().name}
760
+ size="x-large"
761
+ footer={<ui.Button onClick={() => props.close()}>{ctx.t("git.done")}</ui.Button>}
762
+ >
763
+ <div class="gs-diff" onKeyDown={onKeyDown}>
764
+ <div class="gs-diff-head">
765
+ <Badge item={item()} />
766
+ <div class="gs-diff-path" title={path()}>
767
+ <span class="gs-diff-dir">{item().dir}</span>
768
+ <span class="gs-diff-name">{item().name}</span>
769
+ </div>
770
+ <StatView stats={stats()} blocks />
771
+ <div class="gs-diff-tools">
772
+ <ui.Switch
773
+ label={ctx.t("git.diff.include")}
774
+ checked={selected().has(path())}
775
+ onChange={(next) => toggleFile(path(), next)}
776
+ />
777
+ <Show when={props.items.length > 1}>
778
+ <div class="gs-diff-nav">
779
+ <ui.Tooltip value={ctx.t("git.diff.previous")} keys={["K"]}>
780
+ <ui.IconButton
781
+ icon="chevron-left"
782
+ label={ctx.t("git.diff.previous")}
783
+ size="small"
784
+ disabled={index() === 0}
785
+ onClick={() => go(-1)}
786
+ />
787
+ </ui.Tooltip>
788
+ <span class="gs-diff-pos">
789
+ {ctx.t(props.scoped ? "git.diff.position.selected" : "git.diff.position", {
790
+ index: index() + 1,
791
+ count: props.items.length,
792
+ })}
793
+ </span>
794
+ <ui.Tooltip value={ctx.t("git.diff.next")} keys={["J"]}>
795
+ <ui.IconButton
796
+ icon="chevron-right"
797
+ label={ctx.t("git.diff.next")}
798
+ size="small"
799
+ disabled={index() === props.items.length - 1}
800
+ onClick={() => go(1)}
801
+ />
802
+ </ui.Tooltip>
803
+ </div>
804
+ </Show>
805
+ <ui.Tooltip value={ctx.t("git.diff.wrap")}>
806
+ <ui.IconButton
807
+ icon="text-wrap"
808
+ label={ctx.t("git.diff.wrap")}
809
+ size="small"
810
+ pressed={wrap()}
811
+ onClick={() => setWrap(!wrap())}
812
+ />
813
+ </ui.Tooltip>
814
+ <ui.Tooltip value={ctx.t(copied() ? "git.diff.copied" : "git.diff.copy")}>
815
+ <ui.IconButton
816
+ icon={copied() ? "check" : "copy"}
817
+ label={ctx.t(copied() ? "git.diff.copied" : "git.diff.copy")}
818
+ size="small"
819
+ disabled={!loaded()?.text}
820
+ onClick={() => void copy()}
821
+ />
822
+ </ui.Tooltip>
823
+ </div>
824
+ </div>
825
+ <div
826
+ class="gs-diff-view"
827
+ classList={{ "gs-diff-wrap": wrap() }}
828
+ ref={viewport}
829
+ tabindex="0"
830
+ role="region"
831
+ aria-label={ctx.t("git.diff.label", { name: path() })}
832
+ style={{ "--gs-digits": String(loaded()?.parsed.digits ?? 2) }}
833
+ >
834
+ <Show
835
+ when={loaded()}
836
+ fallback={
837
+ <div class="gs-diff-note">
838
+ <ui.Loader />
839
+ <span>{ctx.t("git.diff.loading")}</span>
840
+ </div>
841
+ }
842
+ >
843
+ {(state) => (
844
+ <Show
845
+ when={!state().error}
846
+ fallback={
847
+ <div class="gs-diff-note">
848
+ <ui.Icon name="circle-exclamation" />
849
+ <span>{state().error}</span>
850
+ </div>
851
+ }
852
+ >
853
+ <Show
854
+ when={rows().length > 0}
855
+ fallback={<div class="gs-diff-note">{ctx.t("git.files.diff.empty")}</div>}
856
+ >
857
+ <div class="gs-diff-rows">
858
+ <For each={visible()}>{(row) => <DiffLineView row={row} />}</For>
859
+ </div>
860
+ <Show when={state().parsed.binary && state().parsed.additions + state().parsed.deletions === 0}>
861
+ <div class="gs-diff-note">{ctx.t("git.diff.binary")}</div>
862
+ </Show>
863
+ <Show when={rows().length > limit()}>
864
+ <div class="gs-diff-more">
865
+ <ui.Button size="small" onClick={() => setLimit(limit() + DIFF_PAGE)}>
866
+ {ctx.t("git.diff.more", { count: Math.min(DIFF_PAGE, rows().length - limit()) })}
867
+ </ui.Button>
868
+ </div>
869
+ </Show>
870
+ <Show when={state().truncated}>
871
+ <div class="gs-diff-note">{ctx.t("git.diff.truncated")}</div>
872
+ </Show>
873
+ </Show>
874
+ </Show>
875
+ )}
876
+ </Show>
877
+ </div>
878
+ </div>
879
+ </ui.Dialog>
880
+ )
881
+ }
882
+
883
+ async function load() {
884
+ const dir = directory()
885
+ if (!dir) {
886
+ setStatus(undefined)
887
+ setPulls([])
888
+ setIssues([])
889
+ setBranches([])
890
+ setCommits([])
891
+ setChanges([])
892
+ setSelected(new Set<string>())
893
+ return
894
+ }
895
+ setBusy(true)
896
+ setError(undefined)
897
+ try {
898
+ const [nextStatus, nextPulls, nextIssues, nextBranches, nextCommits, nextChanges] = (await Promise.all([
899
+ ctx.client.rpc(Git).status({ directory: dir }),
900
+ ctx.client.rpc(Git).pulls({ directory: dir }),
901
+ ctx.client.rpc(Git).issues({ directory: dir }),
902
+ ctx.client.rpc(Git).branches({ directory: dir, limit: 60 }),
903
+ ctx.client.rpc(Git).commits({ directory: dir, limit: 20 }),
904
+ ctx.client.rpc(Git).changes({ directory: dir }),
905
+ ])) as [Status, Pull[], Issue[], Branch[], Commit[], Change[]]
906
+ setStatus(nextStatus)
907
+ setPulls(nextPulls)
908
+ setIssues(nextIssues)
909
+ setBranches(nextBranches)
910
+ setCommits(nextCommits)
911
+ setChanges(nextChanges)
912
+ const valid = new Set(nextChanges.map((change) => change.path))
913
+ setSelected(new Set([...selected()].filter((path) => valid.has(path))))
914
+ } catch (cause) {
915
+ setError(cause instanceof Error ? cause.message : String(cause))
916
+ } finally {
917
+ setBusy(false)
918
+ }
919
+ }
920
+
921
+ createEffect(() => {
922
+ directory()
923
+ void load()
924
+ })
925
+
926
+ function openPanel() {
927
+ const session = ctx.sessions.current()
928
+ if (session) ctx.layout.open(panelKey(), session)
929
+ }
930
+
931
+ async function notify(result: Result) {
932
+ await ctx.dialogs.alert({
933
+ title: result.ok ? ctx.t("git.done") : ctx.t("git.failed"),
934
+ description: result.text,
935
+ })
936
+ }
937
+
938
+ async function act(kind: "push" | "pull" | "pr" | "commit") {
939
+ const dir = directory()
940
+ if (!dir) return
941
+ let message = ""
942
+ if (kind === "commit") {
943
+ const prompted = await ctx.dialogs.prompt({
944
+ title: ctx.t("git.commit.title"),
945
+ placeholder: ctx.t("git.commit.placeholder"),
946
+ })
947
+ if (!prompted) return
948
+ message = prompted.trim()
949
+ if (!message) return
950
+ const confirmed = await ctx.dialogs.confirm({
951
+ title: ctx.t("git.commit.confirm", { count: changes().length }),
952
+ description: ctx.t("git.commit.detail"),
953
+ confirm: ctx.t("git.commit"),
954
+ })
955
+ if (!confirmed) return
956
+ }
957
+ setBusy(true)
958
+ try {
959
+ const result = (await (() => {
960
+ switch (kind) {
961
+ case "push":
962
+ return ctx.client.rpc(Git).push({ directory: dir })
963
+ case "pull":
964
+ return ctx.client.rpc(Git).pull({ directory: dir })
965
+ case "pr":
966
+ return ctx.client.rpc(Git).pr({ directory: dir })
967
+ case "commit":
968
+ return ctx.client.rpc(Git).commit({ directory: dir, message })
969
+ }
970
+ })()) as Result
971
+ await notify(result)
972
+ await load()
973
+ } finally {
974
+ setBusy(false)
975
+ }
976
+ }
977
+
978
+ async function actSelected() {
979
+ const dir = directory()
980
+ if (!dir) return
981
+ const files = [...selected()]
982
+ if (!files.length) {
983
+ await ctx.dialogs.alert({ title: ctx.t("git.files.noneSelected") })
984
+ return
985
+ }
986
+ const prompted = await ctx.dialogs.prompt({
987
+ title: ctx.t("git.commit.title"),
988
+ placeholder: ctx.t("git.commit.placeholder"),
989
+ })
990
+ if (!prompted) return
991
+ const message = prompted.trim()
992
+ if (!message) return
993
+ const confirmed = await ctx.dialogs.confirm({
994
+ title: ctx.t("git.commit.selected.confirm", { count: files.length }),
995
+ description: ctx.t("git.commit.selected.detail"),
996
+ confirm: ctx.t("git.commit.selected"),
997
+ })
998
+ if (!confirmed) return
999
+ setBusy(true)
1000
+ try {
1001
+ const result = (await ctx.client.rpc(Git).commitSelected({ directory: dir, message, files })) as Result
1002
+ await notify(result)
1003
+ if (result.ok) clearFiles()
1004
+ await load()
1005
+ } finally {
1006
+ setBusy(false)
1007
+ }
1008
+ }
1009
+
1010
+ async function branchAct(kind: BranchAction, name?: string) {
1011
+ const dir = directory()
1012
+ if (!dir) return
1013
+ let target = name ?? ""
1014
+ if (kind === "create") {
1015
+ const prompted = await ctx.dialogs.prompt({
1016
+ title: ctx.t("git.branch.create"),
1017
+ placeholder: ctx.t("git.branch.create.placeholder"),
1018
+ })
1019
+ if (!prompted) return
1020
+ target = prompted.trim()
1021
+ if (!target) return
1022
+ }
1023
+ if (!target) return
1024
+ const needsConfirm =
1025
+ kind === "delete" || kind === "merge" || (kind === "checkout" && !!status()?.dirty)
1026
+ if (needsConfirm) {
1027
+ const title =
1028
+ kind === "delete"
1029
+ ? ctx.t("git.branch.delete.confirm", { name: target })
1030
+ : kind === "merge"
1031
+ ? ctx.t("git.branch.merge.confirm", { name: target })
1032
+ : ctx.t("git.branch.checkout.confirm", { name: target })
1033
+ const description =
1034
+ kind === "delete"
1035
+ ? ctx.t("git.branch.delete.detail")
1036
+ : kind === "merge"
1037
+ ? undefined
1038
+ : ctx.t("git.branch.checkout.detail")
1039
+ const confirm =
1040
+ kind === "delete"
1041
+ ? ctx.t("git.branch.delete")
1042
+ : kind === "merge"
1043
+ ? ctx.t("git.branch.merge")
1044
+ : ctx.t("git.branch.checkout")
1045
+ const confirmed = await ctx.dialogs.confirm({
1046
+ title,
1047
+ description,
1048
+ confirm,
1049
+ danger: kind === "delete",
1050
+ })
1051
+ if (!confirmed) return
1052
+ }
1053
+ setBusy(true)
1054
+ try {
1055
+ const result = (await ctx.client
1056
+ .rpc(Git)
1057
+ .branchAction({ directory: dir, action: kind, name: target })) as Result
1058
+ await notify(result)
1059
+ await load()
1060
+ } finally {
1061
+ setBusy(false)
1062
+ }
1063
+ }
1064
+
1065
+ ctx.add(Style, css)
1066
+
1067
+ ctx.add(Panel, {
1068
+ id: "main",
1069
+ region: "side",
1070
+ width: "narrow",
1071
+ list: (input) =>
1072
+ input.open.includes("main")
1073
+ ? [
1074
+ {
1075
+ id: "main",
1076
+ title: ctx.t("git.title"),
1077
+ icon: "github",
1078
+ closable: "compact",
1079
+ fallback: true,
1080
+ },
1081
+ ]
1082
+ : [],
1083
+ render: () => (
1084
+ <div class="gs-root">
1085
+ <Show when={error()}>
1086
+ {(message) => <div class="gs-error">{ctx.t("git.error")}: {message()}</div>}
1087
+ </Show>
1088
+
1089
+ <div class="gs-card">
1090
+ <div class="gs-head">
1091
+ <ui.Icon name="github" size="small" />
1092
+ <span class="gs-repo">{status()?.repo || ctx.t("git.repo")}</span>
1093
+ <span class="gs-branch">
1094
+ <ui.Icon name="branch" size="small" />
1095
+ {status()?.branch || "—"}
1096
+ </span>
1097
+ </div>
1098
+ <div class="gs-chips">
1099
+ <span class="gs-chip">
1100
+ {status()?.dirty
1101
+ ? ctx.t("git.changes", { count: status()?.changes ?? 0 })
1102
+ : ctx.t("git.clean")}
1103
+ </span>
1104
+ <Show when={(status()?.ahead ?? 0) > 0}>
1105
+ <span class="gs-chip">{ctx.t("git.ahead", { count: status()?.ahead ?? 0 })}</span>
1106
+ </Show>
1107
+ <Show when={(status()?.behind ?? 0) > 0}>
1108
+ <span class="gs-chip">{ctx.t("git.behind", { count: status()?.behind ?? 0 })}</span>
1109
+ </Show>
1110
+ <Show when={status()?.upstream}>
1111
+ <span class="gs-chip">{status()?.upstream}</span>
1112
+ </Show>
1113
+ <Show when={issues().length > 0}>
1114
+ <span class="gs-chip">{ctx.t("git.issues", { count: issues().length })}</span>
1115
+ </Show>
1116
+ </div>
1117
+ </div>
1118
+
1119
+ <div class="gs-tabs">
1120
+ <ui.Button
1121
+ class="gs-tab"
1122
+ size="small"
1123
+ variant={tab() === "branches" ? "contrast" : "ghost"}
1124
+ onClick={() => setTab("branches")}
1125
+ >
1126
+ {ctx.t("git.tab.branches")}
1127
+ </ui.Button>
1128
+ <ui.Button
1129
+ class="gs-tab"
1130
+ size="small"
1131
+ variant={tab() === "commits" ? "contrast" : "ghost"}
1132
+ onClick={() => setTab("commits")}
1133
+ >
1134
+ {ctx.t("git.tab.commits")}
1135
+ </ui.Button>
1136
+ <ui.Button
1137
+ class="gs-tab"
1138
+ size="small"
1139
+ variant={tab() === "pulls" ? "contrast" : "ghost"}
1140
+ onClick={() => setTab("pulls")}
1141
+ >
1142
+ {ctx.t("git.tab.pulls")}
1143
+ </ui.Button>
1144
+ <ui.Button
1145
+ class="gs-tab"
1146
+ size="small"
1147
+ variant={tab() === "issues" ? "contrast" : "ghost"}
1148
+ onClick={() => setTab("issues")}
1149
+ >
1150
+ {ctx.t("git.tab.issues")}
1151
+ </ui.Button>
1152
+ <ui.Button
1153
+ class="gs-tab"
1154
+ size="small"
1155
+ variant={tab() === "files" ? "contrast" : "ghost"}
1156
+ onClick={() => setTab("files")}
1157
+ >
1158
+ {ctx.t("git.tab.files")}
1159
+ </ui.Button>
1160
+ </div>
1161
+
1162
+ <div class="gs-toolbar">
1163
+ <ui.Tooltip value={ctx.t("git.refresh")}>
1164
+ <ui.IconButton
1165
+ icon="outline-rotate-clockwise"
1166
+ label={ctx.t("git.refresh")}
1167
+ size="small"
1168
+ busy={busy()}
1169
+ onClick={() => void load()}
1170
+ />
1171
+ </ui.Tooltip>
1172
+ <ui.Button size="small" busy={busy()} onClick={() => void act("push")}>
1173
+ {ctx.t("git.push")}
1174
+ </ui.Button>
1175
+ <ui.Button size="small" busy={busy()} onClick={() => void act("pull")}>
1176
+ {ctx.t("git.pull")}
1177
+ </ui.Button>
1178
+ <ui.Button size="small" busy={busy()} onClick={() => void act("commit")}>
1179
+ {ctx.t("git.commit")}
1180
+ </ui.Button>
1181
+ <ui.Button size="small" busy={busy()} onClick={() => void act("pr")}>
1182
+ {ctx.t("git.pr")}
1183
+ </ui.Button>
1184
+ <ui.Tooltip value={ctx.t("git.branch.create")}>
1185
+ <ui.IconButton
1186
+ icon="branch-out"
1187
+ label={ctx.t("git.branch.create")}
1188
+ size="small"
1189
+ busy={busy()}
1190
+ onClick={() => void branchAct("create")}
1191
+ />
1192
+ </ui.Tooltip>
1193
+ </div>
1194
+
1195
+ <Show when={status()} fallback={<div class="gs-empty">{ctx.t("git.noRepo")}</div>}>
1196
+ <Show when={tab() !== "files"} fallback={<FilesPane />}>
1197
+ <div class="gs-scroll">
1198
+ <Show when={tab() === "branches"}>
1199
+ <ui.TextInput
1200
+ label={ctx.t("git.filter")}
1201
+ placeholder={ctx.t("git.filter.placeholder")}
1202
+ type="search"
1203
+ value={filter()}
1204
+ onInput={setFilter}
1205
+ />
1206
+ <Show
1207
+ when={filteredBranches().length > 0}
1208
+ fallback={<div class="gs-empty">{ctx.t("git.branches.empty")}</div>}
1209
+ >
1210
+ <For each={filteredBranches()}>
1211
+ {(branch) => (
1212
+ <div class="gs-row">
1213
+ <ui.Icon name={branch.current ? "check" : "branch"} size="small" />
1214
+ <div class="gs-row-main">
1215
+ <div class="gs-name">{branch.name}</div>
1216
+ <div class="gs-sub">{branch.subject || branch.hash}</div>
1217
+ </div>
1218
+ <div class="gs-chips">
1219
+ <Show when={branch.ahead > 0}>
1220
+ <span class="gs-chip">{ctx.t("git.ahead", { count: branch.ahead })}</span>
1221
+ </Show>
1222
+ <Show when={branch.behind > 0}>
1223
+ <span class="gs-chip">{ctx.t("git.behind", { count: branch.behind })}</span>
1224
+ </Show>
1225
+ </div>
1226
+ <Show when={!branch.current}>
1227
+ <div class="gs-actions" onClick={(event) => event.stopPropagation()}>
1228
+ <ui.Tooltip value={ctx.t("git.branch.checkout")}>
1229
+ <ui.IconButton
1230
+ icon="arrow-right"
1231
+ label={ctx.t("git.branch.checkout")}
1232
+ size="small"
1233
+ busy={busy()}
1234
+ onClick={() => void branchAct("checkout", branch.name)}
1235
+ />
1236
+ </ui.Tooltip>
1237
+ <ui.Tooltip value={ctx.t("git.branch.merge")}>
1238
+ <ui.IconButton
1239
+ icon="branch-out"
1240
+ label={ctx.t("git.branch.merge")}
1241
+ size="small"
1242
+ busy={busy()}
1243
+ onClick={() => void branchAct("merge", branch.name)}
1244
+ />
1245
+ </ui.Tooltip>
1246
+ <ui.Tooltip value={ctx.t("git.branch.delete")}>
1247
+ <ui.IconButton
1248
+ icon="close"
1249
+ label={ctx.t("git.branch.delete")}
1250
+ size="small"
1251
+ busy={busy()}
1252
+ onClick={() => void branchAct("delete", branch.name)}
1253
+ />
1254
+ </ui.Tooltip>
1255
+ </div>
1256
+ </Show>
1257
+ </div>
1258
+ )}
1259
+ </For>
1260
+ </Show>
1261
+ </Show>
1262
+
1263
+ <Show when={tab() === "commits"}>
1264
+ <Show
1265
+ when={commits().length > 0}
1266
+ fallback={<div class="gs-empty">{ctx.t("git.commits.empty")}</div>}
1267
+ >
1268
+ <For each={commits()}>
1269
+ {(commit) => (
1270
+ <>
1271
+ <div
1272
+ class="gs-row"
1273
+ onClick={() => setExpanded(expanded() === commit.hash ? undefined : commit.hash)}
1274
+ >
1275
+ <span class="gs-mono">{commit.short}</span>
1276
+ <div class="gs-row-main">
1277
+ <div class="gs-name">{commit.subject}</div>
1278
+ <div class="gs-detail">
1279
+ <span>{commit.author}</span>
1280
+ <span>·</span>
1281
+ <span>{relative(commit.date)}</span>
1282
+ </div>
1283
+ </div>
1284
+ <span class="gs-chip">
1285
+ {commit.files.length} {ctx.t("git.files")}
1286
+ </span>
1287
+ </div>
1288
+ <Show when={expanded() === commit.hash && commit.files.length > 0}>
1289
+ <div class="gs-files">
1290
+ <For each={commit.files}>{(file) => <div class="gs-file">{file}</div>}</For>
1291
+ </div>
1292
+ </Show>
1293
+ </>
1294
+ )}
1295
+ </For>
1296
+ </Show>
1297
+ </Show>
1298
+
1299
+ <Show when={tab() === "pulls"}>
1300
+ <Show
1301
+ when={pulls().length > 0}
1302
+ fallback={<div class="gs-empty">{ctx.t("git.pulls.empty")}</div>}
1303
+ >
1304
+ <For each={pulls()}>
1305
+ {(pull) => (
1306
+ <div class="gs-row" onClick={() => void ctx.system.openExternal(pull.url)}>
1307
+ <ui.Icon
1308
+ name={
1309
+ pull.checks === "success"
1310
+ ? "check"
1311
+ : pull.checks === "failure"
1312
+ ? "circle-exclamation"
1313
+ : "clock"
1314
+ }
1315
+ size="small"
1316
+ />
1317
+ <div class="gs-row-main">
1318
+ <div class="gs-name">#{pull.number} {pull.title}</div>
1319
+ <div class="gs-sub">{pull.branch}</div>
1320
+ </div>
1321
+ <ui.Icon name="arrow-right" size="small" />
1322
+ </div>
1323
+ )}
1324
+ </For>
1325
+ </Show>
1326
+ </Show>
1327
+
1328
+ <Show when={tab() === "issues"}>
1329
+ <Show
1330
+ when={issues().length > 0}
1331
+ fallback={<div class="gs-empty">{ctx.t("git.issues.empty")}</div>}
1332
+ >
1333
+ <For each={issues()}>
1334
+ {(issue) => (
1335
+ <div class="gs-row" onClick={() => void ctx.system.openExternal(issue.url)}>
1336
+ <ui.Icon name="bullet-list" size="small" />
1337
+ <div class="gs-row-main">
1338
+ <div class="gs-name">#{issue.number} {issue.title}</div>
1339
+ <div class="gs-sub">
1340
+ {[issue.author, relative(issue.date)].filter(Boolean).join(" · ")}
1341
+ </div>
1342
+ <Show when={issue.labels.length > 0}>
1343
+ <div class="gs-chips">
1344
+ <For each={issue.labels.slice(0, 3)}>
1345
+ {(label) => <span class="gs-chip">{label}</span>}
1346
+ </For>
1347
+ </div>
1348
+ </Show>
1349
+ </div>
1350
+ <Show when={issue.comments > 0}>
1351
+ <span class="gs-chip">{issue.comments}</span>
1352
+ </Show>
1353
+ <ui.Icon name="arrow-right" size="small" />
1354
+ </div>
1355
+ )}
1356
+ </For>
1357
+ </Show>
1358
+ </Show>
1359
+ </div>
1360
+ </Show>
1361
+ </Show>
1362
+ </div>
1363
+ ),
1364
+ })
1365
+
1366
+ ctx.add(MenuItem, () => {
1367
+ const session = ctx.sessions.current()
1368
+ return {
1369
+ menu: "session.panel",
1370
+ id: "open",
1371
+ title: ctx.t("git.menu.open"),
1372
+ icon: "github",
1373
+ opened: !!session && ctx.layout.state(panelKey(), session) !== "closed",
1374
+ run: () => openPanel(),
1375
+ } satisfies SessionPanelMenuItem
1376
+ })
1377
+
1378
+ ctx.add(Slot, {
1379
+ at: "session.panel.end",
1380
+ render: () => (
1381
+ <ui.IconButton icon="github" label={ctx.t("git.menu.open")} onClick={() => openPanel()} />
1382
+ ),
1383
+ })
1384
+
1385
+ ctx.add(Slot, {
1386
+ at: "session.location.menu",
1387
+ render: () => (
1388
+ <Show when={status()}>
1389
+ {(current) => (
1390
+ <ui.MenuItem
1391
+ label={`${ctx.t("git.branch")}: ${current().branch}${current().dirty ? " •" : ""}`}
1392
+ icon="github"
1393
+ onSelect={() => openPanel()}
1394
+ />
1395
+ )}
1396
+ </Show>
1397
+ ),
1398
+ })
1399
+
1400
+ ctx.add(ComposerPill, {
1401
+ id: "pulls",
1402
+ show: (): ComposerPillView | undefined => {
1403
+ const list = pulls()
1404
+ if (!list.length) return undefined
1405
+ return {
1406
+ label: ctx.t("git.pulls", { count: list.length }),
1407
+ icon: "github",
1408
+ title: ctx.t("git.pulls", { count: list.length }),
1409
+ rows: list.map((pull) => ({
1410
+ id: String(pull.number),
1411
+ label: `#${pull.number} ${pull.title}`,
1412
+ detail: pull.branch,
1413
+ tone:
1414
+ pull.checks === "success"
1415
+ ? "success"
1416
+ : pull.checks === "failure"
1417
+ ? "danger"
1418
+ : "warning",
1419
+ run: () => void ctx.system.openExternal(pull.url),
1420
+ })),
1421
+ run: () => openPanel(),
1422
+ }
1423
+ },
1424
+ })
1425
+
1426
+ ctx.add(Command, () => ({
1427
+ id: "open",
1428
+ title: ctx.t("git.command.open"),
1429
+ run: () => openPanel(),
1430
+ }))
1431
+
1432
+ ctx.add(Command, () => ({
1433
+ id: "push",
1434
+ title: ctx.t("git.command.push"),
1435
+ run: () => void act("push"),
1436
+ }))
1437
+
1438
+ ctx.add(Command, () => ({
1439
+ id: "pull",
1440
+ title: ctx.t("git.command.pull"),
1441
+ run: () => void act("pull"),
1442
+ }))
1443
+
1444
+ ctx.add(Command, () => ({
1445
+ id: "pr",
1446
+ title: ctx.t("git.command.pr"),
1447
+ run: () => void act("pr"),
1448
+ }))
1449
+
1450
+ ctx.add(Command, () => ({
1451
+ id: "commit",
1452
+ title: ctx.t("git.command.commit"),
1453
+ run: () => void act("commit"),
1454
+ }))
1455
+
1456
+ ctx.add(Command, () => ({
1457
+ id: "commitSelected",
1458
+ title: ctx.t("git.command.commitSelected"),
1459
+ run: () => void actSelected(),
1460
+ }))
1461
+ },
1462
+ })