Skip to content

Commit 6d09500

Browse files
committed
Fixes cli#455 - Hide "current branch" for pr status --repo
1 parent 41a4571 commit 6d09500

2 files changed

Lines changed: 39 additions & 12 deletions

File tree

pkg/cmd/pr/status/status.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -135,19 +135,21 @@ func statusRun(opts *StatusOptions) error {
135135
fmt.Fprintf(out, "Relevant pull requests in %s\n", ghrepo.FullName(baseRepo))
136136
fmt.Fprintln(out, "")
137137

138-
shared.PrintHeader(opts.IO, "Current branch")
139-
currentPR := prPayload.CurrentPR
140-
if currentPR != nil && currentPR.State != "OPEN" && prPayload.DefaultBranch == currentBranch {
141-
currentPR = nil
142-
}
143-
if currentPR != nil {
144-
printPrs(opts.IO, 1, *currentPR)
145-
} else if currentPRHeadRef == "" {
146-
shared.PrintMessage(opts.IO, " There is no current branch")
147-
} else {
148-
shared.PrintMessage(opts.IO, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]")))
138+
if !opts.HasRepoOverride {
139+
shared.PrintHeader(opts.IO, "Current branch")
140+
currentPR := prPayload.CurrentPR
141+
if currentPR != nil && currentPR.State != "OPEN" && prPayload.DefaultBranch == currentBranch {
142+
currentPR = nil
143+
}
144+
if currentPR != nil {
145+
printPrs(opts.IO, 1, *currentPR)
146+
} else if currentPRHeadRef == "" {
147+
shared.PrintMessage(opts.IO, " There is no current branch")
148+
} else {
149+
shared.PrintMessage(opts.IO, fmt.Sprintf(" There is no pull request associated with %s", cs.Cyan("["+currentPRHeadRef+"]")))
150+
}
151+
fmt.Fprintln(out)
149152
}
150-
fmt.Fprintln(out)
151153

152154
shared.PrintHeader(opts.IO, "Created by you")
153155
if prPayload.ViewerCreated.TotalCount > 0 {

pkg/cmd/pr/status/status_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,31 @@ Requesting a code review from you
285285
}
286286
}
287287

288+
func TestPRStatus_blankSlateRepoOverride(t *testing.T) {
289+
http := initFakeHTTP()
290+
defer http.Verify(t)
291+
http.Register(httpmock.GraphQL(`query PullRequestStatus\b`), httpmock.StringResponse(`{"data": {}}`))
292+
293+
output, err := runCommand(http, "blueberries", true, "--repo OWNER/REPO")
294+
if err != nil {
295+
t.Errorf("error running command `pr status`: %v", err)
296+
}
297+
298+
expected := `
299+
Relevant pull requests in OWNER/REPO
300+
301+
Created by you
302+
You have no open pull requests
303+
304+
Requesting a code review from you
305+
You have no pull requests to review
306+
307+
`
308+
if output.String() != expected {
309+
t.Errorf("expected %q, got %q", expected, output.String())
310+
}
311+
}
312+
288313
func TestPRStatus_detachedHead(t *testing.T) {
289314
http := initFakeHTTP()
290315
defer http.Verify(t)

0 commit comments

Comments
 (0)