fix(core): Support branches containing slashes in source control (#10109)

This commit is contained in:
Iván Ovejero 2024-07-22 13:21:56 +02:00 committed by GitHub
parent b267eb0467
commit 03a833db51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 1 deletions

View file

@ -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']);
});
});
});

View file

@ -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();