@@ -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
|
||||
|
||||
Reference in New Issue
Block a user