Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.
TypeScript adeagent-ideai-agentsautomationbotclaude-codecodexghosttygrok-bothermes-agentmobile-appmuseopenclawopencodeorchestrationpiruntimeterminalworktreesyc-backed
fix(git): resolve current branches without tag ambiguity (#35040)
OrcaWin4a0c762f24fe
diff --git a/src/main/agent-hooks/first-work-branch-rename.test.ts b/src/main/agent-hooks/first-work-branch-rename.test.tsindex 56c36ead12e..82de0f5da1d 100644--- a/src/main/agent-hooks/first-work-branch-rename.test.ts+++ b/src/main/agent-hooks/first-work-branch-rename.test.ts@@ -680,7 +680,7 @@ describe('maybeAutoRenameBranchOnFirstWork', () => {throw noUpstreamError}if (args[0] === 'symbolic-ref') {- return { stdout: 'you/Nautilus\n', stderr: '' }+ return { stdout: 'refs/heads/you/Nautilus\n', stderr: '' }}if (args[0] === 'rev-parse' && args.includes('refs/remotes/origin/you/Nautilus')) {throw new Error('not found')@@ -705,7 +705,7 @@ describe('maybeAutoRenameBranchOnFirstWork', () => {return { stdout: 'you/Nautilus\n', stderr: '' }}if (args[0] === 'symbolic-ref') {- return { stdout: 'you/Nautilus\n', stderr: '' }+ return { stdout: 'refs/heads/you/Nautilus\n', stderr: '' }}if (args[0] === 'rev-parse' && args.some((arg) => arg.includes('@{u}'))) {upstreamReadCount += 1diff --git a/src/main/git/branch-rename.test.ts b/src/main/git/branch-rename.test.tsindex c4ba70cd10b..fa74878f019 100644--- a/src/main/git/branch-rename.test.ts+++ b/src/main/git/branch-rename.test.ts@@ -16,7 +16,7 @@ describe('probeBranchUpstream', () => {it('reports has-upstream when @{u} resolves to a tracking ref', async () => {const exec: GitExec = vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n', stderr: '' }+ return { stdout: 'refs/heads/feature\n', stderr: '' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return { stdout: 'origin/feature\n', stderr: '' }@@ -29,7 +29,7 @@ describe('probeBranchUpstream', () => {it('reports no-upstream when there is no upstream', async () => {const exec: GitExec = vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n', stderr: '' }+ return { stdout: 'refs/heads/feature\n', stderr: '' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw noUpstreamError@@ -45,7 +45,7 @@ describe('probeBranchUpstream', () => {it('reports has-upstream when a same-name origin tracking ref exists without configured upstream', async () => {const exec: GitExec = vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n', stderr: '' }+ return { stdout: 'refs/heads/feature\n', stderr: '' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw noUpstreamError@@ -82,7 +82,7 @@ describe('probeBranchUpstream', () => {// gettext can translate even Git's fatal: prefix.const exec: GitExec = vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n', stderr: '' }+ return { stdout: 'refs/heads/feature\n', stderr: '' }}throw new Error('Command failed: git rev-parse --abbrev-ref HEAD@{u}\n' +diff --git a/src/main/git/current-branch-identity-real-git.test.ts b/src/main/git/current-branch-identity-real-git.test.tsnew file mode 100644index 00000000000..b487f8737c2--- /dev/null+++ b/src/main/git/current-branch-identity-real-git.test.ts@@ -0,0 +1,53 @@+import { mkdtemp, rm } from 'node:fs/promises'+import { tmpdir } from 'node:os'+import { join } from 'node:path'+import { runProcess } from '@orca/process-host'+import { afterEach, expect, it } from 'vitest'+import { gitPush } from './remote'+import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures'++let directory: string | null = null++afterEach(async () => {+ if (directory) {+ await rm(directory, { recursive: true, force: true })+ directory = null+ }+})++it('pushes to the configured branch target when a tag shares the branch name', async () => {+ const repo = await mkdtemp(join(tmpdir(), 'orca-current-branch-'))+ directory = repo+ const git = async (args: string[], cwd = repo) => {+ const result = await runProcess({ program: 'git', args, cwd })+ if (result.code !== 0) {+ throw new Error(result.stderr)+ }+ return result.stdout.trim()+ }+ await git(['init', '-q'])+ await git(['symbolic-ref', 'HEAD', 'refs/heads/release'])+ await git(['config', 'user.name', 'Audit'])+ await git(['config', 'user.email', '[email protected]'])+ await git(['config', 'commit.gpgsign', 'false'])+ await git(['config', 'core.hooksPath', ''])+ await git(['commit', '--allow-empty', '-qm', 'base'])+ await git(['tag', 'release'])+ await git(['commit', '--allow-empty', '-qm', 'feature'])+ const head = await git(['rev-parse', 'HEAD'])+ const origin = join(repo, 'origin.git')+ const fork = join(repo, 'fork.git')+ await git(['init', '--bare', '-q', origin])+ await git(['init', '--bare', '-q', fork])+ await git(['remote', 'add', 'origin', origin])+ await git(['remote', 'add', 'fork', fork])+ await git(['config', 'branch.release.remote', 'fork'])+ await git(['config', 'branch.release.merge', 'refs/heads/published'])++ await gitPush(repo)++ expect(await git(['for-each-ref', '--format=%(refname)', 'refs/heads/'], origin)).toBe('')+ expect(await git(['rev-parse', '--verify', 'refs/heads/published'], fork)).toBe(head)+})++installRealWorkerThreadChildProcesses()diff --git a/src/main/git/remote.test.ts b/src/main/git/remote.test.tsindex a8a99fb353a..69e19fcae17 100644--- a/src/main/git/remote.test.ts+++ b/src/main/git/remote.test.ts@@ -39,7 +39,7 @@ describe('git remote operations', () => {it('pushes to the configured upstream remote and branch', async () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'review/pr-1738\n', stderr: '' }+ return { stdout: 'refs/heads/review/pr-1738\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -65,7 +65,7 @@ describe('git remote operations', () => {it('does not combine remote.pushDefault with a base-branch merge target', async () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature/fix\n', stderr: '' }+ return { stdout: 'refs/heads/feature/fix\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -95,7 +95,7 @@ describe('git remote operations', () => {it('keeps a fork head target when the contributor branch matches the base branch name', async () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'review/pr-1\n', stderr: '' }+ return { stdout: 'refs/heads/review/pr-1\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -121,7 +121,7 @@ describe('git remote operations', () => {it('pushes to a URL-valued branch pushRemote when no named remote exists', async () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'imp/chinese-translation\n', stderr: '' }+ return { stdout: 'refs/heads/imp/chinese-translation\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -157,7 +157,7 @@ describe('git remote operations', () => {it('normalizes a URL-valued branch remote to a matching named remote before pushing', async () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'imp/chinese-translation\n', stderr: '' }+ return { stdout: 'refs/heads/imp/chinese-translation\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -209,7 +209,7 @@ describe('git remote operations', () => {]gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'imp/chinese-translation\n', stderr: '' }+ return { stdout: 'refs/heads/imp/chinese-translation\n', stderr: '' }}if (args[0] === 'config' && args[1] === '--list') {return {@@ -265,7 +265,7 @@ describe('git remote operations', () => {it('passes --force-with-lease when requested', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({stdout: 'branch.feature.remote\norigin\0branch.feature.merge\nrefs/heads/feature\0',stderr: ''@@ -397,14 +397,14 @@ describe('git remote operations', () => {it("runs pull with the user's configured strategy", async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: '', stderr: '' })await gitPull('/repo')expect(gitExecFileAsyncMock.mock.calls).toEqual([- [['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],+ [['symbolic-ref', '--quiet', 'HEAD'], { cwd: '/repo' }],[['rev-parse', '--abbrev-ref', 'HEAD@{u}'], { cwd: '/repo' }],[['pull'], { cwd: '/repo' }]])@@ -415,20 +415,20 @@ describe('git remote operations', () => {'Command failed: git pull\n' + 'fatal: Need to specify how to reconcile divergent branches.')gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(divergentError)- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: '', stderr: '' })await gitPull('/repo')expect(gitExecFileAsyncMock.mock.calls).toEqual([- [['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],+ [['symbolic-ref', '--quiet', 'HEAD'], { cwd: '/repo' }],[['rev-parse', '--abbrev-ref', 'HEAD@{u}'], { cwd: '/repo' }],[['pull'], { cwd: '/repo' }],- [['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],+ [['symbolic-ref', '--quiet', 'HEAD'], { cwd: '/repo' }],[['rev-parse', '--abbrev-ref', 'HEAD@{u}'], { cwd: '/repo' }],[['pull', '--no-rebase'], { cwd: '/repo' }]])@@ -436,7 +436,7 @@ describe('git remote operations', () => {it('does not retry a fast-forward-only pull that fails on divergence', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(new Error('Command failed: git pull\nfatal: Not possible to fast-forward, aborting.')@@ -474,10 +474,10 @@ describe('git remote operations', () => {'Command failed: git pull --no-rebase\nCONFLICT (content): Merge conflict in file.txt')gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(divergentError)- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(mergeConflictError)@@ -487,7 +487,7 @@ describe('git remote operations', () => {it('pulls the same-name origin branch for legacy base-tracking worktrees', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/main\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'abc123\n', stderr: '' }).mockResolvedValueOnce({ stdout: '', stderr: '' })@@ -495,7 +495,7 @@ describe('git remote operations', () => {await gitPull('/repo')expect(gitExecFileAsyncMock.mock.calls).toEqual([- [['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],+ [['symbolic-ref', '--quiet', 'HEAD'], { cwd: '/repo' }],[['rev-parse', '--abbrev-ref', 'HEAD@{u}'], { cwd: '/repo' }],[['rev-parse', '--verify', '--quiet', 'refs/remotes/origin/feature'], { cwd: '/repo' }],[['pull', 'origin', 'feature'], { cwd: '/repo' }]@@ -520,14 +520,14 @@ describe('git remote operations', () => {it('fast-forwards with --ff-only using the configured upstream', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: '', stderr: '' })await gitFastForward('/repo')expect(gitExecFileAsyncMock.mock.calls).toEqual([- [['symbolic-ref', '--quiet', '--short', 'HEAD'], { cwd: '/repo' }],+ [['symbolic-ref', '--quiet', 'HEAD'], { cwd: '/repo' }],[['rev-parse', '--abbrev-ref', 'HEAD@{u}'], { cwd: '/repo' }],[['pull', '--ff-only'], { cwd: '/repo' }]])@@ -702,7 +702,7 @@ describe('git remote operations', () => {it('normalizes pull authentication errors to a friendly message', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(new Error('Authentication failed'))@@ -713,7 +713,7 @@ describe('git remote operations', () => {it('normalizes pull dirty-worktree aborts to a friendly message', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(new Error(@@ -732,7 +732,7 @@ describe('git remote operations', () => {it('normalizes pull untracked-file aborts to a friendly message', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n', stderr: '' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n', stderr: '' }).mockResolvedValueOnce({ stdout: 'origin/feature\n', stderr: '' }).mockRejectedValueOnce(new Error(diff --git a/src/main/git/status-upstream-negative-cache.test.ts b/src/main/git/status-upstream-negative-cache.test.tsindex 5618ff1910f..b82b3bf83eb 100644--- a/src/main/git/status-upstream-negative-cache.test.ts+++ b/src/main/git/status-upstream-negative-cache.test.ts@@ -70,7 +70,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'feature\n' }+ return { stdout: 'refs/heads/feature\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error('fatal: no upstream configured for branch feature')@@ -117,7 +117,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'feature\n' }+ return { stdout: 'refs/heads/feature\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error('fatal: no upstream configured for branch feature')@@ -180,7 +180,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentBranch}\n` }+ return { stdout: `refs/heads/${currentBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error(`fatal: no upstream configured for branch ${currentBranch}`)@@ -244,7 +244,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentBranch}\n` }+ return { stdout: `refs/heads/${currentBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error(`fatal: no upstream configured for branch ${currentBranch}`)@@ -302,7 +302,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentBranch}\n` }+ return { stdout: `refs/heads/${currentBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error(`fatal: no upstream configured for branch ${currentBranch}`)@@ -352,7 +352,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentBranch}\n` }+ return { stdout: `refs/heads/${currentBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error(`fatal: no upstream configured for branch ${currentBranch}`)@@ -386,7 +386,7 @@ describe('local upstream negative cache', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentBranch}\n` }+ return { stdout: `refs/heads/${currentBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error(`fatal: no upstream configured for branch ${currentBranch}`)diff --git a/src/main/git/status-upstream-probe-churn.test.ts b/src/main/git/status-upstream-probe-churn.test.tsindex f0a4fd60729..b0bd802bc68 100644--- a/src/main/git/status-upstream-probe-churn.test.ts+++ b/src/main/git/status-upstream-probe-churn.test.ts@@ -75,7 +75,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'Initi-Project\n' }+ return { stdout: 'refs/heads/Initi-Project\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error("fatal: no upstream configured for branch 'Initi-Project'")@@ -116,7 +116,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'Initi-Project\n' }+ return { stdout: 'refs/heads/Initi-Project\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error("fatal: no upstream configured for branch 'Initi-Project'")@@ -150,7 +150,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'Initi-Project\n' }+ return { stdout: 'refs/heads/Initi-Project\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {await Promise.resolve()@@ -191,7 +191,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'bench/feature\n' }+ return { stdout: 'refs/heads/bench/feature\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error("fatal: no upstream configured for branch 'bench/feature'")@@ -268,7 +268,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'feature/fix\n' }+ return { stdout: 'refs/heads/feature/fix\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error("fatal: no upstream configured for branch 'feature/fix'")@@ -305,7 +305,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: `${currentStatusBranch}\n` }+ return { stdout: `refs/heads/${currentStatusBranch}\n` }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error('fatal: no upstream configured')@@ -341,7 +341,7 @@ describe('getStatus missing-upstream polling churn', () => {}}if (args[0] === 'symbolic-ref' && args.includes('HEAD')) {- return { stdout: 'Initi-Project\n' }+ return { stdout: 'refs/heads/Initi-Project\n' }}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {throw new Error("fatal: no upstream configured for branch 'Initi-Project'")diff --git a/src/main/git/status.test.ts b/src/main/git/status.test.tsindex 30ffdcb5a7f..e3b05dacdda 100644--- a/src/main/git/status.test.ts+++ b/src/main/git/status.test.ts@@ -300,7 +300,7 @@ describe('getStatus', () => {})}if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'feature/prompts\n' })+ return Promise.resolve({ stdout: 'refs/heads/feature/prompts\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -330,7 +330,7 @@ describe('getStatus', () => {stdout:'# branch.oid abcdef1234567890\n# branch.head feature/prompts\n# branch.upstream origin/main\n# branch.ab +1 -0\n'})- .mockResolvedValueOnce({ stdout: 'feature/prompts\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature/prompts\n' }).mockResolvedValueOnce({ stdout: 'origin/main\n' }).mockResolvedValueOnce({ stdout: 'abc123\n' }).mockResolvedValueOnce({ stdout: '3\t1\n' })diff --git a/src/main/git/upstream.test.ts b/src/main/git/upstream.test.tsindex fdf991eed0b..1759758957a 100644--- a/src/main/git/upstream.test.ts+++ b/src/main/git/upstream.test.ts@@ -31,7 +31,7 @@ describe('getUpstreamStatus', () => {gitExecFileAsyncMock.mockImplementation(async (args: string[]) => {if (args[0] === 'symbolic-ref') {await symbolicRefGate- return { stdout: 'main\n' }+ return { stdout: 'refs/heads/main\n' }}if (args[0] === 'rev-parse') {return { stdout: 'origin/main\n' }@@ -59,7 +59,7 @@ describe('getUpstreamStatus', () => {it('isolates physical reads by worktree, native or WSL host, and every target field', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'main\n' })+ return Promise.resolve({ stdout: 'refs/heads/main\n' })}if (args[0] === 'check-ref-format') {return Promise.resolve({ stdout: '' })@@ -103,10 +103,10 @@ describe('getUpstreamStatus', () => {it('runs fresh physical work after a normalized rejection', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'main\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/main\n' }).mockResolvedValueOnce({ stdout: 'origin/main\n' }).mockRejectedValueOnce(new Error('fatal: authentication failed'))- .mockResolvedValueOnce({ stdout: 'main\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/main\n' }).mockResolvedValueOnce({ stdout: 'origin/main\n' }).mockResolvedValueOnce({ stdout: '0\t0\n' })@@ -155,14 +155,14 @@ describe('getUpstreamStatus', () => {const after = getUpstreamStatus('/repo')await vi.waitFor(() => expect(pendingReads).toHaveLength(3))- pendingReads.forEach(({ resolve }) => resolve({ stdout: 'main\n' }))+ pendingReads.forEach(({ resolve }) => resolve({ stdout: 'refs/heads/main\n' }))await Promise.all([before, during, after])expect(pendingReads).toHaveLength(3)})it('returns upstream and ahead/behind counts when tracking is configured', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'main\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/main\n' }).mockResolvedValueOnce({ stdout: 'origin/main\n' }).mockResolvedValueOnce({ stdout: '2\t3\n' }).mockResolvedValueOnce({ stdout: '+ abc123 remote work\n' })@@ -180,7 +180,7 @@ describe('getUpstreamStatus', () => {it('marks diverged upstream commits as patch-equivalent after a rebase', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockResolvedValueOnce({ stdout: 'origin/feature\n' }).mockResolvedValueOnce({ stdout: '14\t3\n' }).mockResolvedValueOnce({@@ -202,7 +202,7 @@ describe('getUpstreamStatus', () => {it('keeps configured local-branch upstreams', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockResolvedValueOnce({ stdout: 'main\n' }).mockResolvedValueOnce({ stdout: '1\t0\n' })@@ -218,7 +218,7 @@ describe('getUpstreamStatus', () => {it('returns hasUpstream=false when upstream output is empty', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockResolvedValueOnce({ stdout: '\n' }).mockResolvedValueOnce({ stdout: '' }).mockRejectedValueOnce(new Error('missing remote branch'))@@ -234,7 +234,7 @@ describe('getUpstreamStatus', () => {it('returns hasUpstream=false when upstream is missing', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockRejectedValueOnce(new Error('fatal: no upstream configured')).mockResolvedValueOnce({ stdout: '' }).mockRejectedValueOnce(new Error('missing remote branch'))@@ -250,7 +250,7 @@ describe('getUpstreamStatus', () => {it('returns hasUpstream=false when the configured tracking ref is missing', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockRejectedValueOnce(missingTrackingRefError).mockResolvedValueOnce({ stdout: '' }).mockRejectedValueOnce(new Error('missing remote branch'))@@ -266,7 +266,7 @@ describe('getUpstreamStatus', () => {it('uses the same-name origin branch when a legacy worktree tracks origin/main', async () => {gitExecFileAsyncMock- .mockResolvedValueOnce({ stdout: 'feature\n' })+ .mockResolvedValueOnce({ stdout: 'refs/heads/feature\n' }).mockResolvedValueOnce({ stdout: 'origin/main\n' }).mockResolvedValueOnce({ stdout: 'abc123\n' }).mockResolvedValueOnce({ stdout: '3\t1\n' })@@ -286,7 +286,7 @@ describe('getUpstreamStatus', () => {it('uses a named remote that matches a URL-valued branch remote', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'imp/chinese-translation\n' })+ return Promise.resolve({ stdout: 'refs/heads/imp/chinese-translation\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -344,7 +344,7 @@ describe('getUpstreamStatus', () => {it('uses a fork head branch even when its name matches the base branch', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'review/pr-1\n' })+ return Promise.resolve({ stdout: 'refs/heads/review/pr-1\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -380,7 +380,7 @@ describe('getUpstreamStatus', () => {it('marks a URL-valued branch push target when no matching remote is configured', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'imp/chinese-translation\n' })+ return Promise.resolve({ stdout: 'refs/heads/imp/chinese-translation\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -425,7 +425,7 @@ describe('getUpstreamStatus', () => {it('marks a fork head push target when the same-named base branch is on another remote', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'review/pr-1\n' })+ return Promise.resolve({ stdout: 'refs/heads/review/pr-1\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -467,7 +467,7 @@ describe('getUpstreamStatus', () => {it('does not mark origin base-branch config as a push target', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'feature\n' })+ return Promise.resolve({ stdout: 'refs/heads/feature\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -508,7 +508,7 @@ describe('getUpstreamStatus', () => {it('does not mark remote.pushDefault plus origin base branch as a push target', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'feature/fix\n' })+ return Promise.resolve({ stdout: 'refs/heads/feature/fix\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.reject(new Error('fatal: no upstream configured'))@@ -546,7 +546,7 @@ describe('getUpstreamStatus', () => {it('keeps a configured upstream whose remote name contains a slash', async () => {gitExecFileAsyncMock.mockImplementation((args: string[]) => {if (args[0] === 'symbolic-ref') {- return Promise.resolve({ stdout: 'feature\n' })+ return Promise.resolve({ stdout: 'refs/heads/feature\n' })}if (args[0] === 'rev-parse' && args.includes('HEAD@{u}')) {return Promise.resolve({ stdout: 'origin/team/feature\n' })diff --git a/src/main/ipc/worktree-push-target-setup.test.ts b/src/main/ipc/worktree-push-target-setup.test.tsindex 338bfe448e3..b1b7f4b0f6f 100644--- a/src/main/ipc/worktree-push-target-setup.test.ts+++ b/src/main/ipc/worktree-push-target-setup.test.ts@@ -28,8 +28,8 @@ function makeRepoExec(checkedOutBranch = 'local-branch'): ExecMock {return vi.fn<GitRemoteExec>(async (args: string[]) => {- if (args[0] === 'symbolic-ref' && args[1] === '--short' && args[2] === 'HEAD') {- return { stdout: `${checkedOutBranch}\n`, stderr: '' }+ if (args[0] === 'symbolic-ref' && args[1] === '--quiet' && args[2] === 'HEAD') {+ return { stdout: `refs/heads/${checkedOutBranch}\n`, stderr: '' }}if (args[0] === 'remote' && args.length === 1) {return { stdout: Object.keys(remotes).join('\n'), stderr: '' }diff --git a/src/main/ipc/worktree-push-target-setup.ts b/src/main/ipc/worktree-push-target-setup.tsindex 75b863fc07d..cf74380786e 100644--- a/src/main/ipc/worktree-push-target-setup.ts+++ b/src/main/ipc/worktree-push-target-setup.ts@@ -1,5 +1,6 @@import type { GitPushTarget } from '../../shared/worktree/types'import { findGitRemoteNameByFetchUrl } from '../../shared/git-remote-url-index'+import { getGitCurrentBranchName } from '../../shared/git-current-branch'import { sameGitHubRemoteUrl, type GitRemoteExec } from './worktree-push-target-cleanup'import {buildNarrowForkFetchRefspec,@@ -42,13 +43,7 @@ export async function resolveCheckedOutBranchName(execGit: GitRemoteExec,repoPath: string): Promise<string | null> {- try {- const { stdout } = await execGit(['symbolic-ref', '--short', 'HEAD'], repoPath)- const branch = stdout.trim()- return branch.length > 0 ? branch : null- } catch {- return null- }+ return getGitCurrentBranchName((args) => execGit(args, repoPath))}export async function ensureUniqueRemoteName(diff --git a/src/main/ipc/worktree-remote-push-target-materialization.test.ts b/src/main/ipc/worktree-remote-push-target-materialization.test.tsindex a69bdf39b23..63052a86e7a 100644--- a/src/main/ipc/worktree-remote-push-target-materialization.test.ts+++ b/src/main/ipc/worktree-remote-push-target-materialization.test.ts@@ -55,7 +55,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('no such section')}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -73,7 +73,7 @@ describe('materializeWorktreePushTargetRemote', () => {`+refs/heads/${target.branchName}*:refs/remotes/${FORK_REMOTE}/${target.branchName}*`])expect(calls).toContainEqual(['config', `remote.${FORK_REMOTE}.tagOpt`, '--no-tags'])- expect(calls).toContainEqual(['symbolic-ref', '--short', 'HEAD'])+ expect(calls).toContainEqual(['symbolic-ref', '--quiet', 'HEAD'])expect(calls).toContainEqual(['branch','--set-upstream-to',@@ -93,7 +93,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('no such section')}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -111,7 +111,7 @@ describe('materializeWorktreePushTargetRemote', () => {],['config', `remote.${FORK_REMOTE}.tagOpt`, '--no-tags'],['rev-parse', '--verify', '--quiet', `refs/remotes/${FORK_REMOTE}/contributor/fix`],- ['symbolic-ref', '--short', 'HEAD'],+ ['symbolic-ref', '--quiet', 'HEAD'],['branch', '--set-upstream-to', `${FORK_REMOTE}/contributor/fix`, 'contributor/fix']])})@@ -125,7 +125,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('no such section')}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -181,7 +181,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('unknown revision')}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -227,7 +227,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('no such section')}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -264,7 +264,7 @@ describe('materializeWorktreePushTargetRemote', () => {throw new Error('no such section')}if (args[0] === 'symbolic-ref') {- return { stdout: 'joiner/branch\n', stderr: '' }+ return { stdout: 'refs/heads/joiner/branch\n', stderr: '' }}return { stdout: '', stderr: '' }})@@ -398,7 +398,7 @@ describe('materializeWorktreePushTargetRemote', () => {return { stdout: `${FORK_URL}\n`, stderr: '' }}if (args[0] === 'symbolic-ref') {- return { stdout: 'contributor/fix\n', stderr: '' }+ return { stdout: 'refs/heads/contributor/fix\n', stderr: '' }}return { stdout: '', stderr: '' }})diff --git a/src/shared/git-current-branch.ts b/src/shared/git-current-branch.tsnew file mode 100644index 00000000000..face9fbe003--- /dev/null+++ b/src/shared/git-current-branch.ts@@ -0,0 +1,12 @@+export async function getGitCurrentBranchName(+ runGit: (args: string[]) => Promise<{ stdout: string }>+): Promise<string | null> {+ try {+ const { stdout } = await runGit(['symbolic-ref', '--quiet', 'HEAD'])+ const ref = stdout.trim()+ const prefix = 'refs/heads/'+ return ref.startsWith(prefix) ? ref.slice(prefix.length) || null : null+ } catch {+ return null+ }+}diff --git a/src/shared/git-effective-upstream.ts b/src/shared/git-effective-upstream.tsindex 2b0c486c033..3ebc70452a7 100644--- a/src/shared/git-effective-upstream.ts+++ b/src/shared/git-effective-upstream.ts@@ -8,6 +8,7 @@ import { splitRemoteBranchName } from './git-remote-branch-name'import { parseGitRevListAheadBehindCounts } from './git-rev-list-output'import { iterateProcessOutputLines } from './process-output-field-scanner'import { createGitConfigSnapshotRunner } from './git-config-snapshot-runner'+import { getGitCurrentBranchName } from './git-current-branch'export { gitRefTargetsBranchName, splitRemoteBranchName } from './git-remote-branch-name'@@ -61,16 +62,6 @@ async function splitRemoteBranchNameByKnownRemote(}}-async function getCurrentBranchName(runGit: GitCommandRunner): Promise<string | null> {- try {- const { stdout } = await runGit(['symbolic-ref', '--quiet', '--short', 'HEAD'])- const branchName = stdout.trim()- return branchName || null- } catch {- return null- }-}-async function getConfiguredUpstream(runGit: GitCommandRunner): Promise<EffectiveGitUpstream | null> {@@ -183,7 +174,7 @@ export async function resolveEffectiveGitUpstream(execGit: GitCommandRunner): Promise<EffectiveGitUpstream | null> {const runGit = createGitConfigSnapshotRunner(execGit)- return resolveEffectiveGitUpstreamForBranch(runGit, await getCurrentBranchName(runGit))+ return resolveEffectiveGitUpstreamForBranch(runGit, await getGitCurrentBranchName(runGit))}export async function getEffectiveGitUpstreamStatus(@@ -191,7 +182,7 @@ export async function getEffectiveGitUpstreamStatus(getBehindCommitsArePatchEquivalent?: (upstreamName: string) => Promise<boolean>): Promise<GitUpstreamStatus> {const runGit = createGitConfigSnapshotRunner(execGit)- const currentBranchName = await getCurrentBranchName(runGit)+ const currentBranchName = await getGitCurrentBranchName(runGit)const upstream = await resolveEffectiveGitUpstreamForBranch(runGit, currentBranchName)if (!upstream) {const hasConfiguredPushTarget = currentBranchNamediff --git a/src/shared/git-history.test.ts b/src/shared/git-history.test.tsindex 4f370f5cc28..b3de54bd0a6 100644--- a/src/shared/git-history.test.ts+++ b/src/shared/git-history.test.ts@@ -59,7 +59,7 @@ function createHistoryExecutor(limitRecords = 2): {return { stdout: `${REMOTE_OID}\n` }}if (command === 'symbolic-ref') {- return { stdout: 'feature\n' }+ return { stdout: 'refs/heads/feature\n' }}if (command === 'for-each-ref') {return { stdout: 'refs/remotes/origin/feature\0origin/feature\n' }@@ -225,7 +225,7 @@ describe('git history loader', () => {return { stdout: 'refs/remotes/origin/main\n' }}if (command === 'symbolic-ref') {- return { stdout: 'old-workspace\n' }+ return { stdout: 'refs/heads/old-workspace\n' }}if (command === 'for-each-ref') {return { stdout: 'refs/remotes/origin/main\0origin/main\n' }@@ -317,7 +317,7 @@ describe('symbolic full-name resolution', () => {return { stdout: `${HEAD_OID}\n` }}if (args[0] === 'symbolic-ref') {- return { stdout: 'main\n' }+ return { stdout: 'refs/heads/main\n' }}if (args[0] === 'for-each-ref' || args[0] === 'merge-base') {return { stdout: '' }diff --git a/src/shared/git-history.ts b/src/shared/git-history.tsindex c0b0d1af127..28ef542d26a 100644--- a/src/shared/git-history.ts+++ b/src/shared/git-history.ts@@ -12,6 +12,7 @@ import {type GitHistoryOptions,type GitHistoryResult} from './git-history-types'+import { getGitCurrentBranchName } from './git-current-branch'export type {GitHistoryExecutor,@@ -93,22 +94,17 @@ async function resolveCurrentRef(cwd: string,headOid: string): Promise<{ currentRef: GitHistoryItemRef; branchName: string | null }> {- try {- const { stdout } = await git(['symbolic-ref', '--quiet', '--short', 'HEAD'], cwd)- const branchName = stdout.trim()- if (branchName) {- return {- branchName,- currentRef: {- id: `refs/heads/${branchName}`,- name: branchName,- revision: headOid,- category: 'branches'- }+ const branchName = await getGitCurrentBranchName((args) => git(args, cwd))+ if (branchName) {+ return {+ branchName,+ currentRef: {+ id: `refs/heads/${branchName}`,+ name: branchName,+ revision: headOid,+ category: 'branches'}}- } catch {- // Detached HEAD.}return {diff --git a/src/shared/git-push-target-resolution.ts b/src/shared/git-push-target-resolution.tsindex 5b7031c4414..f35505d17b6 100644--- a/src/shared/git-push-target-resolution.ts+++ b/src/shared/git-push-target-resolution.ts@@ -2,6 +2,7 @@ import type { GitCommandRunner } from './git-effective-upstream'import { gitRefTargetsBranchOnRemote } from './git-remote-branch-name'import { findGitRemoteNameByFetchUrl } from './git-remote-url-index'import { createGitConfigSnapshotRunner } from './git-config-snapshot-runner'+import { getGitCurrentBranchName } from './git-current-branch'export type ResolvedGitPushTarget = {remote: string@@ -106,8 +107,7 @@ export async function resolveConfiguredGitPushTarget(): Promise<ResolvedGitPushTarget | null> {const runGit = createGitConfigSnapshotRunner(execGit)try {- const { stdout: branchStdout } = await runGit(['symbolic-ref', '--quiet', '--short', 'HEAD'])- const branch = branchStdout.trim()+ const branch = await getGitCurrentBranchName(runGit)if (!branch) {return null}diff --git a/src/shared/git-resolution-config-snapshot.test.ts b/src/shared/git-resolution-config-snapshot.test.tsindex c776050b3d5..a00344cdd2a 100644--- a/src/shared/git-resolution-config-snapshot.test.ts+++ b/src/shared/git-resolution-config-snapshot.test.ts@@ -8,7 +8,7 @@ import { resolveConfiguredGitPushTarget } from './git-push-target-resolution'function createRunner(config = new Map<string, string>(), snapshotFails = false) {return vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n' }+ return { stdout: 'refs/heads/feature\n' }}if (args[0] === 'config' && args[1] === '--list') {if (snapshotFails) {@@ -100,7 +100,7 @@ describe('resolution config snapshots', () => {it('skips config reads when the configured upstream resolves directly', async () => {const runGit = vi.fn(async (args: string[]) => {if (args[0] === 'symbolic-ref') {- return { stdout: 'feature\n' }+ return { stdout: 'refs/heads/feature\n' }}if (args[0] === 'rev-parse') {return { stdout: 'origin/feature\n' }