From dc077dc09ba68843e973b715c448e376135e6c67 Mon Sep 17 00:00:00 2001 From: William Martin Date: Mon, 6 Jan 2025 15:44:34 +0100 Subject: [PATCH] Panic if tracking ref can't be reconstructed --- git/objects.go | 12 ------------ pkg/cmd/pr/create/create.go | 16 ++++++++++++---- 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/git/objects.go b/git/objects.go index 924a3059e..ae058a01c 100644 --- a/git/objects.go +++ b/git/objects.go @@ -1,7 +1,6 @@ package git import ( - "fmt" "net/url" "strings" ) @@ -65,17 +64,6 @@ func (r TrackingRef) String() string { return "refs/remotes/" + r.RemoteName + "/" + r.BranchName } -func ParseTrackingRef(text string) (TrackingRef, error) { - parts := strings.SplitN(string(text), "/", 4) - if len(parts) != 4 { - return TrackingRef{}, fmt.Errorf("invalid tracking ref: %s", text) - } - return TrackingRef{ - RemoteName: parts[2], - BranchName: parts[3], - }, nil -} - type Commit struct { Sha string Title string diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index df62dc889..d7032714a 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -555,10 +555,7 @@ func determineTrackingBranch(gitClient *git.Client, remotes ghContext.Remotes, l continue } // Otherwise we can parse the returned ref into a tracking ref and return that - trackingRef, err := git.ParseTrackingRef(r.Name) - if err != nil { - return nil - } + trackingRef := mustParseTrackingRef(r.Name) return &trackingRef } } @@ -566,6 +563,17 @@ func determineTrackingBranch(gitClient *git.Client, remotes ghContext.Remotes, l return nil } +func mustParseTrackingRef(text string) git.TrackingRef { + parts := strings.SplitN(string(text), "/", 4) + if len(parts) != 4 { + panic(fmt.Errorf("invalid tracking ref: %s", text)) + } + return git.TrackingRef{ + RemoteName: parts[2], + BranchName: parts[3], + } +} + func NewIssueState(ctx CreateContext, opts CreateOptions) (*shared.IssueMetadataState, error) { var milestoneTitles []string if opts.Milestone != "" {