Repository: cli/cli
File: pkg/cmd/pr/create/create.go (Go)

Code before:
// pushableRefs. We could go very OOP and have a Fork method on this
// struct that returns a pushableRefs but then we'd need to embed an API client
// and it just seems nice that it is a simple bag of data.
type forkableRefs struct {
	baseRefs

	qualifiedHeadRef shared.QualifiedHeadRef
}

func (r forkableRefs) QualifiedHeadRef() string {
	return r.qualifiedHeadRef.String()
}

func (r forkableRefs) UnqualifiedHeadRef() string {
	return r.qualifiedHeadRef.BranchName()
}

// isSameRef checks if the head and base refs point to the same ref in the same repository.
// For cross-repository PRs (e.g., from a fork), the qualified head ref will contain
// an owner prefix (owner:branch), so even if branch names match, they refer to different repos.
func isSameRef(refs creationRefs) bool {
	// If the qualified head ref contains ":", it's a cross-repo PR (e.g., from a fork)
	// and we should allow it even if branch names are the same
	if strings.Contains(refs.QualifiedHeadRef(), ":") {
		return false
	}
	// Same repository: check if branch names are identical
	return refs.UnqualifiedHeadRef() == refs.BaseRef()
}

// CreateContext stores contextual data about the creation process and is for building up enough
// data to create a pull request.
type CreateContext struct {
	ResolvedRemotes *ghContext.ResolvedRemotes
	PRRefs          creationRefs
	// BaseTrackingBranch is perhaps a slightly leaky abstraction in the presence
	// of PRRefs, but a huge amount of refactoring was done to introduce that struct,
	// and this is a small price to pay for the convenience of not having to do a lot
	// more design.
	BaseTrackingBranch string
	Client             *api.Client
	GitClient          *git.Client
}

func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
	opts := &CreateOptions{
		IO:               f.IOStreams,
		HttpClient:       f.HttpClient,
		GitClient:        f.GitClient,
		Config:           f.Config,
		Remotes:          f.Remotes,

Review comment (suggestion):
Nit: I think we can just stick to the Godoc comment for the func since the function is so small :)


```suggestion
// isSameRef checks if the head and base refs point to the same ref in the same repository.
// For cross-repository PRs (e.g., from a fork), the qualified head ref will contain
// an owner prefix (owner:branch), so even if branch names match, they refer to different repos.
func isSameRef(refs creationRefs) bool {
	if strings.Contains(refs.QualifiedHeadRef(), ":") {
		return false
	}

	return refs.UnqualifiedHeadRef() == refs.BaseRef()
}
```

Code after:
// pushableRefs. We could go very OOP and have a Fork method on this
// struct that returns a pushableRefs but then we'd need to embed an API client
// and it just seems nice that it is a simple bag of data.
type forkableRefs struct {
	baseRefs

	qualifiedHeadRef shared.QualifiedHeadRef
}

func (r forkableRefs) QualifiedHeadRef() string {
	return r.qualifiedHeadRef.String()
}

func (r forkableRefs) UnqualifiedHeadRef() string {
	return r.qualifiedHeadRef.BranchName()
}

// isSameRef checks if the head and base refs point to the same ref in the same repository.
// For cross-repository PRs (e.g., from a fork), the qualified head ref will contain
// an owner prefix (owner:branch), so even if branch names match, they refer to different repos.
func isSameRef(refs creationRefs) bool {
	if strings.Contains(refs.QualifiedHeadRef(), ":") {
		return false
	}
	return refs.UnqualifiedHeadRef() == refs.BaseRef()
}

// CreateContext stores contextual data about the creation process and is for building up enough
// data to create a pull request.
type CreateContext struct {
	ResolvedRemotes *ghContext.ResolvedRemotes
	PRRefs          creationRefs
	// BaseTrackingBranch is perhaps a slightly leaky abstraction in the presence
	// of PRRefs, but a huge amount of refactoring was done to introduce that struct,
	// and this is a small price to pay for the convenience of not having to do a lot
	// more design.
	BaseTrackingBranch string
	Client             *api.Client
	GitClient          *git.Client
}

func NewCmdCreate(f *cmdutil.Factory, runF func(*CreateOptions) error) *cobra.Command {
	opts := &CreateOptions{
		IO:               f.IOStreams,
		HttpClient:       f.HttpClient,
		GitClient:        f.GitClient,
		Config:           f.Config,
		Remotes:          f.Remotes,
		Branch:           f.Branch,
		Browser:          f.Browser,
		Prompter:         f.Prompter,