Skip to content

fix: check git ref directly when pushing signed commits - #4521

Merged
peter-evans merged 1 commit into
mainfrom
peter-evans-laughing-giggle
Nov 10, 2026
Merged

peter-evans merged 1 commit into
mainfrom
peter-evans-laughing-giggle

Conversation

@peter-evans

@peter-evans peter-evans commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4502

Summary

With sign-commits: true, createOrUpdateRef decides whether to create or update the pull request branch using repos.getBranch. The branches API follows branch rename redirects. If a branch was ever renamed from the pull request branch name, GET /repos/{owner}/{repo}/branches/{name} returns the renamed branch instead of a 404. For example, on this repository GET /branches/master returns main.

The action then treats the branch as existing and calls updateRef, which fails with Reference does not exist. The git-based steps don't hit this because git operations never follow rename redirects.

This PR checks the ref directly with git.getRef (GET /repos/{owner}/{repo}/git/ref/heads/{branch}):

  • It checks the same ref that is then created or updated.
  • It isn't affected by rename redirects (GET /git/ref/heads/master returns 404 on this repository).
  • It's an exact match, case-sensitive, and costs the same single API call as before.

Changes

  • src/github-helper.ts: use git.getRef instead of repos.getBranch in createOrUpdateRef.
  • __test__/github-helper.unit.test.ts: add a regression test for a branch name that only resolves through a rename redirect, which now creates the ref; add a test that an existing branch is still updated; switch the existing submodule test's mock from getBranch to getRef.

Alternative considered

Keep repos.getBranch and treat the branch as existing only when data.name === branch. That also fixes the bug, but it infers the answer from the branches API's response rather than checking the ref that's about to change.

dist/ is not updated here; CI regenerates it after merge.

The branches API follows branch rename redirects, so a branch name that was
previously renamed resolves to the renamed branch. This caused the ref to be
reported as existing, and the subsequent updateRef failed with 'Reference does
not exist'. Check the git ref directly instead, which is the same ref that is
then created or updated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@github-actions

Copy link
Copy Markdown
Contributor

Full test suite slash command (repository admin only)

/test repository=peter-evans/create-pull-request ref=peter-evans-laughing-giggle build=true
/test repository=peter-evans/create-pull-request ref=peter-evans-laughing-giggle build=true sign-commits=true

@peter-evans

peter-evans commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner Author

/test repository=peter-evans/create-pull-request ref=peter-evans-laughing-giggle build=true sign-commits=true

Command run output

@peter-evans
peter-evans marked this pull request as ready for review November 10, 2026 12:42
@peter-evans
peter-evans merged commit 77d5650 into main Nov 10, 2026
6 checks passed
sdwilsh pushed a commit to sdwilsh/ansible-playbooks that referenced this pull request Nov 10, 2026
…2130)

##### [\`v8.1.3\`](https://github.com/peter-evans/create-pull-request/releases/tag/v8.1.3)

#### What's Changed

- fix: check git ref directly when pushing signed commits by [@peter-evans](https://github.com/peter-evans) in [#4521](peter-evans/create-pull-request#4521)
- Update distribution by [@actions-bot](https://github.com/actions-bot) in [#4526](peter-evans/create-pull-request#4526)

**Full Changelog**: <peter-evans/create-pull-request@v8.1.2...v8.1.3>

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error: Reference does not exist

2 participants