diff --git a/packages/cli/src/environments/sourceControl/__tests__/source-control-git.service.test.ts b/packages/cli/src/environments/sourceControl/__tests__/source-control-git.service.test.ts new file mode 100644 index 0000000000..145ebe40c0 --- /dev/null +++ b/packages/cli/src/environments/sourceControl/__tests__/source-control-git.service.test.ts @@ -0,0 +1,35 @@ +import { mock } from 'jest-mock-extended'; +import { SourceControlGitService } from '../sourceControlGit.service.ee'; +import { simpleGit } from 'simple-git'; + +const MOCK_BRANCHES = { + all: ['origin/master', 'origin/feature/branch'], + branches: { + 'origin/master': {}, + 'origin/feature/branch': {}, + }, + current: 'master', +}; + +jest.mock('simple-git', () => { + return { + simpleGit: jest.fn().mockImplementation(() => ({ + branch: jest.fn().mockResolvedValue(MOCK_BRANCHES), + })), + }; +}); + +describe('SourceControlGitService', () => { + const sourceControlGitService = new SourceControlGitService(mock(), mock(), mock()); + + beforeAll(() => { + sourceControlGitService.git = simpleGit(); + }); + + describe('getBranches', () => { + it('should support branch names containing slashes', async () => { + const branches = await sourceControlGitService.getBranches(); + expect(branches.branches).toEqual(['master', 'feature/branch']); + }); + }); +}); diff --git a/packages/cli/src/environments/sourceControl/sourceControlGit.service.ee.ts b/packages/cli/src/environments/sourceControl/sourceControlGit.service.ee.ts index aa5fb50559..1904761996 100644 --- a/packages/cli/src/environments/sourceControl/sourceControlGit.service.ee.ts +++ b/packages/cli/src/environments/sourceControl/sourceControlGit.service.ee.ts @@ -244,7 +244,7 @@ export class SourceControlGitService { // Get remote branches const { branches } = await this.git.branch(['-r']); const remoteBranches = Object.keys(branches) - .map((name) => name.split('/')[1]) + .map((name) => name.split('/').slice(1).join('/')) .filter((name) => name !== 'HEAD'); const { current } = await this.git.branch();