Skip to content

Commit 0423093

Browse files
committed
Fix for issue #30 and created common error status object
1 parent acf0ab5 commit 0423093

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

git/gitRepoStatus.js

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,19 @@ const execPromised = util.promisify(exec);
66
const getGitStatus = async (repoPath) => {
77
console.log("Repo Path : " + repoPath);
88

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+
919
let gitRemoteData = "";
1020
let gitBranchList = [];
11-
let gitCurrentBranch = "No Active Branch";
21+
let gitCurrentBranch = errorStatus.noActiveBranch;
1222
let gitRemoteHost = "";
1323
let gitRepoName = "";
1424
let gitTotalCommits = "";
@@ -77,11 +87,11 @@ const getGitStatus = async (repoPath) => {
7787
if (gitRemotePromise) {
7888
gitRemoteData = gitRemotePromise.join("||");
7989
} else {
80-
gitRemoteData = "NO_REMOTE";
90+
gitRemoteData = errorStatus.noRemote;
8191
}
8292

8393
// Module to get Git actual repo name
84-
if (gitRemoteData && gitRemoteData !== "NO_REMOTE") {
94+
if (gitRemoteData && gitRemoteData !== errorStatus.noRemote) {
8595
let tempSplitLength = gitRemoteData.split("/").length;
8696
gitRepoName = gitRemoteData
8797
.split("/")
@@ -92,9 +102,9 @@ const getGitStatus = async (repoPath) => {
92102
gitRemoteHost = entry;
93103
}
94104
});
95-
} else if (gitRemoteData === "NO_REMOTE") {
105+
} else if (gitRemoteData === errorStatus.noRemote) {
96106
gitRepoName = repoPath.split("/")[currentDir.split("/").length - 1];
97-
gitRemoteHost = "No Remote Host Set";
107+
gitRemoteHost = errorStatus.noRemoteHost;
98108
}
99109

100110
//Module to get all branch list
@@ -153,7 +163,7 @@ const getGitStatus = async (repoPath) => {
153163
if (gitCurrentBranch.length > 0 && gitCurrentBranch !== "No Active Branch") {
154164
gitBranchList = [gitCurrentBranch, ...gitBranchList];
155165
} else {
156-
gitBranchList = ["NO_BRANCH"];
166+
gitBranchList = errorStatus.noBranch;
157167
}
158168

159169
// Module to get total number of commits to current branch
@@ -197,12 +207,12 @@ const getGitStatus = async (repoPath) => {
197207
gitLatestCommit = res.stdout.trim();
198208
} else {
199209
console.log(stderr);
200-
gitLatestCommit = "No Commits in the Current Branch";
210+
gitLatestCommit = errorStatus.noCommits;
201211
}
202212
})
203213
.catch((err) => {
204214
console.log(err);
205-
gitLatestCommit = "No Commits in the Current Branch";
215+
gitLatestCommit = errorStatus.noCommits;
206216
}));
207217

208218
//Module to get all git tracked files
@@ -251,7 +261,7 @@ const getGitStatus = async (repoPath) => {
251261

252262
//Module to fetch commit for each file and folder
253263

254-
var gitFileBasedCommit = ["NO_COMMITS"];
264+
var gitFileBasedCommit = errorStatus.noFileCommits;
255265

256266
gitFileBasedCommit =
257267
isGitLogAvailable &&
@@ -266,12 +276,12 @@ const getGitStatus = async (repoPath) => {
266276
return stdout.trim();
267277
} else {
268278
console.log(stderr);
269-
return ["NO_COMMITS"];
279+
return errorStatus.noFileCommits;
270280
}
271281
})
272282
.catch((err) => {
273283
console.log("Tracked file has been removed!", err);
274-
return ["NO_COMMITS"];
284+
return errorStatus.noFileCommits;
275285
});
276286
})
277287
));
@@ -298,9 +308,9 @@ const getGitStatus = async (repoPath) => {
298308
if (!isGitLogAvailable) {
299309
console.log("Untracked Git Repo!");
300310
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;
304314
gitTotalTrackedFiles = 0;
305315
}
306316

0 commit comments

Comments
 (0)