fix(pr): keep targeting the base repository after a fork PR checkout

Repository discovery preferred the current branch's upstream remote,
which for a fork pull request is the pulls/<owner>/<repo> remote that
pr checkout adds, so every later command targeted the fork. pr checkout
now records the pull request number and base remote in
branch.<name>.tea-pr and branch.<name>.tea-base-remote, discovery
honors the recorded base remote, and it skips pulls/* head remotes.

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-11 21:47:06 +02:00
1 parent 59bae60926
commit 299428bf10
5 files changed
+50 -7

No files matched your search

+14
View File
@@ -7,9 +7,16 @@ import (
"context"
"errors"
"fmt"
"strconv"
"strings"
)
// Branch configuration keys that record the pull request and base remote of a checked-out PR branch.
const (
pullNumberKey = "tea-pr"
pullBaseRemoteKey = "tea-base-remote"
)
// CheckoutOptions identifies the base remote and how to check out the PR commit.
type CheckoutOptions struct {
// CredentialArgs contains per-operation Git configuration for the fetch only.
@@ -152,5 +159,12 @@ func CheckoutPull(ctx context.Context, runner Runner, options CheckoutOptions) (
return CheckoutResult{}, fmt.Errorf("checked out the branch, but could not configure tracking: %w", err)
}
}
if !options.Detached {
for _, setting := range [][2]string{{pullNumberKey, strconv.FormatInt(options.Number, 10)}, {pullBaseRemoteKey, options.Remote}} {
if _, err := run("config", "branch."+options.Branch+"."+setting[0], setting[1]); err != nil {
return CheckoutResult{}, fmt.Errorf("checked out the branch, but could not record its pull request: %w", err)
}
}
}
return CheckoutResult{Branch: options.Branch, Commit: commit, Detached: options.Detached, Remote: fetchRemote, Tracking: tracking}, nil
}