Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

feat(scm): backend git actions — merge/rebase/branch/fetch/stash/revert + IPC

enesa6abcef9d919
diff --git a/src/main/git-service.ts b/src/main/git-service.ts
index fb510fa88..c8270a99d 100644
--- a/src/main/git-service.ts
+++ b/src/main/git-service.ts
@@ -177,6 +177,25 @@ export class GitService {
ipcMain.handle(IPC.gitRemoteCommitUrl, (_e, cwd: string, sha: string) =>
this.remoteCommitUrl(cwd, sha)
)
+ ipcMain.handle(IPC.gitMerge, (_e, cwd: string, ref: string) => this.merge(cwd, ref))
+ ipcMain.handle(IPC.gitRebase, (_e, cwd: string, onto: string) => this.rebase(cwd, onto))
+ ipcMain.handle(IPC.gitDeleteBranch, (_e, cwd: string, name: string, force: boolean) =>
+ this.deleteBranch(cwd, name, force)
+ )
+ ipcMain.handle(IPC.gitRenameBranch, (_e, cwd: string, newName: string) =>
+ this.renameBranch(cwd, newName)
+ )
+ ipcMain.handle(IPC.gitFetch, (_e, cwd: string) => this.fetch(cwd))
+ ipcMain.handle(IPC.gitForcePush, (_e, cwd: string) => this.forcePush(cwd))
+ ipcMain.handle(IPC.gitStashPush, (_e, cwd: string) => this.stashPush(cwd))
+ ipcMain.handle(IPC.gitStashPop, (_e, cwd: string) => this.stashPop(cwd))
+ ipcMain.handle(IPC.gitRevert, (_e, cwd: string, oid: string) => this.revert(cwd, oid))
+ ipcMain.handle(IPC.gitBranchAt, (_e, cwd: string, name: string, oid: string) =>
+ this.branchAt(cwd, name, oid)
+ )
+ ipcMain.handle(IPC.gitCheckoutCommit, (_e, cwd: string, oid: string) =>
+ this.checkoutCommit(cwd, oid)
+ )
}
async status(cwd: string): Promise<GitStatus> {
@@ -383,6 +402,69 @@ export class GitService {
return r.ok ? { ok: true, message: `Created ${name.trim()}.` } : fail(r)
}
+ async merge(cwd: string, ref: string): Promise<GitResult> {
+ if (!isValidRef(ref)) return { ok: false, message: 'Invalid branch name.' }
+ const r = await git(cwd, ['merge', ref.trim()])
+ return r.ok ? { ok: true, message: r.out || `Merged ${ref.trim()}.` } : fail(r)
+ }
+
+ async rebase(cwd: string, onto: string): Promise<GitResult> {
+ if (!isValidRef(onto)) return { ok: false, message: 'Invalid branch name.' }
+ const r = await git(cwd, ['rebase', onto.trim()])
+ return r.ok ? { ok: true, message: r.out || `Rebased onto ${onto.trim()}.` } : fail(r)
+ }
+
+ async deleteBranch(cwd: string, name: string, force: boolean): Promise<GitResult> {
+ if (!isValidRef(name)) return { ok: false, message: 'Invalid branch name.' }
+ const r = await git(cwd, ['branch', force ? '-D' : '-d', name.trim()])
+ return r.ok ? { ok: true, message: `Deleted ${name.trim()}.` } : fail(r)
+ }
+
+ async renameBranch(cwd: string, newName: string): Promise<GitResult> {
+ if (!isValidRef(newName)) return { ok: false, message: 'Invalid branch name.' }
+ const r = await git(cwd, ['branch', '-m', newName.trim()])
+ return r.ok ? { ok: true, message: `Renamed to ${newName.trim()}.` } : fail(r)
+ }
+
+ async fetch(cwd: string): Promise<GitResult> {
+ const r = await git(cwd, ['fetch', '--all', '--prune'])
+ return r.ok ? { ok: true, message: r.out || 'Fetched.' } : fail(r)
+ }
+
+ async forcePush(cwd: string): Promise<GitResult> {
+ const r = await git(cwd, ['push', '--force-with-lease'])
+ return r.ok ? { ok: true, message: 'Force-pushed.' } : fail(r)
+ }
+
+ async stashPush(cwd: string): Promise<GitResult> {
+ const r = await git(cwd, ['stash', 'push', '-u'])
+ return r.ok ? { ok: true, message: r.out || 'Stashed.' } : fail(r)
+ }
+
+ async stashPop(cwd: string): Promise<GitResult> {
+ const r = await git(cwd, ['stash', 'pop'])
+ return r.ok ? { ok: true, message: r.out || 'Popped stash.' } : fail(r)
+ }
+
+ async revert(cwd: string, oid: string): Promise<GitResult> {
+ if (!/^[0-9a-fA-F]{7,64}$/.test(oid)) return { ok: false, message: 'Invalid commit.' }
+ const r = await git(cwd, ['revert', '--no-edit', oid])
+ return r.ok ? { ok: true, message: r.out || 'Reverted.' } : fail(r)
+ }
+
+ async branchAt(cwd: string, name: string, oid: string): Promise<GitResult> {
+ if (!isValidRef(name)) return { ok: false, message: 'Invalid branch name.' }
+ if (!/^[0-9a-fA-F]{7,64}$/.test(oid)) return { ok: false, message: 'Invalid commit.' }
+ const r = await git(cwd, ['switch', '-c', name.trim(), oid])
+ return r.ok ? { ok: true, message: `Created ${name.trim()}.` } : fail(r)
+ }
+
+ async checkoutCommit(cwd: string, oid: string): Promise<GitResult> {
+ if (!/^[0-9a-fA-F]{7,64}$/.test(oid)) return { ok: false, message: 'Invalid commit.' }
+ const r = await git(cwd, ['checkout', '--detach', oid])
+ return r.ok ? { ok: true, message: `Checked out ${oid.slice(0, 7)} (detached).` } : fail(r)
+ }
+
/** Clone a repo into parentDir; returns the cloned folder path in `message` on success. */
async clone(parentDir: string, url: string): Promise<GitResult> {
if (!parentDir || !url.trim()) return { ok: false, message: 'Folder and URL are required.' }
diff --git a/src/preload/index.ts b/src/preload/index.ts
index 1c016892d..763cb21a9 100644
--- a/src/preload/index.ts
+++ b/src/preload/index.ts
@@ -94,7 +94,18 @@ const api: NodeTerminalApi = {
generateMessage: (cwd) => ipcRenderer.invoke(IPC.commitGenerate, cwd),
history: (cwd, options) => ipcRenderer.invoke(IPC.gitHistory, cwd, options),
commitFiles: (cwd, oid) => ipcRenderer.invoke(IPC.gitCommitFiles, cwd, oid),
- remoteCommitUrl: (cwd, sha) => ipcRenderer.invoke(IPC.gitRemoteCommitUrl, cwd, sha)
+ remoteCommitUrl: (cwd, sha) => ipcRenderer.invoke(IPC.gitRemoteCommitUrl, cwd, sha),
+ merge: (cwd, ref) => ipcRenderer.invoke(IPC.gitMerge, cwd, ref),
+ rebase: (cwd, onto) => ipcRenderer.invoke(IPC.gitRebase, cwd, onto),
+ deleteBranch: (cwd, name, force) => ipcRenderer.invoke(IPC.gitDeleteBranch, cwd, name, force),
+ renameBranch: (cwd, newName) => ipcRenderer.invoke(IPC.gitRenameBranch, cwd, newName),
+ fetch: (cwd) => ipcRenderer.invoke(IPC.gitFetch, cwd),
+ forcePush: (cwd) => ipcRenderer.invoke(IPC.gitForcePush, cwd),
+ stashPush: (cwd) => ipcRenderer.invoke(IPC.gitStashPush, cwd),
+ stashPop: (cwd) => ipcRenderer.invoke(IPC.gitStashPop, cwd),
+ revert: (cwd, oid) => ipcRenderer.invoke(IPC.gitRevert, cwd, oid),
+ branchAt: (cwd, name, oid) => ipcRenderer.invoke(IPC.gitBranchAt, cwd, name, oid),
+ checkoutCommit: (cwd, oid) => ipcRenderer.invoke(IPC.gitCheckoutCommit, cwd, oid)
},
clipboard: {
writeText: (text: string) => clipboard.writeText(text)
diff --git a/src/shared/ipc.ts b/src/shared/ipc.ts
index 0606391cc..56815f290 100644
--- a/src/shared/ipc.ts
+++ b/src/shared/ipc.ts
@@ -76,6 +76,17 @@ export const IPC = {
gitHistory: 'git:history',
gitCommitFiles: 'git:commit-files',
gitRemoteCommitUrl: 'git:remote-commit-url',
+ gitMerge: 'git:merge',
+ gitRebase: 'git:rebase',
+ gitDeleteBranch: 'git:delete-branch',
+ gitRenameBranch: 'git:rename-branch',
+ gitFetch: 'git:fetch',
+ gitForcePush: 'git:force-push',
+ gitStashPush: 'git:stash-push',
+ gitStashPop: 'git:stash-pop',
+ gitRevert: 'git:revert',
+ gitBranchAt: 'git:branch-at',
+ gitCheckoutCommit: 'git:checkout-commit',
shellOpenExternal: 'shell:open-external',
commitGenerate: 'commit:generate',
remoteHostStart: 'remote:host:start',
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 3d372d3f3..476284772 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -336,6 +336,28 @@ export interface GitApi {
commitFiles(cwd: string, oid: string): Promise<GitFileChange[]>
/** Remote web URL for a commit sha, or null if it can't be derived. */
remoteCommitUrl(cwd: string, sha: string): Promise<string | null>
+ /** Merge a branch into the current branch. */
+ merge(cwd: string, ref: string): Promise<GitResult>
+ /** Rebase the current branch onto another. */
+ rebase(cwd: string, onto: string): Promise<GitResult>
+ /** Delete a branch (force = -D, for unmerged). */
+ deleteBranch(cwd: string, name: string, force: boolean): Promise<GitResult>
+ /** Rename the current branch. */
+ renameBranch(cwd: string, newName: string): Promise<GitResult>
+ /** Fetch all remotes and prune. */
+ fetch(cwd: string): Promise<GitResult>
+ /** Push with --force-with-lease. */
+ forcePush(cwd: string): Promise<GitResult>
+ /** Stash uncommitted changes (incl. untracked). */
+ stashPush(cwd: string): Promise<GitResult>
+ /** Pop the latest stash. */
+ stashPop(cwd: string): Promise<GitResult>
+ /** Revert a commit (--no-edit). */
+ revert(cwd: string, oid: string): Promise<GitResult>
+ /** Create + switch to a new branch at a commit. */
+ branchAt(cwd: string, name: string, oid: string): Promise<GitResult>
+ /** Checkout a commit (detached HEAD). */
+ checkoutCommit(cwd: string, oid: string): Promise<GitResult>
}
export interface UpdateInfo {