Skip to content

Commit 80c0058

Browse files
feat: use git rev-parse
1 parent 77a9e7f commit 80c0058

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

__tests__/git-helper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ describe('GitHelper', () => {
4343
});
4444

4545
it('should get current branch name', async() => {
46-
setChildProcessParams({stdout: ' master\n* test-branch\n develop'});
46+
setChildProcessParams({stdout: 'test-branch'});
4747
expect(await helper.getCurrentBranchName(workDir)).toBe('test-branch');
4848
});
4949
});

src/git-helper.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ export default class GitHelper {
125125
if (!isCloned(workDir)) {
126126
return '';
127127
}
128-
// eslint-disable-next-line no-magic-numbers
129-
return (await this.runCommand(workDir, {command: 'git branch', args: ['-a']}))[0].stdout.find(branch => branch.startsWith('*'))?.slice(2).trim() ?? '';
128+
return (await this.runCommand(workDir, {command: 'git rev-parse', args: ['--abbrev-ref', 'HEAD']}))[0].stdout[0]?.trim() ?? '';
130129
};
131130

132131
/**

0 commit comments

Comments
 (0)