fix: bundle transport fails when agent commits to HEAD instead of named branch#24317
fix: bundle transport fails when agent commits to HEAD instead of named branch#24317
Conversation
… branch In generate_git_bundle.cjs Strategy 2, when the agent-specified branch doesn't exist locally, create a local branch pointing to HEAD before bundling so the bundle contains refs/heads/<branchName> — which create_pull_request.cjs needs. Also add a defensive fallback in create_pull_request.cjs that uses git bundle list-heads to find available refs when the expected ref is missing. Agent-Logs-Url: https://github.com/github/gh-aw/sessions/dc510197-23d5-4865-87e8-b6726dc060ea Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
remove fallback: create_pull_request.cjs — defensive fallback: If the expected refs/heads/ ref is still absent from the bundle (any future edge case), run git bundle list-heads and use the first available refs/heads/* ref rather than failing immediately. |
Agent-Logs-Url: https://github.com/github/gh-aw/sessions/5d02e19c-08a5-4f7a-99bc-137d1df78d4e Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes git bundle generation when the agent commits on the currently checked-out branch (HEAD) instead of first creating the requested local branch, ensuring the resulting bundle advertises the expected refs/heads/<branchName> ref so create_pull_request.cjs can fetch it reliably.
Changes:
- In
generate_git_bundle.cjsStrategy 2, create/force-update a local branch ref pointing atHEADbefore bundling. - Bundle the commit range as
${GITHUB_SHA}..${branchName}(falling back to${GITHUB_SHA}..HEADif branch creation fails).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| try { | ||
| // Use -f (force) to overwrite any stale local branch from previous runs, | ||
| // since Strategy 1 verified the named branch does not exist as a proper local ref. | ||
| execGitSync(["branch", "-f", branchName, "HEAD"], { cwd }); |
There was a problem hiding this comment.
branchName is user-/agent-controlled and may begin with "-". In git branch -f <branchName> HEAD, a leading dash can be parsed as another option (git requires -- to allow such branch names), which is both a correctness and hardening issue. Elsewhere you already defend against this (e.g., generate_git_patch.cjs uses -- when passing branch names to git fetch). Consider adding -- before branchName here (or using update-ref with an explicit refs/heads/... refname) so branch names can’t be interpreted as flags.
| execGitSync(["branch", "-f", branchName, "HEAD"], { cwd }); | |
| // Use -- so a branch name beginning with "-" is not parsed as another option. | |
| execGitSync(["branch", "-f", "--", branchName, "HEAD"], { cwd }); |
|
Review comments |
…ng dash Agent-Logs-Url: https://github.com/github/gh-aw/sessions/a02ead34-16bc-4fb7-8018-0e89a4453e2c Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
When the Copilot agent commits changes to the current checkout branch (HEAD) rather than first creating the target branch locally, the git bundle is created with
${GITHUB_SHA}..HEAD— bundling the checkout branch ref (e.g.refs/heads/copilot/make-bundle-default-patch-format) instead of the agent-requested ref (refs/heads/jsweep/clean-remove-trigger-label).create_pull_request.cjsthen fails withfatal: couldn't find remote ref refs/heads/jsweep/clean-remove-trigger-label.Changes
generate_git_bundle.cjs: In Strategy 2, before bundling${GITHUB_SHA}..HEAD, create a local branch pointing to HEAD (git branch -f <branchName> HEAD) so the bundle always advertisesrefs/heads/<branchName>: