fix: simplify set-default remote parsing

This commit is contained in:
lif 2026-01-14 18:35:04 +08:00
parent 8de78e6410
commit 1d506f5331
No known key found for this signature in database
GPG key ID: 1C9764AD60647215
2 changed files with 8 additions and 5 deletions

View file

@ -92,10 +92,6 @@ func NewCmdSetDefault(f *cmdutil.Factory, runF func(*SetDefaultOptions) error) *
var err error
opts.Repo, err = ghrepo.FromFullName(args[0])
if err != nil {
if opts.Remotes == nil {
return fmt.Errorf("given arg is not a valid repo or git remote: %w", err)
}
remotes, remoteErr := opts.Remotes()
if remoteErr != nil {
return remoteErr

View file

@ -116,10 +116,17 @@ func TestNewCmdSetDefault(t *testing.T) {
io.SetStdoutTTY(true)
io.SetStdinTTY(true)
io.SetStderrTTY(true)
remotesFunc := tt.remotes
if remotesFunc == nil {
remotesFunc = func() (context.Remotes, error) {
return context.Remotes{}, nil
}
}
f := &cmdutil.Factory{
IOStreams: io,
GitClient: &git.Client{GitPath: "/fake/path/to/git"},
Remotes: tt.remotes,
Remotes: remotesFunc,
}
var gotOpts *SetDefaultOptions