fix(github): ensure local branch exists for fork PR checkout#1454
Conversation
|
@jschwxrz is attempting to deploy a commit to the General Action Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR fixes fork PR checkout in the fallback path of
Confidence Score: 4/5
|
| Filename | Overview |
|---|---|
| src/main/services/GitHubService.ts | Removes --detach from gh pr checkout fallback and adds a post-checkout guard that creates a local branch ref via git branch --force if git show-ref shows the ref is missing. Logic is sound; one stale comment and a slightly misleading error message remain. |
Sequence Diagram
sequenceDiagram
participant Caller as githubIpc.ts
participant GHS as GitHubService
participant Git as git (exec)
participant GH as gh CLI
Caller->>GHS: ensurePullRequestBranch(path, prNumber, branchName)
GHS->>Git: git fetch origin refs/pull/N/head:refs/heads/<branch> --force
alt fetch succeeds
Git-->>GHS: ok
else fetch fails (fork PR / no direct access)
Git-->>GHS: error
GHS->>Git: git rev-parse --abbrev-ref HEAD
Git-->>GHS: previousRef
GHS->>GH: gh pr checkout <N> --branch <branch> --force
GH-->>GHS: ok (working tree updated)
GHS->>Git: git show-ref --verify --quiet refs/heads/<branch>
alt ref exists
Git-->>GHS: exit 0
else ref missing (gh/fork edge case)
Git-->>GHS: exit 1
GHS->>Git: git branch --force <branch> HEAD
Git-->>GHS: branch created
end
Note over GHS,Git: finally block
GHS->>Git: git checkout <previousRef> --force
Git-->>GHS: working tree restored
end
GHS-->>Caller: safeBranch (string)
Caller->>GHS: WorktreeService.createWorktreeFromBranch(path, ..., branchName)
GHS->>Git: git worktree add <worktreePath> <branchName>
Git-->>GHS: worktree created
Comments Outside Diff (1)
-
src/main/services/GitHubService.ts, line 900 (link)Stale comment still references
--detachThe comment on line 900 still says
"try gh pr checkout with detach to avoid working tree conflicts", but this PR removes--detachfrom the command below. The comment now describes the opposite of what the code does —gh pr checkoutwithout--detachexplicitly will touch the working tree. The comment should be updated to reflect the new intent.
Last reviewed commit: 60cfd4a
|
Thanks! good catch |
summary:
this ensures downstream worktree creation can reliably use the expected local branch for fork PR review flows.