Official
git
Built-in git UI (JavaScript UI plugin).
The app opens the listing; nothing installs until an agent in your Plugins workspace has read the files and you enable the plugin. In a terminal: dvg install divergence/git@0.3.0
Permissions in 0.3.0
Files
views/controls.tsx5.6 KB
// The commit box (message field, primary action), branch picker and repository menu trees.
// HTM whitespace is significant; keep these templates out of Prettier's HTML formatter.
import type { GitStatus } from "divergence";
import type { EffectViewContext } from "divergence/effect";
import type { Git } from "../controller.ts";
import { branchOptions, MENU, onBranch, primaryAction } from "../status.ts";
import type { Groups } from "../status.ts";
import { column, fill, row, panelRow, menuCard } from "./layout.ts";
export function controls(ctx: EffectViewContext<object>, actions: Git["Service"]) {
const { state } = actions;
// The message box. Commit with it empty has an agent write the message; typing stays open
// while the agent writes, and replaces what it was writing.
function messageField(status: GitStatus) {
const branch = status.branch ? `"${status.branch}"` : "this branch";
return (
<input id="git-message" multiline submitOnEnter value={state.message} placeholder={state.writing ? "Writing a commit message…" : `Message (⏎ to commit on ${branch})`} onChange={(e: { value: string }) => {
ctx.run(actions.typed(e.value));
ctx.update();
}} onSubmit={() => ctx.run(actions.commit())} />
);
}
function primaryButton(status: GitStatus, total: number) {
const disabled = !!state.busy;
if (primaryAction(status, total) === "commit") {
// An empty box asks an agent for a message, so only an agent already writing one holds the buttons.
const waiting = disabled || (state.writing && !state.message.trim());
const commit = <button id="git-commit" icon="check" label="Commit" variant="accent" disabled={waiting} onClick={() => ctx.run(actions.commit())} />;
if (!onBranch(status)) return commit;
return (
<div {...row} gap="small">
<div {...column} {...fill}>{commit}</div>
<div {...column} {...fill}><button id="git-commit-push" icon="arrow-up" label="Commit and Push" disabled={waiting} onClick={() => ctx.run(actions.commitAndPush())} /></div>
</div>
);
}
if (primaryAction(status, total) === "publish") {
return <button id="git-publish" icon="cloud-upload" label="Publish Branch" variant="accent" disabled={disabled} onClick={() => ctx.run(actions.publish())} />;
}
if (primaryAction(status, total) === "sync") {
const counts = [status.behind ? `${status.behind}↓` : null, status.ahead ? `${status.ahead}↑` : null]
.filter(Boolean)
.join(" ");
return <button id="git-sync" icon="refresh-cw" label={`Sync Changes ${counts}`} variant="accent" disabled={disabled} onClick={() => ctx.run(actions.sync())} />;
}
return <button id="git-commit" icon="check" label="Commit" variant="accent" disabled />;
}
function branchPicker(status: GitStatus) {
const { query: q, shown, create } = branchOptions(state.branches, state.branchQuery);
const items = [
...(create
? [
{
id: "git-branch-create",
label: `Create branch "${q}"`,
icon: "plus",
onClick: () => ctx.run(actions.checkout(q, true)),
},
]
: []),
...shown.map((b) => ({
id: `git-branch-${b}`,
label: b,
icon: "git-branch",
selected: b === status.branch,
onClick: () => ctx.run(actions.checkout(b, false)),
})),
];
return (
<popover id="git-branch-popover" open={state.branchOpen} align="start" width={280} onDismiss={() => {
state.branchOpen = false;
ctx.update();
}}>
<div {...panelRow} id="git-branch" onPress={() => ctx.run(actions.openBranches())}>
<icon name="git-branch" small tone="muted" />
<text style="body" size="xs" tone="muted" truncate>{status.branch ?? "(no branch)"}</text>
</div>
<div {...menuCard}>
<input id="git-branch-query" value={state.branchQuery} placeholder="Switch to or create a branch" onChange={(e: { value: string }) => {
state.branchQuery = e.value;
ctx.update();
}} onSubmit={() => {
if (create) ctx.run(actions.checkout(q, true));
else if (shown[0]) ctx.run(actions.checkout(shown[0], false));
}} />
<div {...column} gap="small" padding="small" maxHeight={280} overflowY="scroll">
{items.length ? <list id="git-branch-list" items={items} /> : <text style="muted">No branches.</text>}
</div>
</div>
</popover>
);
}
function menu(status: GitStatus, g: Groups) {
const items = MENU.map((item) => ({
id: `git-menu-${item.action}`,
label: item.label,
icon: item.icon,
onClick: () => {
state.menuOpen = false;
ctx.update();
ctx.run(actions.menuAction(item.action, status, g));
},
}));
return (
<popover id="git-menu" open={state.menuOpen} align="end" width={220} onDismiss={() => {
state.menuOpen = false;
ctx.update();
}}>
<button id="git-more" icon="ellipsis" variant="ghost" small tooltip="More actions" disabled={!!state.busy} onClick={() => {
state.menuOpen = !state.menuOpen;
ctx.update();
}} />
<div {...menuCard}><list id="git-menu-list" items={items} /></div>
</popover>
);
}
return { messageField, primaryButton, branchPicker, menu };
}
No comments yet.