Merge branch 'trunk' into 7216

This commit is contained in:
ffalor 2023-05-15 09:57:07 -05:00 committed by GitHub
commit ff991c3c84
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 8 deletions

View file

@ -80,9 +80,6 @@ func mainRun() exitCode {
surveyCore.TemplateFuncsWithColor["color"] = func(style string) string {
switch style {
case "white":
if cmdFactory.IOStreams.ColorSupport256() {
return fmt.Sprintf("\x1b[%d;5;%dm", 38, 242)
}
return ansi.ColorCode("default")
default:
return ansi.ColorCode(style)

View file

@ -86,7 +86,7 @@ func NewCmdSetDefault(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *
}
}
if !opts.IO.CanPrompt() && opts.Repo == nil {
if !opts.ViewMode && !opts.IO.CanPrompt() && opts.Repo == nil {
return cmdutil.FlagErrorf("repository required when not running interactively")
}
@ -119,10 +119,10 @@ func setDefaultRun(opts *SetDefaultOptions) error {
currentDefaultRepo, _ := remotes.ResolvedRemote()
if opts.ViewMode {
if currentDefaultRepo == nil {
fmt.Fprintln(opts.IO.Out, "no default repository has been set; use `gh repo set-default` to select one")
} else {
if currentDefaultRepo != nil {
fmt.Fprintln(opts.IO.Out, displayRemoteRepoName(currentDefaultRepo))
} else if opts.IO.IsStdoutTTY() {
fmt.Fprintln(opts.IO.Out, "no default repository has been set; use `gh repo set-default` to select one")
}
return nil
}

View file

@ -166,7 +166,8 @@ func TestDefaultRun(t *testing.T) {
wantStdout: "no default repository has been set\n",
},
{
name: "view mode no current default",
name: "tty view mode no current default",
tty: true,
opts: SetDefaultOptions{ViewMode: true},
remotes: []*context.Remote{
{
@ -176,6 +177,16 @@ func TestDefaultRun(t *testing.T) {
},
wantStdout: "no default repository has been set; use `gh repo set-default` to select one\n",
},
{
name: "view mode no current default",
opts: SetDefaultOptions{ViewMode: true},
remotes: []*context.Remote{
{
Remote: &git.Remote{Name: "origin"},
Repo: repo1,
},
},
},
{
name: "view mode with base resolved current default",
opts: SetDefaultOptions{ViewMode: true},