Skip to content
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
672f34c
Add Git Graph view showing all branches and commit history
brennanb2025 Jun 29, 2026
37194db
Address review: virtual-tab guards, nav-order, truncation copy
brennanb2025 Jun 29, 2026
7ebd572
Forward allRefs over SSH relay and web runtime paths
brennanb2025 Jun 29, 2026
fb96738
Merge origin/main into git-graph view; rebuild the change on main's s…
brennanb2025 Nov 5, 2026
5c6e047
Support filtered and pinned Git history
brennanb2025 Nov 6, 2026
fe7fa0b
Add the Git Graph tab and commit details
brennanb2025 Nov 6, 2026
1e97bda
Restore files the main merge left at stale versions
brennanb2025 Nov 6, 2026
e8979d1
Limit pinned history to explicit graph scopes
brennanb2025 Nov 6, 2026
2e74847
Preserve canonical placement for older graph clients
brennanb2025 Nov 6, 2026
d391794
Retain Git Graph browsing state for the tab lifetime
brennanb2025 Nov 6, 2026
a5f518d
Apply Git Graph branch selections on picker close
brennanb2025 Nov 6, 2026
2faebb0
Keep Git Graph navigation bound to its tab owner
brennanb2025 Nov 6, 2026
8092d3f
Translate desktop layout commands against canonical state
brennanb2025 Nov 6, 2026
349dbd1
Refine Git Graph picker and owner transitions
brennanb2025 Nov 6, 2026
005bd9b
Merge origin/main into brennanb2025/issue-4521-git-graph-view
brennanb2025 Nov 6, 2026
58b2ed3
Drop the redundant default from the exhaustive layout command switch
brennanb2025 Nov 6, 2026
494468b
Align Git Graph with changed-code quality rules
brennanb2025 Nov 6, 2026
f1deb3e
Route Git Graph opening through the existing editor action
brennanb2025 Nov 6, 2026
b5b8f36
Merge origin/main into brennanb2025/issue-4521-git-graph-view
brennanb2025 Nov 6, 2026
4e0f995
Preserve Git Graph selection and keep row content visible
brennanb2025 Nov 6, 2026
e71f631
Bound Git Graph refresh and allow graph column resizing
brennanb2025 Nov 6, 2026
b70df34
Retain Git Graph history for errors without a message
brennanb2025 Nov 6, 2026
b34fd68
Retain Git Graph widths and preserve shifted selections
brennanb2025 Nov 6, 2026
5d435b0
Preserve nullable Git Graph owner fallback
brennanb2025 Nov 6, 2026
cd697c1
Allow guarded checkout of reachable detached commits
brennanb2025 Nov 6, 2026
d2dfd16
Apply commits with cherry-pick and revert through every desktop trans…
brennanb2025 Nov 6, 2026
e2137de
Recover cherry-picks and reverts without opening an editor
brennanb2025 Nov 6, 2026
bc9ab13
Distinguish commit checkout from branches named like object IDs
brennanb2025 Nov 6, 2026
cefda4f
Confirm Git Graph commit actions and preserve their outcomes across n…
brennanb2025 Nov 6, 2026
0bb7849
Preserve Git recovery context and report commit outcomes accurately
brennanb2025 Nov 6, 2026
7f9f7ca
Keep commit action refreshes with their owner and preserve manual rec…
brennanb2025 Nov 6, 2026
28eb179
Type the optional graph filter assertion in the action regression
brennanb2025 Nov 6, 2026
cdf1762
Consolidate commit conflict recovery coverage
brennanb2025 Nov 6, 2026
0af281e
Invalidate the original graph after sequencer recovery
brennanb2025 Nov 6, 2026
9097767
Distinguish existing index conflicts from commit action conflicts
brennanb2025 Nov 6, 2026
5711088
Merge main into Git Graph view
brennanb2025 Nov 7, 2026
227a7ad
Merge main into Git Graph view
brennanb2025 Nov 7, 2026
ca58864
Fix Git Graph layout imports after the RPC method move
brennanb2025 Nov 7, 2026
56ced9b
Merge main into Git Graph view
brennanb2025 Nov 7, 2026
e6ddc82
Merge main into Git Graph view
brennanb2025 Nov 7, 2026
26929b4
Route the Git Graph owner connection through the source-control conne…
brennanb2025 Nov 7, 2026
e1adb5c
Merge main into Git Graph view
brennanb2025 Nov 7, 2026
c19bc41
Keep the Git Graph button idle in hidden Source Control sections
brennanb2025 Nov 7, 2026
c8a0eda
Re-probe Git Graph support when the owner's runtime status changes
brennanb2025 Nov 7, 2026
e3c9374
Merge the final Git Graph view branch into commit actions
brennanb2025 Nov 7, 2026
885da80
Merge main into Git Graph commit actions
brennanb2025 Nov 7, 2026
1e5bab1
Merge main into Git Graph commit actions
brennanb2025 Nov 8, 2026
7cd2e81
Create branches at selected Git Graph commits
brennanb2025 Nov 8, 2026
e4a5cb4
Enable Git Graph branch actions
brennanb2025 Nov 8, 2026
03a73a5
Avoid redundant Git Graph and status requests
brennanb2025 Nov 8, 2026
f0b58ea
Correct Git Graph branch checkout outcomes
brennanb2025 Nov 8, 2026
0920988
Merge main into Git Graph commit actions
brennanb2025 Nov 8, 2026
30ed478
Allow sequencer recovery controls to compile
brennanb2025 Nov 8, 2026
a39c84c
Assert landed HEAD in branch warning tests
brennanb2025 Nov 8, 2026
6a264b0
Show only Git failure reason for commit checkout
brennanb2025 Nov 8, 2026
71c6ac1
Keep a reason when a commit checkout fails without Git output
brennanb2025 Nov 8, 2026
a0ff3ff
Merge main into Git Graph commit actions
brennanb2025 Nov 8, 2026
4cd7c84
Preserve Git action errors and recovery context
brennanb2025 Nov 8, 2026
c576f55
Merge main into Git Graph commit actions
brennanb2025 Nov 8, 2026
53af377
Fix Git Graph badge actions and validation feedback
brennanb2025 Nov 8, 2026
fa2b82a
Show only the reason in Source Control recovery errors
brennanb2025 Nov 8, 2026
c76b15d
Finish empty revert recovery and show Git failure reasons
brennanb2025 Nov 8, 2026
ca68efc
Detect empty commit actions from repository state
brennanb2025 Nov 8, 2026
a4001ec
Preserve staged gitlinks and unstaged sequencer resolutions
brennanb2025 Nov 8, 2026
1003306
Preserve unrelated edits when finishing empty commit actions
brennanb2025 Nov 8, 2026
4e4d0d5
Use the recorded mainline and raw Git paths during recovery
brennanb2025 Nov 8, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 124 additions & 5 deletions src/main/git/branch-switch-real-git.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
import { mkdtemp, rm, writeFile } from 'node:fs/promises'
import { chmod, mkdir, mkdtemp, rename, rm, writeFile } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { runProcess } from '@orca/process-host'
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures'
import { switchBranchGuarded, type BranchSwitchDeps } from './branch-switch'
import {
BranchSwitchLandedWithWarningError,
switchBranchGuarded,
type BranchSwitchDeps
} from './branch-switch'
import { checkoutBranch } from './checkout'
import { getStatus } from './source-control/status-read'

