Fix PR workspace branch checkout (#4003)
This commit is contained in:
@@ -141,8 +141,13 @@ describe('resolveGitHubPrStartPoint', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('returns a tracking ref and push target when same-repo branch fetch succeeds', async () => {
|
||||
const gitExec = vi.fn(async () => ({ stdout: '', stderr: '' }))
|
||||
it('returns the verified head SHA, branch override, and push target when same-repo branch fetch succeeds', async () => {
|
||||
const gitExec = vi.fn(async (args: string[]) => {
|
||||
if (args[0] === 'rev-parse') {
|
||||
return { stdout: 'abc123\n', stderr: '' }
|
||||
}
|
||||
return { stdout: '', stderr: '' }
|
||||
})
|
||||
|
||||
const result = await resolveGitHubPrStartPoint({
|
||||
repoPath: '/repo-root',
|
||||
@@ -159,7 +164,9 @@ describe('resolveGitHubPrStartPoint', () => {
|
||||
])
|
||||
expect(gitExec).toHaveBeenCalledWith(['rev-parse', '--verify', 'origin/feature/add-feature'])
|
||||
expect(result).toEqual({
|
||||
baseBranch: 'origin/feature/add-feature',
|
||||
baseBranch: 'abc123',
|
||||
headSha: 'abc123',
|
||||
branchNameOverride: 'feature/add-feature',
|
||||
pushTarget: { remoteName: 'origin', branchName: 'feature/add-feature' }
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { GitPushTarget } from '../../shared/types'
|
||||
import type { GitHubPrStartPoint, GitPushTarget } from '../../shared/types'
|
||||
import { isMissingRemoteRefGitError } from '../git/fetch-error-classification'
|
||||
import { getPullRequestPushTarget, getWorkItem } from './client'
|
||||
|
||||
@@ -14,9 +14,7 @@ type ResolveGitHubPrStartPointArgs = {
|
||||
resolveRemote: () => Promise<string>
|
||||
}
|
||||
|
||||
type ResolveGitHubPrStartPointResult =
|
||||
| { baseBranch: string; pushTarget?: GitPushTarget }
|
||||
| { error: string }
|
||||
type ResolveGitHubPrStartPointResult = GitHubPrStartPoint | { error: string }
|
||||
|
||||
export async function resolveGitHubPrStartPoint(
|
||||
args: ResolveGitHubPrStartPointArgs
|
||||
@@ -122,14 +120,21 @@ export async function resolveGitHubPrStartPoint(
|
||||
}
|
||||
|
||||
const remoteRef = `${remote}/${headRefName}`
|
||||
let headSha: string
|
||||
try {
|
||||
await args.gitExec(['rev-parse', '--verify', remoteRef])
|
||||
const { stdout } = await args.gitExec(['rev-parse', '--verify', remoteRef])
|
||||
headSha = stdout.trim()
|
||||
} catch {
|
||||
return { error: `Remote ref ${remoteRef} does not exist after fetch.` }
|
||||
}
|
||||
if (!headSha) {
|
||||
return { error: `Empty SHA resolving PR #${args.prNumber} head.` }
|
||||
}
|
||||
|
||||
return {
|
||||
baseBranch: remoteRef,
|
||||
baseBranch: headSha,
|
||||
headSha,
|
||||
branchNameOverride: headRefName,
|
||||
pushTarget: { remoteName: remote, branchName: headRefName }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user