fix regression in support for detached HEAD state
for gh pr status
This commit is contained in:
parent
28f91cbed8
commit
3bb6983b35
4 changed files with 12 additions and 6 deletions
|
|
@ -116,7 +116,7 @@ func prStatus(cmd *cobra.Command, args []string) error {
|
||||||
repoOverride, _ := cmd.Flags().GetString("repo")
|
repoOverride, _ := cmd.Flags().GetString("repo")
|
||||||
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
|
currentPRNumber, currentPRHeadRef, err := prSelectorForCurrentBranch(ctx, baseRepo)
|
||||||
|
|
||||||
if err != nil && repoOverride == "" && err.Error() != "git: not on any branch" {
|
if err != nil && repoOverride == "" && err != git.ErrNotOnAnyBranch {
|
||||||
return fmt.Errorf("could not query for pull request for current branch: %w", err)
|
return fmt.Errorf("could not query for pull request for current branch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -207,7 +207,11 @@ func (c *fsContext) Branch() (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
currentBranch, err := git.CurrentBranch()
|
currentBranch, err := git.CurrentBranch()
|
||||||
if err != nil {
|
switch err {
|
||||||
|
case nil:
|
||||||
|
case git.ErrNotOnAnyBranch:
|
||||||
|
return "", err
|
||||||
|
default:
|
||||||
return "", fmt.Errorf("could not determine current branch: %w", err)
|
return "", fmt.Errorf("could not determine current branch: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ import (
|
||||||
"github.com/cli/cli/internal/run"
|
"github.com/cli/cli/internal/run"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// ErrNotOnAnyBranch indicates that the users is in detached HEAD state
|
||||||
|
var ErrNotOnAnyBranch = errors.New("git: not on any branch")
|
||||||
|
|
||||||
// Ref represents a git commit reference
|
// Ref represents a git commit reference
|
||||||
type Ref struct {
|
type Ref struct {
|
||||||
Hash string
|
Hash string
|
||||||
|
|
@ -64,7 +67,7 @@ func CurrentBranch() (string, error) {
|
||||||
if errors.As(err, &cmdErr) {
|
if errors.As(err, &cmdErr) {
|
||||||
if cmdErr.Stderr.Len() == 0 {
|
if cmdErr.Stderr.Len() == 0 {
|
||||||
// Detached head
|
// Detached head
|
||||||
return "", errors.New("git: not on any branch")
|
return "", ErrNotOnAnyBranch
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,9 +67,8 @@ func Test_CurrentBranch_detached_head(t *testing.T) {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("expected an error")
|
t.Errorf("expected an error")
|
||||||
}
|
}
|
||||||
expectedError := "git: not on any branch"
|
if err != ErrNotOnAnyBranch {
|
||||||
if err.Error() != expectedError {
|
t.Errorf("got unexpected error: %s instead of %s", err, ErrNotOnAnyBranch)
|
||||||
t.Errorf("got unexpected error: %s instead of %s", err.Error(), expectedError)
|
|
||||||
}
|
}
|
||||||
if len(cs.Calls) != 1 {
|
if len(cs.Calls) != 1 {
|
||||||
t.Errorf("expected 1 git call, saw %d", len(cs.Calls))
|
t.Errorf("expected 1 git call, saw %d", len(cs.Calls))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue