@@ -243,6 +243,24 @@ export async function commit(root: string, message: string): Promise<void> {
|
||||
await git(root, ['commit', '-m', message])
|
||||
}
|
||||
|
||||
/**
|
||||
* Push the current branch to its remote. If the branch has no upstream yet,
|
||||
* retry with `-u origin <branch>` so the first push also sets tracking.
|
||||
* Returns a concise one-line summary for the toast (git writes progress to
|
||||
* stderr, so we pull the summary from there).
|
||||
*/
|
||||
export async function push(root: string): Promise<{ ok: boolean; message: string }> {
|
||||
let res = await runGit(root, ['push'])
|
||||
if (res.code !== 0 && /no upstream branch|set-upstream/i.test(res.stderr)) {
|
||||
const branch = (await runGit(root, ['rev-parse', '--abbrev-ref', 'HEAD'])).stdout.trim()
|
||||
if (branch && branch !== 'HEAD') res = await runGit(root, ['push', '-u', 'origin', branch])
|
||||
}
|
||||
const lines = (res.stderr || res.stdout).trim().split('\n').map((l) => l.trim()).filter(Boolean)
|
||||
if (res.code !== 0) return { ok: false, message: lines.pop() || 'push failed' }
|
||||
const summary = lines.find((l) => /->|up-to-date|new branch/i.test(l)) || lines.pop() || 'Pushed'
|
||||
return { ok: true, message: summary }
|
||||
}
|
||||
|
||||
/**
|
||||
* Discard working-tree changes for each path:
|
||||
* - exists in HEAD → restore index + worktree to the last commit
|
||||
|
||||
+2
-1
@@ -5,7 +5,7 @@ import { app, dialog, shell, BrowserWindow, ipcMain, Menu } from 'electron'
|
||||
import { watch, type FSWatcher } from 'chokidar'
|
||||
import { addRecentProject, getName, getRecentProjects, getRoot, openDialog, setRoot } from './project'
|
||||
import { createProjectDir, createProjectFile, deleteProjectFile, readAll, readDirChildren, readProjectFile, readTree, writeProjectFile } from './fs-service'
|
||||
import { commit, discard, load, stage, unstage } from './git-service'
|
||||
import { commit, discard, load, push, stage, unstage } from './git-service'
|
||||
import { createPty, killAllPtys, killPty, ptyAvailable, resizePty, writePty } from './pty-service'
|
||||
import { getConfig, getRecent, getThemeCss, resolveConfig, setRecent } from './config'
|
||||
import { listFiles, searchContent } from './search-service'
|
||||
@@ -215,6 +215,7 @@ function registerIpc(): void {
|
||||
ipcMain.handle('git:stage', (_e, paths: string[]) => { const r = getRoot(); if (r) return stage(r, paths) })
|
||||
ipcMain.handle('git:unstage', (_e, paths: string[]) => { const r = getRoot(); if (r) return unstage(r, paths) })
|
||||
ipcMain.handle('git:commit', (_e, message: string) => { const r = getRoot(); if (r) return commit(r, message) })
|
||||
ipcMain.handle('git:push', () => { const r = getRoot(); return r ? push(r) : { ok: false, message: 'No project open' } })
|
||||
ipcMain.handle('git:discard', (_e, paths: string[]) => { const r = getRoot(); if (r) return discard(r, paths) })
|
||||
|
||||
ipcMain.handle('pty:available', () => ptyAvailable())
|
||||
|
||||
Reference in New Issue
Block a user