@@ -3,7 +3,7 @@ import { GitCli } from '.'
33import { Command , Flag } from './constants'
44import { getOptions } from './options'
55import { typeCheckCommands } from '..'
6- import { cleanUpBranchName , trimAndSplit } from '../../util/stdout'
6+ import { trimAndSplit } from '../../util/stdout'
77import { isDirectory } from '../../fileSystem'
88
99export const autoRegisteredCommands = {
@@ -25,25 +25,20 @@ export class GitReader extends GitCli {
2525 )
2626
2727 public async hasChanges ( cwd : string ) {
28- const options = getOptions (
29- cwd ,
30- Command . DIFF ,
31- Flag . NAME_ONLY ,
32- Flag . RAW_WITH_NUL
33- )
28+ const options = getOptions ( {
29+ args : [ Command . DIFF , Flag . NAME_ONLY , Flag . RAW_WITH_NUL ] ,
30+ cwd
31+ } )
3432 const output = await this . executeProcess ( options )
3533
3634 return ! ! output
3735 }
3836
3937 public async hasNoCommits ( cwd : string ) {
40- const options = getOptions (
41- cwd ,
42- Command . REV_LIST ,
43- Flag . NUMBER ,
44- '1' ,
45- Flag . ALL
46- )
38+ const options = getOptions ( {
39+ args : [ Command . REV_LIST , Flag . NUMBER , '1' , Flag . ALL ] ,
40+ cwd
41+ } )
4742 const output = await this . executeProcess ( options )
4843
4944 return ! output
@@ -54,15 +49,17 @@ export class GitReader extends GitCli {
5449 revision : string ,
5550 revisions : string
5651 ) : Promise < string > {
57- const options = getOptions (
58- cwd ,
59- Command . LOG ,
60- revision ,
61- Flag . PRETTY_FORMAT_COMMIT_MESSAGE ,
62- Flag . SEPARATE_WITH_NULL ,
63- Flag . NUMBER ,
64- revisions
65- )
52+ const options = getOptions ( {
53+ args : [
54+ Command . LOG ,
55+ revision ,
56+ Flag . PRETTY_FORMAT_COMMIT_MESSAGE ,
57+ Flag . SEPARATE_WITH_NULL ,
58+ Flag . NUMBER ,
59+ revisions
60+ ] ,
61+ cwd
62+ } )
6663 try {
6764 return await this . executeProcess ( options )
6865 } catch {
@@ -71,7 +68,7 @@ export class GitReader extends GitCli {
7168 }
7269
7370 public async getRemoteUrl ( cwd : string ) : Promise < string > {
74- const options = getOptions ( cwd , Command . LS_REMOTE , Flag . GET_URL )
71+ const options = getOptions ( { args : [ Command . LS_REMOTE , Flag . GET_URL ] , cwd } )
7572 try {
7673 return await this . executeProcess ( options )
7774 } catch {
@@ -88,7 +85,10 @@ export class GitReader extends GitCli {
8885 }
8986
9087 public async getNumCommits ( cwd : string , branch : string ) {
91- const options = getOptions ( cwd , Command . REV_LIST , Flag . COUNT , branch )
88+ const options = getOptions ( {
89+ args : [ Command . REV_LIST , Flag . COUNT , branch ] ,
90+ cwd
91+ } )
9292 try {
9393 const nbCommits = await this . executeProcess ( options )
9494 return Number . parseInt ( nbCommits )
@@ -98,37 +98,49 @@ export class GitReader extends GitCli {
9898 }
9999
100100 public async getBranches ( cwd : string ) : Promise < string [ ] > {
101- const options = getOptions ( cwd , Command . BRANCH )
101+ const options = getOptions ( {
102+ args : [ Command . BRANCH ] ,
103+ cwd,
104+ env : { LANG : 'en_US.UTF-8' }
105+ } )
102106 try {
103107 const branches = await this . executeProcess ( options )
104- return trimAndSplit ( branches ) . map ( cleanUpBranchName )
108+ return trimAndSplit ( branches ) . map ( branch =>
109+ this . cleanUpBranchName ( branch )
110+ )
105111 } catch {
106112 return [ ]
107113 }
108114 }
109115
110116 public async getCurrentBranch ( cwd : string ) : Promise < string > {
111- const options = getOptions ( cwd , Command . BRANCH )
117+ const options = getOptions ( {
118+ args : [ Command . BRANCH ] ,
119+ cwd,
120+ env : { LANG : 'en_US.UTF-8' }
121+ } )
112122 try {
113123 const branches = await this . executeProcess ( options )
114124 const currentBranch = trimAndSplit ( branches ) . find (
115125 branch => branch . indexOf ( '*' ) === 0
116126 )
117- return ( currentBranch && cleanUpBranchName ( currentBranch ) ) || ''
127+ return ( currentBranch && this . cleanUpBranchName ( currentBranch ) ) || ''
118128 } catch {
119129 return ''
120130 }
121131 }
122132
123133 private async getUntrackedDirectories ( cwd : string ) : Promise < string [ ] > {
124- const options = getOptions (
125- cwd ,
126- Command . LS_FILES ,
127- Flag . OTHERS ,
128- Flag . EXCLUDE_STANDARD ,
129- Flag . DIRECTORY ,
130- Flag . NO_EMPTY_DIRECTORY
131- )
134+ const options = getOptions ( {
135+ args : [
136+ Command . LS_FILES ,
137+ Flag . OTHERS ,
138+ Flag . EXCLUDE_STANDARD ,
139+ Flag . DIRECTORY ,
140+ Flag . NO_EMPTY_DIRECTORY
141+ ] ,
142+ cwd
143+ } )
132144
133145 const output = await this . executeProcess ( options )
134146 return this . getUris ( cwd , trimAndSplit ( output ) ) . filter ( path =>
@@ -137,12 +149,10 @@ export class GitReader extends GitCli {
137149 }
138150
139151 private async getUntrackedFiles ( cwd : string ) : Promise < string [ ] > {
140- const options = getOptions (
141- cwd ,
142- Command . LS_FILES ,
143- Flag . OTHERS ,
144- Flag . EXCLUDE_STANDARD
145- )
152+ const options = getOptions ( {
153+ args : [ Command . LS_FILES , Flag . OTHERS , Flag . EXCLUDE_STANDARD ] ,
154+ cwd
155+ } )
146156
147157 const output = await this . executeProcess ( options )
148158 return this . getUris ( cwd , trimAndSplit ( output ) )
@@ -151,4 +161,11 @@ export class GitReader extends GitCli {
151161 private getUris ( repositoryRoot : string , relativePaths : string [ ] ) {
152162 return relativePaths . map ( path => resolve ( repositoryRoot , path ) )
153163 }
164+
165+ private cleanUpBranchName ( branch : string ) {
166+ return branch
167+ . replace ( '* ' , '' )
168+ . replace ( / \( H E A D \s \w + \s \w + \s / , '' )
169+ . replace ( ')' , '' )
170+ }
154171}
0 commit comments