@@ -6,9 +6,19 @@ const execPromised = util.promisify(exec);
6
6
const getGitStatus = async ( repoPath ) => {
7
7
console . log ( "Repo Path : " + repoPath ) ;
8
8
9
+ const errorStatus = {
10
+ noRemote : "NO_REMOTE" ,
11
+ noRemoteHost : "No Remote Host Set" ,
12
+ noBranch : [ "NO_BRANCH" ] ,
13
+ noActiveBranch : "No active branch" ,
14
+ noCommits : "No Commits in the Current Branch" ,
15
+ noFileCommits : [ "NO_COMMITS" ] ,
16
+ noTrackedFiles : [ "NO_TRACKED_FILES" ] ,
17
+ } ;
18
+
9
19
let gitRemoteData = "" ;
10
20
let gitBranchList = [ ] ;
11
- let gitCurrentBranch = "No Active Branch" ;
21
+ let gitCurrentBranch = errorStatus . noActiveBranch ;
12
22
let gitRemoteHost = "" ;
13
23
let gitRepoName = "" ;
14
24
let gitTotalCommits = "" ;
@@ -77,11 +87,11 @@ const getGitStatus = async (repoPath) => {
77
87
if ( gitRemotePromise ) {
78
88
gitRemoteData = gitRemotePromise . join ( "||" ) ;
79
89
} else {
80
- gitRemoteData = "NO_REMOTE" ;
90
+ gitRemoteData = errorStatus . noRemote ;
81
91
}
82
92
83
93
// Module to get Git actual repo name
84
- if ( gitRemoteData && gitRemoteData !== "NO_REMOTE" ) {
94
+ if ( gitRemoteData && gitRemoteData !== errorStatus . noRemote ) {
85
95
let tempSplitLength = gitRemoteData . split ( "/" ) . length ;
86
96
gitRepoName = gitRemoteData
87
97
. split ( "/" )
@@ -92,9 +102,9 @@ const getGitStatus = async (repoPath) => {
92
102
gitRemoteHost = entry ;
93
103
}
94
104
} ) ;
95
- } else if ( gitRemoteData === "NO_REMOTE" ) {
105
+ } else if ( gitRemoteData === errorStatus . noRemote ) {
96
106
gitRepoName = repoPath . split ( "/" ) [ currentDir . split ( "/" ) . length - 1 ] ;
97
- gitRemoteHost = "No Remote Host Set" ;
107
+ gitRemoteHost = errorStatus . noRemoteHost ;
98
108
}
99
109
100
110
//Module to get all branch list
@@ -153,7 +163,7 @@ const getGitStatus = async (repoPath) => {
153
163
if ( gitCurrentBranch . length > 0 && gitCurrentBranch !== "No Active Branch" ) {
154
164
gitBranchList = [ gitCurrentBranch , ...gitBranchList ] ;
155
165
} else {
156
- gitBranchList = [ "NO_BRANCH" ] ;
166
+ gitBranchList = errorStatus . noBranch ;
157
167
}
158
168
159
169
// Module to get total number of commits to current branch
@@ -197,12 +207,12 @@ const getGitStatus = async (repoPath) => {
197
207
gitLatestCommit = res . stdout . trim ( ) ;
198
208
} else {
199
209
console . log ( stderr ) ;
200
- gitLatestCommit = "No Commits in the Current Branch" ;
210
+ gitLatestCommit = errorStatus . noCommits ;
201
211
}
202
212
} )
203
213
. catch ( ( err ) => {
204
214
console . log ( err ) ;
205
- gitLatestCommit = "No Commits in the Current Branch" ;
215
+ gitLatestCommit = errorStatus . noCommits ;
206
216
} ) ) ;
207
217
208
218
//Module to get all git tracked files
@@ -251,7 +261,7 @@ const getGitStatus = async (repoPath) => {
251
261
252
262
//Module to fetch commit for each file and folder
253
263
254
- var gitFileBasedCommit = [ "NO_COMMITS" ] ;
264
+ var gitFileBasedCommit = errorStatus . noFileCommits ;
255
265
256
266
gitFileBasedCommit =
257
267
isGitLogAvailable &&
@@ -266,12 +276,12 @@ const getGitStatus = async (repoPath) => {
266
276
return stdout . trim ( ) ;
267
277
} else {
268
278
console . log ( stderr ) ;
269
- return [ "NO_COMMITS" ] ;
279
+ return errorStatus . noFileCommits ;
270
280
}
271
281
} )
272
282
. catch ( ( err ) => {
273
283
console . log ( "Tracked file has been removed!" , err ) ;
274
- return [ "NO_COMMITS" ] ;
284
+ return errorStatus . noFileCommits ;
275
285
} ) ;
276
286
} )
277
287
) ) ;
@@ -298,9 +308,9 @@ const getGitStatus = async (repoPath) => {
298
308
if ( ! isGitLogAvailable ) {
299
309
console . log ( "Untracked Git Repo!" ) ;
300
310
gitTotalCommits = 0 ;
301
- gitLatestCommit = "No Commits" ;
302
- gitTrackedFiles = [ "NO_TRACKED_FILES" ] ;
303
- gitFileBasedCommit = "No Changes" ;
311
+ gitLatestCommit = errorStatus . noCommits ;
312
+ gitTrackedFiles = errorStatus . noTrackedFiles ;
313
+ gitFileBasedCommit = errorStatus . noFileCommits ;
304
314
gitTotalTrackedFiles = 0 ;
305
315
}
306
316
0 commit comments