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): branch quick-pick lists remote-only branches after fetch

enes0e0a03335bc2
diff --git a/src/core/git-service.ts b/src/core/git-service.ts
index f307f4abd..fc7c8a912 100644
--- a/src/core/git-service.ts
+++ b/src/core/git-service.ts
@@ -367,10 +367,11 @@ export class GitService {
// simply fails to empty when there's no origin, so it needn't wait on `remote`.)
// gh auth is deliberately NOT awaited here (ghAuthedSwr): it hits the GitHub API and
// used to hold the whole status — i.e. the panel's first paint — hostage for ~700ms.
- const [branchR, branchesR, remotesR, originR, countsR, upstreamR, cachedR, workR, porcelainR] =
+ const [branchR, branchesR, remoteBranchesR, remotesR, originR, countsR, upstreamR, cachedR, workR, porcelainR] =
await Promise.all([
git(cwd, ['rev-parse', '--abbrev-ref', 'HEAD']),
git(cwd, ['branch', '--format=%(refname:short)']),
+ git(cwd, ['branch', '-r', '--format=%(refname:short)']),
git(cwd, ['remote']),
git(cwd, ['remote', 'get-url', 'origin']),
git(cwd, ['rev-list', '--left-right', '--count', '@{upstream}...HEAD']),
@@ -385,6 +386,11 @@ export class GitService {
const branch = branchR.out.trim() || 'HEAD'
const branches = branchesR.out.split('\n').map((b) => b.trim()).filter(Boolean)
+ // `<remote>/HEAD` is a symref to the remote's default branch, not a branch of its own.
+ const remoteBranches = remoteBranchesR.out
+ .split('\n')
+ .map((b) => b.trim())
+ .filter((b) => b && !/\/HEAD$/.test(b))
const hasRemote = !!remotesR.out.trim()
const hasUpstream = upstreamR.ok && !!upstreamR.out.trim()
const originUrl = originR.out.trim()
@@ -433,6 +439,7 @@ export class GitService {
repoName,
branch,
branches,
+ remoteBranches,
ahead,
behind,
hasRemote,
diff --git a/src/renderer/components/SourceControlPanel.tsx b/src/renderer/components/SourceControlPanel.tsx
index 7774ac3a6..5fd1b1d05 100644
--- a/src/renderer/components/SourceControlPanel.tsx
+++ b/src/renderer/components/SourceControlPanel.tsx
@@ -603,7 +603,18 @@ export function SourceControlPanel({
const query = newBranch.trim()
const q = query.toLowerCase()
const shown = status.branches.filter((b) => !q || b.toLowerCase().includes(q))
+ // Branches that exist only on a remote (fetched, but never checked out here):
+ // `origin/feat/x` whose local name `feat/x` is not a local branch. Switching passes
+ // the LOCAL name — `git switch feat/x` DWIMs a tracking branch from the remote ref
+ // (ambiguity across several remotes is git's own error, surfaced in the banner).
+ const localName = (r: string): string => r.slice(r.indexOf('/') + 1)
+ const localSet = new Set(status.branches)
+ const remoteOnly = (status.remoteBranches ?? []).filter((r) => !localSet.has(localName(r)))
+ const remoteShown = remoteOnly.filter((r) => !q || r.toLowerCase().includes(q))
const exact = status.branches.find((b) => b === query)
+ // Typing the exact local name of a remote-only branch must SWITCH (track), not
+ // create an unrelated branch at HEAD under the same name.
+ const remoteExact = !exact && remoteOnly.find((r) => localName(r) === query)
const close = (): void => {
setBranchMenu(null)
setNewBranch('')
@@ -638,6 +649,7 @@ export function SourceControlPanel({
}
if (e.key !== 'Enter' || !query) return
if (exact) pick(exact)
+ else if (remoteExact) pick(localName(remoteExact))
else createNew()
}}
/>
@@ -649,9 +661,24 @@ export function SourceControlPanel({
{b}
</button>
))}
- {query && !exact && (
+ {remoteShown.length > 0 && (
<>
{shown.length > 0 && <div className="ctx-sep" />}
+ {remoteShown.map((r) => (
+ <button
+ key={`r:${r}`}
+ title={`Check out ${r} as a local tracking branch`}
+ onClick={() => pick(localName(r))}
+ >
+ {'⇣ '}
+ {r}
+ </button>
+ ))}
+ </>
+ )}
+ {query && !exact && !remoteExact && (
+ <>
+ {(shown.length > 0 || remoteShown.length > 0) && <div className="ctx-sep" />}
<button onClick={createNew}>+ Create branch “{query}”</button>
</>
)}
diff --git a/src/shared/types.ts b/src/shared/types.ts
index 2c6f6d85e..ebe0138fb 100644
--- a/src/shared/types.ts
+++ b/src/shared/types.ts
@@ -855,6 +855,10 @@ export interface GitStatus {
branch: string
/** Local branch names (for the branch switcher). */
branches: string[]
+ /** Remote-tracking branch names as `<remote>/<branch>` (HEAD pointers excluded), so the
+ * switcher can offer branches that exist only on a remote — a plain `git switch <branch>`
+ * then DWIMs a local tracking branch. Absent in stale caches: read with `?? []`. */
+ remoteBranches?: string[]
ahead: number
behind: number
/** The repo has at least one remote — which may well not be named `origin` (a fork can have only