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.

fix(worktree): the merge confirm only promises a push it can actually make — and never ticks it

enes5ed141b55d3d
diff --git a/src/core/git-service.ts b/src/core/git-service.ts
index b3127cec2..85bfcf395 100644
--- a/src/core/git-service.ts
+++ b/src/core/git-service.ts
@@ -258,6 +258,7 @@ export class GitService {
ahead: 0,
behind: 0,
hasRemote: false,
+ hasOrigin: false,
hasUpstream: false,
ghAvailable: !!GH_PATH,
ghAuthed: false,
@@ -295,6 +296,9 @@ export class GitService {
const hasRemote = !!remotesR.out.trim()
const hasUpstream = upstreamR.ok && !!upstreamR.out.trim()
const originUrl = originR.out.trim()
+ // `hasRemote` is true for ANY remote — a fork whose only remote is `upstream` included. Anything
+ // that pushes to `origin` by name (the worktree merge does) must ask for origin itself.
+ const hasOrigin = originR.ok && !!originUrl
const repoName = originUrl ? parseRepoName(originUrl, path.basename(cwd)) : path.basename(cwd)
let ahead = 0
@@ -340,6 +344,7 @@ export class GitService {
ahead,
behind,
hasRemote,
+ hasOrigin,
hasUpstream,
ghAvailable: !!GH_PATH,
ghAuthed: gh,
diff --git a/src/renderer/canvas/Canvas.tsx b/src/renderer/canvas/Canvas.tsx
index 2b8344ca7..ef38a0457 100644
--- a/src/renderer/canvas/Canvas.tsx
+++ b/src/renderer/canvas/Canvas.tsx
@@ -444,15 +444,14 @@ export function Canvas() {
canDelete: boolean
} | null>(null)
const [deleteFromDisk, setDeleteFromDisk] = useState(false)
- // Group awaiting confirmation to merge its worktree into the base branch. `hasRemote` decides
- // whether the dialog offers (and warns about) the push to origin — a repo with no remote must
+ // Group awaiting confirmation to merge its worktree into the base branch. `hasOrigin` decides
+ // whether the dialog offers (and warns about) the push to origin — a repo with no `origin` must
// never be threatened with a publish that cannot happen.
const [mergeTarget, setMergeTarget] = useState<{
- groupId: string
repoPath: string
branch: string
baseRef: string
- hasRemote: boolean
+ hasOrigin: boolean
} | null>(null)
const [mergePush, setMergePush] = useState(false)
const settings = useSettings((s) => s.settings)
@@ -2184,7 +2183,7 @@ export function Canvas() {
const t = mergeTarget
setMergeTarget(null)
if (!t) return
- const push = t.hasRemote && mergePush
+ const push = t.hasOrigin && mergePush
void window.nodeTerminal.git
.worktreeMerge(t.repoPath, t.branch, t.baseRef, push)
.then((res) => setNotice({ kind: res.ok ? 'info' : 'error', text: res.message }))
@@ -2226,17 +2225,18 @@ export function Canvas() {
// main working tree — AND (if asked) pushes the base branch to origin, which publishes it
// to every teammate. Ask first, and say BOTH of those out loud.
//
- // `hasRemote` comes from the store's status poll (the chip that carries this very button
- // has been polling it), so no extra git IPC is fired here. Unknown → assume no remote:
+ // `hasOrigin` comes from the store's status poll (the chip that carries this very button
+ // has been polling it), so no extra git IPC is fired here. Unknown → assume no origin:
// the merge then does not push, which is the only safe way to be wrong.
- const hasRemote = !!useWorktrees.getState().statusByPath[wt.path]?.hasRemote
- setMergePush(hasRemote) // pushing is the default when a remote exists — but opt-out.
+ const hasOrigin = !!useWorktrees.getState().statusByPath[wt.path]?.hasOrigin
+ // Publishing to other people's machines is a DECISION, not a side effect of merging — and
+ // a push to origin/<base> cannot be politely undone. The box is offered, ticked by nobody.
+ setMergePush(false)
setMergeTarget({
- groupId,
repoPath: wt.repoPath,
branch: wt.branch,
baseRef: wt.baseRef,
- hasRemote
+ hasOrigin
})
break
}
@@ -4575,17 +4575,18 @@ export function Canvas() {
message={
`Merge ${mergeTarget.branch} into ${mergeTarget.baseRef}?\n\n` +
`If ${mergeTarget.baseRef} is checked out somewhere, this merges into that working tree.` +
- (mergeTarget.hasRemote && mergePush
+ (mergeTarget.hasOrigin && mergePush
? `\n\n⚠ ${mergeTarget.baseRef} is also pushed to origin — everyone on the remote gets this merge.`
: '')
}
confirmLabel="Merge"
danger={false}
option={
- // No remote → no push to offer. With a remote, the push stays the default (it is what
- // the user almost always wants after merging a finished worktree) but is now visible
- // and switch-offable, instead of happening silently behind a dialog that never said so.
- mergeTarget.hasRemote
+ // No `origin` → no push to offer (the push is `git push origin <base>`; a fork whose
+ // only remote is `upstream` would be promised a publish that then fails). With an
+ // origin, the push is offered UNTICKED: it lands on other people's machines and cannot
+ // be politely undone, so it is the user's decision, never a side effect of merging.
+ mergeTarget.hasOrigin
? {
label: `Also push ${mergeTarget.baseRef} to origin`,
checked: mergePush,
diff --git a/src/renderer/state/worktrees.test.ts b/src/renderer/state/worktrees.test.ts
index ece1e130c..a365da68d 100644
--- a/src/renderer/state/worktrees.test.ts
+++ b/src/renderer/state/worktrees.test.ts
@@ -142,7 +142,7 @@ describe('useWorktrees.refreshStatus', () => {
dirty: 3,
ahead: 3,
behind: 1,
- hasRemote: false
+ hasOrigin: false
})
})
@@ -256,15 +256,23 @@ describe('useWorktrees.refreshStatus', () => {
})
// The merge confirm has to tell the user whether merging also PUBLISHES to origin, and it reads
- // that fact from here (the store is the only caller of the status IPC).
- it('carries hasRemote into the chip status (the merge confirm reads it)', async () => {
- gitMock.status.mockResolvedValue(okStatus({ hasRemote: true }))
+ // that fact from here (the store is the only caller of the status IPC). It is `hasOrigin`, not
+ // `hasRemote`: the push is `git push origin <base>`, which a fork with only `upstream` cannot do.
+ it('carries hasOrigin into the chip status (the merge confirm reads it)', async () => {
+ gitMock.status.mockResolvedValue(okStatus({ hasRemote: true, hasOrigin: true }))
await useWorktrees.getState().refreshStatus('/wt/feat')
- expect(useWorktrees.getState().statusByPath['/wt/feat'].hasRemote).toBe(true)
+ expect(useWorktrees.getState().statusByPath['/wt/feat'].hasOrigin).toBe(true)
})
+ it('does not call a fork with only an `upstream` remote pushable to origin', async () => {
+ gitMock.status.mockResolvedValue(okStatus({ hasRemote: true, hasOrigin: false }))
+
+ await useWorktrees.getState().refreshStatus('/wt/feat')
+
+ expect(useWorktrees.getState().statusByPath['/wt/feat'].hasOrigin).toBe(false)
+ })
// `refresh()` runs on a project switch, on binding another worktree, on deleting a node, on
// ungrouping. If it SET `staleGroupIds` from reconcile alone, every one of those would erase a
@@ -368,7 +376,7 @@ describe('useWorktrees.refreshStatus', () => {
dirty: 0,
ahead: 2,
behind: 0,
- hasRemote: false
+ hasOrigin: false
})
})
diff --git a/src/renderer/state/worktrees.ts b/src/renderer/state/worktrees.ts
index f7c6bbc65..31a6d27d8 100644
--- a/src/renderer/state/worktrees.ts
+++ b/src/renderer/state/worktrees.ts
@@ -12,9 +12,11 @@ export interface WorktreeStatus {
dirty: number
ahead: number
behind: number
- /** The repo has a remote — i.e. a merge CAN publish the base branch to origin. The merge confirm
- * reads this to say so (and to not threaten a push that could never happen). */
- hasRemote: boolean
+ /** A remote named `origin` exists — i.e. a merge CAN publish the base branch to origin. The merge
+ * confirm reads this to offer the push (and to not threaten one that could never happen). It is
+ * deliberately NOT `hasRemote` ("any remote"): the push is hardcoded to `origin`, so a fork whose
+ * only remote is `upstream` would be shown a push it cannot perform. */
+ hasOrigin: boolean
}
/** The chip re-renders constantly; without this, every render would spawn a `git status`. */
@@ -175,7 +177,7 @@ export const useWorktrees = create<WorktreesState>((set) => ({
dirty: status.staged.length + status.changes.length,
ahead: status.ahead,
behind: status.behind,
- hasRemote: !!status.hasRemote
+ hasOrigin: !!status.hasOrigin
}
}
}))
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 1e1b5463c..ba3663eed 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -520,8 +520,11 @@ export interface GitStatus {
branches: string[]
ahead: number
behind: number
- /** The repo has at least one remote (origin). */
+ /** The repo has at least one remote — which may well not be named `origin` (a fork can have only
+ * `upstream`). Never read this to decide whether a `git push origin …` can work: use `hasOrigin`. */
hasRemote: boolean
+ /** A remote literally named `origin` exists — i.e. a hardcoded `push origin <ref>` has a target. */
+ hasOrigin: boolean
/** The current branch has an upstream tracking ref (i.e. it has been published). */
hasUpstream: boolean
ghAvailable: boolean
diff --git a/src/shared/worktree-ops.test.ts b/src/shared/worktree-ops.test.ts
index 4baf9f0c5..a13300d96 100644
--- a/src/shared/worktree-ops.test.ts
+++ b/src/shared/worktree-ops.test.ts
@@ -150,6 +150,26 @@ describe('worktreeMerge', () => {
expect(calls.some((c) => c[0] === 'push')).toBe(false)
expect(r.message).not.toMatch(/push/i)
})
+ // A fork's only remote is often `upstream`. The push is `git push origin <base>`, so "a remote
+ // exists" is not the question — `origin` itself has to exist, or the promise cannot be kept.
+ it('does not push when the only remote is not origin (a fork with just `upstream`)', async () => {
+ const list = 'worktree /wt/x\nHEAD aaa\nbranch refs/heads/feature/x\n'
+ const { git, calls } = fakeGit({ 'worktree list --porcelain': ok(list), remote: ok('upstream\n') })
+ const r = await worktreeMerge(git, '/repo', 'feature/x', 'main', true)
+ expect(r.ok).toBe(true)
+ expect(calls.some((c) => c[0] === 'push')).toBe(false)
+ expect(r.message).not.toMatch(/push/i)
+ })
+ it('pushes when origin is one of several remotes', async () => {
+ const list = 'worktree /wt/x\nHEAD aaa\nbranch refs/heads/feature/x\n'
+ const { git, calls } = fakeGit({
+ 'worktree list --porcelain': ok(list),
+ remote: ok('origin\nupstream\n')
+ })
+ const r = await worktreeMerge(git, '/repo', 'feature/x', 'main', true)
+ expect(calls.some((c) => c.join(' ') === 'push origin main')).toBe(true)
+ expect(r.message).toMatch(/pushed main to origin/i)
+ })
it('reports a failed push instead of swallowing it', async () => {
const list = 'worktree /wt/x\nHEAD aaa\nbranch refs/heads/feature/x\n'
const { git } = fakeGit({
diff --git a/src/shared/worktree-ops.ts b/src/shared/worktree-ops.ts
index 37d1de6fa..a8c62dce7 100644
--- a/src/shared/worktree-ops.ts
+++ b/src/shared/worktree-ops.ts
@@ -83,8 +83,8 @@ export async function worktreeAdd(
}
/**
- * Merge `branch` into `baseRef`, and — only when `push` is true AND the repo has a remote — publish
- * the base branch to origin.
+ * Merge `branch` into `baseRef`, and — only when `push` is true AND the repo actually has an
+ * `origin` — publish the base branch to origin.
*
* The push is OPT-IN by design. It used to run "best effort" on every merge: one click on a small
* header chip published to `origin/main` (CI, teammates, protected-branch noise) without the confirm
@@ -124,9 +124,11 @@ export async function worktreeMerge(
}
const merged = `Merged ${branch} into ${baseRef}.`
if (!push) return { ok: true, message: merged }
- // Only push if a remote actually exists — never claim (or attempt) a publish that cannot happen.
- const hasRemote = (await git(repoPath, ['remote'])).out.trim().length > 0
- if (!hasRemote) return { ok: true, message: merged }
+ // The push below is hardcoded to `origin`, so "some remote exists" is not the question: a fork
+ // whose only remote is `upstream` would fail here after being promised an origin push. Only push
+ // when `origin` itself is there — never claim (or attempt) a publish that cannot happen.
+ const remotes = (await git(repoPath, ['remote'])).out.split('\n').map((r) => r.trim())
+ if (!remotes.includes('origin')) return { ok: true, message: merged }
const p = await git(repoPath, ['push', 'origin', baseRef])
// A failed push does not undo the merge, so this stays `ok` — but it is reported, not swallowed:
// the user must know whether origin has the merge.