@@ -189,18 +189,16 @@ func TestFetchRemoteRevErrorHandling(t *testing.T) {
189
189
190
190
func TestListingAvailableRemotes (t * testing.T ) {
191
191
type testcase struct {
192
- name string
193
- remotes []string
194
- want []git.Remote
192
+ name string
193
+ want []git.Remote
195
194
}
196
195
197
196
tests := []testcase {
198
197
{
199
198
name : "no remotes" ,
200
199
},
201
200
{
202
- name : "one remote" ,
203
- remotes : []string {"origin" },
201
+ name : "one remote" ,
204
202
want : []git.Remote {
205
203
{
206
204
Name : "origin" ,
@@ -209,8 +207,34 @@ func TestListingAvailableRemotes(t *testing.T) {
209
207
},
210
208
},
211
209
{
212
- name : "two remotes" ,
213
- remotes : []string {"origin" , "another" },
210
+ name : "two branches" ,
211
+ want : []git.Remote {
212
+ {
213
+ Name : "origin" ,
214
+ Branches : []string {"main" , "test" },
215
+ },
216
+ },
217
+ },
218
+ {
219
+ name : "branches with one forward slash" ,
220
+ want : []git.Remote {
221
+ {
222
+ Name : "origin" ,
223
+ Branches : []string {"main" , "test/hi" },
224
+ },
225
+ },
226
+ },
227
+ {
228
+ name : "branches with multiple forward slashes" ,
229
+ want : []git.Remote {
230
+ {
231
+ Name : "origin" ,
232
+ Branches : []string {"main" , "test/hi/one/more/yay" },
233
+ },
234
+ },
235
+ },
236
+ {
237
+ name : "two remotes" ,
214
238
want : []git.Remote {
215
239
{
216
240
Name : "another" ,
@@ -229,14 +253,25 @@ func TestListingAvailableRemotes(t *testing.T) {
229
253
repodir := mkOneCommitRepo (t )
230
254
g := test .NewGitWrapper (t , repodir , false )
231
255
232
- for _ , remote := range tc .remotes {
256
+ for _ , gitRemote := range tc .want {
233
257
258
+ remote := gitRemote .Name
234
259
remoteDir := test .EmptyRepo (t , true )
235
260
err := g .RemoteAdd (remote , remoteDir )
236
261
assert .NoError (t , err )
237
262
238
- err = g .Push (remote , "main" )
239
- assert .NoError (t , err )
263
+ for _ , branch := range gitRemote .Branches {
264
+
265
+ if branch == defaultBranch {
266
+ err = g .Push (remote , branch )
267
+ assert .NoError (t , err )
268
+ continue
269
+ }
270
+
271
+ assert .NoError (t , g .Checkout (branch , true ))
272
+ assert .NoError (t , g .Push (remote , branch ))
273
+ assert .NoError (t , g .Checkout (defaultBranch , false ))
274
+ }
240
275
}
241
276
242
277
gotRemotes , err := g .Remotes ()
@@ -250,8 +285,7 @@ func TestListingAvailableRemotes(t *testing.T) {
250
285
251
286
func TestListRemoteWithMultipleBranches (t * testing.T ) {
252
287
const (
253
- remote = "origin"
254
- defaultBranch = "main"
288
+ remote = "origin"
255
289
)
256
290
257
291
repodir := mkOneCommitRepo (t )
@@ -281,6 +315,8 @@ func TestListRemoteWithMultipleBranches(t *testing.T) {
281
315
assertEqualRemotes (t , got , want )
282
316
}
283
317
318
+ const defaultBranch = "main"
319
+
284
320
func mkOneCommitRepo (t * testing.T ) string {
285
321
repodir := test .EmptyRepo (t , false )
286
322
0 commit comments