@@ -10,6 +10,7 @@ import (
1010
1111 "github.com/google/go-cmp/cmp"
1212 "github.com/google/go-cmp/cmp/cmpopts"
13+
1314 batcheslib "github.com/sourcegraph/sourcegraph/lib/batches"
1415
1516 "github.com/sourcegraph/src-cli/internal/api"
@@ -322,6 +323,70 @@ const testBatchIgnoreInRepos = `{
322323}
323324`
324325
326+ func TestResolveRepositories_RepoWithoutBranch (t * testing.T ) {
327+ spec := & batcheslib.BatchSpec {
328+ On : []batcheslib.OnQueryOrRepository {
329+ {RepositoriesMatchingQuery : "testquery" },
330+ },
331+ }
332+
333+ client , done := mockGraphQLClient (testResolveRepositoriesNoBranch , testBatchIgnoreInReposNoBranch )
334+ defer done ()
335+
336+ svc := & Service {client : client , allowIgnored : false }
337+
338+ repos , err := svc .ResolveRepositories (context .Background (), spec )
339+ if err != nil {
340+ t .Fatalf ("unexpected error: %s" , err )
341+ }
342+ if len (repos ) != 1 {
343+ t .Fatalf ("wrong number of repos. want=%d, have=%d" , 2 , len (repos ))
344+ }
345+ }
346+
347+ const testResolveRepositoriesNoBranch = `{
348+ "data": {
349+ "search": {
350+ "results": {
351+ "results": [
352+ {
353+ "__typename": "Repository",
354+ "id": "UmVwb3NpdG9yeToxMw==",
355+ "name": "bitbucket.sgdev.org/SOUR/automation-testing",
356+ "url": "/bitbucket.sgdev.org/SOUR/automation-testing",
357+ "externalRepository": { "serviceType": "bitbucketserver" },
358+ "defaultBranch": null
359+ },
360+ {
361+ "__typename": "Repository",
362+ "id": "UmVwb3NpdG9yeTo0",
363+ "name": "github.com/sourcegraph/automation-testing",
364+ "url": "/github.com/sourcegraph/automation-testing",
365+ "externalRepository": { "serviceType": "github" },
366+ "defaultBranch": null
367+ },
368+ {
369+ "__typename": "Repository",
370+ "id": "UmVwb3NpdG9yeTo2MQ==",
371+ "name": "gitlab.sgdev.org/sourcegraph/automation-testing",
372+ "url": "/gitlab.sgdev.org/sourcegraph/automation-testing",
373+ "externalRepository": { "serviceType": "gitlab" },
374+ "defaultBranch": { "name": "refs/heads/master", "target": { "oid": "3b79a5d479d2af9cfe91e0aad4e9dddca7278150" } }
375+ }
376+ ]
377+ }
378+ }
379+ }
380+ }
381+ `
382+
383+ const testBatchIgnoreInReposNoBranch = `{
384+ "data": {
385+ "repo_0": { "results": { "results": [] } }
386+ }
387+ }
388+ `
389+
325390func TestService_FindDirectoriesInRepos (t * testing.T ) {
326391 client , done := mockGraphQLClient (testFindDirectoriesInRepos )
327392 defer done ()
0 commit comments