Skip to content

Commit 35385b2

Browse files
authored
Use regex to handle detached HEAD branch name in other languages (#4137)
1 parent ef77c8b commit 35385b2

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

extension/src/util/stdout.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { trimAndSplit } from './stdout'
1+
import { cleanUpBranchName, trimAndSplit } from './stdout'
22

33
describe('trimAndSplit', () => {
44
it('should return an empty array given an empty string', () => {
@@ -13,3 +13,15 @@ describe('trimAndSplit', () => {
1313
expect(trimAndSplit('a\nb\nc\n')).toStrictEqual(['a', 'b', 'c'])
1414
})
1515
})
16+
17+
describe('cleanUpBranchName', () => {
18+
it('should clean up a detached head message in English', () => {
19+
const branchName = '(HEAD detached at 786cfcd)'
20+
expect(cleanUpBranchName(branchName)).toStrictEqual('786cfcd')
21+
})
22+
23+
it('should clean up a detached head message in Spanish', () => {
24+
const branchName = '(HEAD desacoplado en 786cfcd)'
25+
expect(cleanUpBranchName(branchName)).toStrictEqual('786cfcd')
26+
})
27+
})

extension/src/util/stdout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ export const trimAndSplit = (stdout: string): string[] =>
66
.filter(Boolean)
77

88
export const cleanUpBranchName = (branch: string) =>
9-
branch.replace('* ', '').replace('(HEAD detached at ', '').replace(')', '')
9+
branch
10+
.replace('* ', '')
11+
.replace(/\(HEAD\s\w+\s\w+\s/, '')
12+
.replace(')', '')

0 commit comments

Comments
 (0)