fix: fetch remote branch before checkout in update-copilot-dependency workflow#1088
Conversation
…ale info error Agent-Logs-Url: https://github.com/github/copilot-sdk/sessions/f1827486-b704-48bd-851e-bd6584dd6ae7 Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes re-run failures in the “Update @github/copilot Dependency” workflow where git push --force-with-lease can be rejected due to stale/missing remote-tracking information for an already-existing remote branch.
Changes:
- Fetch the target remote branch before checkout in the existing-branch path.
- Reset the local branch to
origin/$BRANCHinstead ofHEADwhen the remote branch is detected.
Show a summary per file
| File | Description |
|---|---|
.github/workflows/update-copilot-dependency.yml |
Attempts to ensure up-to-date remote-tracking refs before force-with-lease pushes during dependency update PR automation. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 2
| if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then | ||
| git fetch origin "$BRANCH" |
There was a problem hiding this comment.
git rev-parse --verify "origin/$BRANCH" only checks for a local remote-tracking ref. On a fresh Actions checkout this ref typically won’t exist for non-default branches, so this condition can still be false even when the remote branch exists—meaning the new git fetch origin "$BRANCH" never runs and --force-with-lease can remain stale. Consider checking remote existence via git ls-remote --exit-code --heads origin "$BRANCH" (or attempting an explicit refspec fetch and branching on its exit code), then fetching +refs/heads/$BRANCH:refs/remotes/origin/$BRANCH to ensure the tracking ref is populated/updated.
| if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then | |
| git fetch origin "$BRANCH" | |
| if git ls-remote --exit-code --heads origin "$BRANCH" >/dev/null 2>&1; then | |
| git fetch origin "+refs/heads/$BRANCH:refs/remotes/origin/$BRANCH" |
| git checkout "$BRANCH" | ||
| git reset --hard HEAD | ||
| git reset --hard "origin/$BRANCH" |
There was a problem hiding this comment.
git reset --hard "origin/$BRANCH" will discard the dependency/codegen changes produced by the earlier workflow steps (since this runs after the update/format steps). If the intent is only to refresh remote-tracking info for --force-with-lease, avoid a hard reset here; alternatively stash changes before switching/resetting and re-apply them, or move the branch checkout/reset logic earlier (before modifications are made).
git push --force-with-leasefails with "stale info" when the workflow re-runs against an already-existing remote branch, because the local remote-tracking ref is never populated before the push.Changes
.github/workflows/update-copilot-dependency.yml: In the existing-branch path, addgit fetch origin "$BRANCH"before checkout and reset toorigin/$BRANCH(instead ofHEAD) so--force-with-leasehas accurate tracking info.Original prompt
This pull request was created from Copilot chat.