@@ -21,6 +21,7 @@ func TestNewCmdSetDefault(t *testing.T) {
2121 tests := []struct {
2222 name string
2323 gitStubs func (* run.CommandStubber )
24+ remotes func () (context.Remotes , error )
2425 input string
2526 output SetDefaultOptions
2627 wantErr bool
@@ -43,11 +44,13 @@ func TestNewCmdSetDefault(t *testing.T) {
4344 output : SetDefaultOptions {Repo : ghrepo .New ("cli" , "cli" )},
4445 },
4546 {
46- name : "invalid repo argument" ,
47- gitStubs : func (cs * run.CommandStubber ) {},
48- input : "some_invalid_format" ,
49- wantErr : true ,
50- errMsg : `expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"` ,
47+ name : "invalid repo argument" ,
48+ gitStubs : func (cs * run.CommandStubber ) {
49+ cs .Register (`git rev-parse --git-dir` , 0 , ".git" )
50+ },
51+ input : "some_invalid_format" ,
52+ wantErr : true ,
53+ errMsg : `given arg is not a valid repo or git remote: expected the "[HOST/]OWNER/REPO" format, got "some_invalid_format"` ,
5154 },
5255 {
5356 name : "view flag" ,
@@ -74,16 +77,56 @@ func TestNewCmdSetDefault(t *testing.T) {
7477 wantErr : true ,
7578 errMsg : "must be run from inside a git repository" ,
7679 },
80+ {
81+ name : "remote name argument" ,
82+ gitStubs : func (cs * run.CommandStubber ) {
83+ cs .Register (`git rev-parse --git-dir` , 0 , ".git" )
84+ },
85+ remotes : func () (context.Remotes , error ) {
86+ return context.Remotes {
87+ {
88+ Remote : & git.Remote {Name : "origin" },
89+ Repo : ghrepo .New ("OWNER" , "REPO" ),
90+ },
91+ }, nil
92+ },
93+ input : "origin" ,
94+ output : SetDefaultOptions {Repo : ghrepo .New ("OWNER" , "REPO" )},
95+ },
96+ {
97+ name : "repo argument despite remote name matching owner/repo" ,
98+ gitStubs : func (cs * run.CommandStubber ) {
99+ cs .Register (`git rev-parse --git-dir` , 0 , ".git" )
100+ },
101+ remotes : func () (context.Remotes , error ) {
102+ return context.Remotes {
103+ {
104+ Remote : & git.Remote {Name : "OWNER/REPO" },
105+ Repo : ghrepo .New ("OTHER" , "REPO" ),
106+ },
107+ }, nil
108+ },
109+ input : "OWNER/REPO" ,
110+ output : SetDefaultOptions {Repo : ghrepo .New ("OWNER" , "REPO" )},
111+ },
77112 }
78113
79114 for _ , tt := range tests {
80115 io , _ , _ , _ := iostreams .Test ()
81116 io .SetStdoutTTY (true )
82117 io .SetStdinTTY (true )
83118 io .SetStderrTTY (true )
119+ remotesFunc := tt .remotes
120+ if remotesFunc == nil {
121+ remotesFunc = func () (context.Remotes , error ) {
122+ return context.Remotes {}, nil
123+ }
124+ }
125+
84126 f := & cmdutil.Factory {
85127 IOStreams : io ,
86128 GitClient : & git.Client {GitPath : "/fake/path/to/git" },
129+ Remotes : remotesFunc ,
87130 }
88131
89132 var gotOpts * SetDefaultOptions
0 commit comments