Skip to content

Fix pr checkout for agit-based workflows in forgejo#117

Merged
andrew merged 4 commits into
git-pkgs:mainfrom
untitaker:pr-checkout-agit
Jun 8, 2026
Merged

Fix pr checkout for agit-based workflows in forgejo#117
andrew merged 4 commits into
git-pkgs:mainfrom
untitaker:pr-checkout-agit

Conversation

@untitaker

@untitaker untitaker commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

When checking out forgejo PRs that do not have a real head branch (using
agit-based workflow), head.Ref is of the form refs/pull/123/head. This is
not a real branch name and using it for PR checkout will break right now,
because the generic code in internal/cli will try to wrap it in another
generic ref, refs/heads/refs/pull/....

Example PR: https://codeberg.org/forgejo/website/pulls/926

Other forges don't have this concept, and it only breaks on some PRs in
forgejo.

We could handle this case by checking Ref for a prefix within the CLI, but
now we're handling agit-specificities in code that is supposed to be generic.

Ref is currently documented as "branch name". I've changed the doc to point
out that it can be a full ref, and that downstream code just has to handle
that.

If we want to keep Ref being just a branch name, the other option is to make
it optional and add another optional field PullRef that contains a full ref.
This is explored in a commit in this PR, but ultimately reverted since it only
made the model more technically correct with no actual gained capability.

untitaker added 4 commits June 8, 2026 00:02
I encountered this error:

```
$ git cd https://codeberg.org/forgejo/website/pulls/926/files
fatal: couldn't find remote ref refs/heads/refs/pull/926/head
Error: fetching origin/refs/pull/926/head: exit status 128
```

It turned out that the gitea module returns a full git ref
`refs/pull/123` for PRs that don't have a real git branch to check out
to.

This case wasn't properly handled by the generic checkout code.
This reverts commit c8a1070.
@untitaker untitaker marked this pull request as ready for review June 7, 2026 23:04

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean separation between bare branch names and full refs, with the local-branch fallback handling the AGit case well. Routing fork PRs with pull refs through the same-repo path is the right call.

@andrew andrew merged commit 6c6fd94 into git-pkgs:main Jun 8, 2026
4 checks passed
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.

2 participants