let directory: string
let initialHead: string

async function git(...args: string[]): Promise<string> {
const result = await runProcess({ program: 'git', args, cwd: directory })
Expand All @@ -18,10 +23,13 @@ async function git(...args: string[]): Promise<string> {
return result.stdout.trim()
}

function deps(agentBlocker: string | null = null): BranchSwitchDeps {
function deps(agentBlocker: string | null = null, target = 'feature'): BranchSwitchDeps {
return {
getStatus: () => getStatus(directory, { includeLineStats: false }),
checkout: () => checkoutBranch(directory, 'feature'),
checkout: () =>
checkoutBranch(directory, target, {
detached: /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(target)
}),
getAgentBlocker: async () => agentBlocker
}
}
Expand All @@ -42,17 +50,128 @@ beforeEach(async () => {
await git('add', 'file.txt')
await git('commit', '-qm', 'base')
await git('branch', 'feature')
initialHead = await git('rev-parse', 'HEAD')
})

afterEach(async () => {
await rm(directory, { recursive: true, force: true })
})

describe('switchBranchGuarded', () => {
it.each([false, true])(
'keeps the checkout refusal when the landed HEAD read fails: %s',
async (missingHead) => {
const oid = await git('rev-parse', 'HEAD')
await writeFile(join(directory, '.git', 'HEAD.lock'), '')
const dependencies = deps(null, oid)
const checkout = dependencies.checkout
dependencies.checkout = async (...args) => {
try {
return await checkout(...args)
} catch (error) {
if (missingHead) {
await rename(join(directory, '.git', 'HEAD'), join(directory, '.git', 'saved-HEAD'))
}
throw error
}
}
try {
await switchBranchGuarded(directory, { commitId: oid }, {}, dependencies)
throw new Error('Expected checkout to fail')
} catch (error) {
expect(error).not.toBeInstanceOf(BranchSwitchLandedWithWarningError)
expect(String(error)).toContain('HEAD.lock')
expect(String(error)).not.toContain('Command failed:')
expect(String(error)).not.toContain('\n')
} finally {
if (missingHead) {
await rename(join(directory, '.git', 'saved-HEAD'), join(directory, '.git', 'HEAD'))
}
}
expect(await currentBranch()).toBe('main')
}
)
it('leaves a reachable detached commit and actually checks out the branch', async () => {
await git('checkout', '--detach', '-q')
const result = await switchBranchGuarded(directory, 'feature', {}, deps())
expect(result).toEqual({ branch: 'feature', previousBranch: null, head: initialHead })
expect(await currentBranch()).toBe('feature')
})

it('refuses to abandon a detached commit not reachable from branches, remotes or tags', async () => {
await git('checkout', '--detach', '-q')
await git('commit', '--allow-empty', '-qm', 'detached work')
await expect(switchBranchGuarded(directory, 'feature', {}, deps())).rejects.toThrow(
'This checkout is on a detached commit. Switch branches from a terminal so commits made here are not lost.'
)
expect(await git('log', '-1', '--format=%s')).toBe('detached work')
})

it('detaches at the commit even when a branch has the same full object ID as its name', async () => {
const oid = await git('rev-parse', 'HEAD')
await git('commit', '--allow-empty', '-qm', 'later')
await git('branch', oid)
await switchBranchGuarded(directory, { commitId: oid }, {}, deps(null, oid))
expect(await git('log', '-1', '--format=%s')).toBe('base')
expect(await git('branch', '--show-current')).toBe('')
await switchBranchGuarded(
directory,
oid,
{},
{ ...deps(), checkout: () => checkoutBranch(directory, oid) }
)
expect(await currentBranch()).toBe(oid)
expect(await git('log', '-1', '--format=%s')).toBe('later')
})

it('moves between distinct reachable detached commits', async () => {
const target = await git('rev-parse', 'HEAD')
await git('commit', '--allow-empty', '-qm', 'later')
await git('checkout', '--detach', '-q')
await switchBranchGuarded(directory, { commitId: target }, {}, deps(null, target))
expect(await git('log', '-1', '--format=%s')).toBe('base')
expect(await git('branch', '--show-current')).toBe('')
})

it('does not check out a detached commit that is already HEAD', async () => {
const oid = await git('rev-parse', 'HEAD')
await git('checkout', '--detach', '-q')
const hooks = join(directory, '.git', 'hooks')
await git('config', 'core.hooksPath', hooks)
await mkdir(hooks, { recursive: true })
await writeFile(join(hooks, 'post-checkout'), '#!/bin/sh\necho should-not-run >&2\nexit 1\n')
await chmod(join(hooks, 'post-checkout'), 0o755)
await expect(
switchBranchGuarded(directory, { commitId: oid }, {}, deps(null, oid))
).resolves.toEqual({
branch: oid,
previousBranch: null,
head: oid
})
})

it('reports a landed commit checkout even when its post-checkout hook fails', async () => {
const oid = await git('rev-parse', 'HEAD')
await git('commit', '--allow-empty', '-qm', 'later')
const hooks = join(directory, '.git', 'hooks')
await git('config', 'core.hooksPath', hooks)
await mkdir(hooks, { recursive: true })
await writeFile(join(hooks, 'post-checkout'), '#!/bin/sh\necho hook-failed >&2\nexit 1\n')
await chmod(join(hooks, 'post-checkout'), 0o755)
await expect(
switchBranchGuarded(directory, { commitId: oid }, {}, deps(null, oid))
).rejects.toMatchObject({
name: 'BranchSwitchLandedWithWarningError',
message: `Switched to ${oid}. A git hook in this repository failed afterwards and said: hook-failed. The switch itself worked.`
})
expect(await git('rev-parse', 'HEAD')).toBe(oid)
expect(await git('branch', '--show-current')).toBe('')
})

it('switches a clean checkout and reports the branch it left', async () => {
const result = await switchBranchGuarded(directory, 'feature', {}, deps())

expect(result).toEqual({ branch: 'feature', previousBranch: 'main' })
expect(result).toEqual({ branch: 'feature', previousBranch: 'main', head: initialHead })
expect(await currentBranch()).toBe('feature')
})

Expand Down
48 changes: 31 additions & 17 deletions src/main/git/branch-switch-target-real-git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ import { runProcess } from '@orca/process-host'
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
import type { BranchSwitchTarget } from '../../shared/git/branch-switch-target'
import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures'
import { BranchSwitchLandedWithWarningError, switchBranchGuarded } from './branch-switch'
import { switchBranchGuarded } from './branch-switch'
import { BranchSwitchCollisionError } from './branch-switch-target'
import { checkoutBranch, listLocalBranches } from './checkout'
import { getStatus } from './source-control/status-read'
import { searchRemoteRefPage } from './repo-remote-ref-search'

let directory: string
let initialHead: string
async function git(...args: string[]): Promise<string> {
const result = await runProcess({
program: 'git',
Expand Down Expand Up @@ -56,6 +57,7 @@ beforeEach(async () => {
await writeFile(join(directory, 'file.txt'), 'base\n')
await git('add', 'file.txt')
await git('commit', '-qm', 'base')
initialHead = await git('rev-parse', 'HEAD')
})
afterEach(async () => {
await rm(directory, { recursive: true, force: true })
Expand All @@ -66,7 +68,8 @@ it('switches an exact local target and records it', async () => {
const recorded = vi.fn()
expect(await switchTo({ kind: 'local', name: 'feature' }, null, recorded)).toEqual({
branch: 'feature',
previousBranch: 'main'
previousBranch: 'main',
head: initialHead
})
expect(await git('symbolic-ref', '--short', 'HEAD')).toBe('feature')
expect(recorded).toHaveBeenCalledOnce()
Expand All @@ -84,12 +87,17 @@ it.each(['team/upstream', 'origin'])(
expect(await git('rev-parse', `refs/heads/${name}/topic`)).toBe(await git('rev-parse', 'main'))
}
)
it('reuses a differently named local tracker', async () => {
it('returns the advanced HEAD when reusing a differently named local tracker', async () => {
await remote('origin')
await git('branch', '--track', 'my-topic', 'refs/remotes/origin/topic')
await git('checkout', '-q', 'my-topic')
await git('commit', '--allow-empty', '-qm', 'local advance')
const advanced = await git('rev-parse', 'HEAD')
await git('checkout', '-q', 'main')
expect(await switchTo({ kind: 'remote', name: 'origin/topic' })).toEqual({
branch: 'my-topic',
previousBranch: 'main'
previousBranch: 'main',
head: advanced
})
expect(await git('symbolic-ref', '--short', 'HEAD')).toBe('my-topic')
expect((await listLocalBranches(directory)).branches).not.toContain('topic')
Expand Down Expand Up @@ -130,6 +138,14 @@ it('carries uncommitted changes onto a new branch but refuses an existing branch
expect(await git('ls-files', '--others', '--exclude-standard')).toBe('draft.txt')
expect(await readFile(join(directory, 'draft.txt'), 'utf8')).toBe('draft\n')
})
it('refuses creation of the current branch without recording a switch', async () => {
const recorded = vi.fn()
await expect(switchTo({ kind: 'new', name: 'main' }, null, recorded)).rejects.toMatchObject({
data: { existingBranch: 'main' }
})
expect(recorded).not.toHaveBeenCalled()
expect(await git('symbolic-ref', '--short', 'HEAD')).toBe('main')
})
it('offers direct local collision recovery without relying on discovery', async () => {
await git('branch', 'topic')
await expect(switchTo({ kind: 'new', name: 'topic' })).rejects.toMatchObject({
Expand All @@ -152,16 +168,15 @@ it('probes the resolved local name when a remote checkout lands with a hook fail
const recorded = vi.fn()
await expect(
switchTo({ kind: 'remote', name: 'team/upstream/topic' }, null, recorded)
).rejects.toThrow(
new BranchSwitchLandedWithWarningError(
'Switched to topic. A git hook in this repository failed afterwards and said: hook failed. The switch itself worked.',
'topic'
)
)
).rejects.toMatchObject({
name: 'BranchSwitchLandedWithWarningError',
branch: 'topic',
head: initialHead
})
expect(await git('symbolic-ref', '--short', 'HEAD')).toBe('topic')
expect(recorded).toHaveBeenCalledOnce()
})
it("quotes git's own error without blaming a hook when a switch lands", async () => {
it('reports the landed HEAD when git errors after checkout', async () => {
await git('branch', 'topic')
await expect(
switchBranchGuarded(
Expand All @@ -179,12 +194,11 @@ it("quotes git's own error without blaming a hook when a switch lands", async ()
getAgentBlocker: async () => null
}
)
).rejects.toThrow(
new BranchSwitchLandedWithWarningError(
'Switched to topic, but git reported: error: unable to create file app.css: Permission denied',
'topic'
)
)
).rejects.toMatchObject({
name: 'BranchSwitchLandedWithWarningError',
branch: 'topic',
head: initialHead
})
})
it('maps a remote not covered by its fetch settings to tracking recovery', async () => {
await remote('origin')
Expand Down
56 changes: 50 additions & 6 deletions src/main/git/branch-switch-target.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,66 @@ export class BranchSwitchCollisionError extends Error {
}
}

export async function readCurrentBranch(
worktreePath: string,
options: GitRuntimeOptions
): Promise<string | null> {
try {
const { stdout } = await gitExecFileAsync(
['symbolic-ref', '--quiet', '--short', 'HEAD'],
gitOptionsForWorktree(worktreePath, options)
)
return stdout.trim() || null
} catch {
return null
}
}

export async function readBranchSwitchHead(
worktreePath: string,
options: GitRuntimeOptions
): Promise<string | undefined> {
try {
const { stdout } = await gitExecFileAsync(
['rev-parse', '--verify', 'HEAD'],
gitOptionsForWorktree(worktreePath, options)
)
return stdout.trim() || undefined
} catch {
return undefined
}
}

export async function validateNewBranchName(
path: string,
name: string,
options: GitRuntimeOptions
): Promise<void> {
if (!isBranchNameValid(name)) {
throw new Error('This branch name is invalid. Choose a different name.')
}
await gitExecFileAsync(
['check-ref-format', '--branch', name],
gitOptionsForWorktree(path, options)
).catch(() => {
throw new Error('This branch name is invalid. Choose a different name.')
})
}

export async function resolveBranchSwitchTarget(
path: string,
target: BranchSwitchTarget,
options: GitRuntimeOptions
): Promise<{ branch: string; creation?: BranchSwitchCreation }> {
const execution = gitOptionsForWorktree(path, { ...options, admissionTier: 'interactive' })
const run = (args: string[]) => gitExecFileAsync(args, execution)
if (!isBranchNameValid(target.name)) {
throw new Error('This branch name is invalid. Choose a different name.')
}
if (target.kind === 'new') {
await run(['check-ref-format', '--branch', target.name]).catch(() => {
throw new Error('This branch name is invalid. Choose a different name.')
})
await validateNewBranchName(path, target.name, { ...options, admissionTier: 'interactive' })
return { branch: target.name, creation: { kind: 'new' } }
}
if (!isBranchNameValid(target.name)) {
throw new Error('This branch name is invalid. Choose a different name.')
}
const full =
target.kind === 'local'
? `refs/heads/${target.name}`
Expand Down
Loading