Skip to content

Commit e6e6f4e

Browse files
committed
Fix for issue #31 to show details for new uninitialized repos
1 parent 51b3019 commit e6e6f4e

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

git/gitRepoStatus.js

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,16 @@ const getGitStatus = async (repoPath) => {
1717
};
1818

1919
let gitRemoteData = "";
20-
let gitBranchList = [];
20+
let gitBranchList = ["NO_BRANCHES"];
2121
let gitCurrentBranch = errorStatus.noActiveBranch;
2222
let gitRemoteHost = "";
2323
let gitRepoName = "";
2424
let gitTotalCommits = "";
2525
let gitLatestCommit = "";
2626
let gitTrackedFiles = "";
2727
let gitTotalTrackedFiles = 0;
28-
let gitAllBranchList = [];
28+
let gitAllBranchList = ["NO_BRANCHES"];
29+
let isGitLogAvailable = false;
2930

3031
const gitRemoteReference = [
3132
"github",
@@ -37,18 +38,21 @@ const getGitStatus = async (repoPath) => {
3738

3839
const currentDir = `cd ${repoPath};`;
3940

40-
let isGitLogAvailable = fs.promises
41+
isGitLogAvailable = await fs.promises
4142
.access(`${repoPath}/.git/logs`)
4243
.then(() => {
4344
isGitLogAvailable = true;
4445
return isGitLogAvailable;
4546
})
4647
.catch((err) => {
47-
console.log(err);
48+
console.log("Not a git repo or a new git repo with no commits!");
49+
// console.log(err);
4850
isGitLogAvailable = false;
4951
return isGitLogAvailable;
5052
});
5153

54+
console.log("Git log available : ", isGitLogAvailable);
55+
5256
// Module to get git remote repo URL
5357

5458
let gitRemotePromise =
@@ -148,6 +152,7 @@ const getGitStatus = async (repoPath) => {
148152
}));
149153

150154
gitBranchList =
155+
isGitLogAvailable &&
151156
gitBranchList.length > 0 &&
152157
gitBranchList
153158
.split("\n")
@@ -160,12 +165,22 @@ const getGitStatus = async (repoPath) => {
160165
})
161166
.filter((entry) => (entry !== "" ? entry : null));
162167

163-
if (gitCurrentBranch.length > 0 && gitCurrentBranch !== "No Active Branch") {
168+
if (
169+
isGitLogAvailable &&
170+
gitCurrentBranch.length > 0 &&
171+
gitCurrentBranch !== "No Active Branch"
172+
) {
164173
gitBranchList = [gitCurrentBranch, ...gitBranchList];
165174
} else {
166175
gitBranchList = errorStatus.noBranch;
167176
}
168177

178+
if (!gitBranchList && gitBranchList.length === 0) {
179+
gitBranchList = errorStatus.noBranch;
180+
}
181+
182+
console.log("GIT BRANCH LIST", gitBranchList);
183+
169184
// Module to get total number of commits to current branch
170185
isGitLogAvailable &&
171186
(await execPromised(`git log --oneline`, {

0 commit comments

Comments
 (0)