Skip to content

Commit 2ab32d8

Browse files
committed
Merge pull request #18 from neel1996/branchlist-enhance
1 parent ac2a87c commit 2ab32d8

File tree

5 files changed

+96
-5
lines changed

5 files changed

+96
-5
lines changed

git/gitBranchDeleteApi.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { exec } = require("child_process");
2+
const fs = require("fs");
3+
const util = require("util");
4+
const execPromised = util.promisify(exec);
5+
6+
const fetchRepopath = require("../global/fetchGitRepoPath");
7+
8+
const gitDeleteBranchApi = async (repoId, branchName, forceFlag) => {
9+
let commandString = "";
10+
if (forceFlag) {
11+
commandString = `git branch -D ${branchName}`;
12+
} else {
13+
commandString = `git branch -d ${branchName}`;
14+
}
15+
16+
return execPromised(commandString, {
17+
cwd: fetchRepopath.getRepoPath(repoId),
18+
windowsHide: true,
19+
})
20+
.then(({ stdout, stderr }) => {
21+
if (stdout && !stderr) {
22+
console.log(stdout);
23+
return {
24+
status: "BRANCH_DELETE_SUCCESS",
25+
deletionResponse: stdout.trim().split("\n"),
26+
};
27+
} else {
28+
console.log(stderr);
29+
if (stderr.includes("Error")) {
30+
return {
31+
status: "BRANCH_DELETE_FAILED",
32+
};
33+
} else {
34+
return {
35+
status: "BRANCH_DELETE_SUCCESS",
36+
};
37+
}
38+
}
39+
})
40+
.catch((err) => {
41+
console.log(err);
42+
return {
43+
status: "BRANCH_DELETE_FAILED",
44+
};
45+
});
46+
};
47+
48+
module.exports.gitDeleteBranchApi = gitDeleteBranchApi;

git/gitRepoStatus.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const getGitStatus = async (repoPath) => {
1717
let gitLatestCommit = "";
1818
let gitTrackedFiles = "";
1919
let gitTotalTrackedFiles = 0;
20+
let gitAllBranchList = [];
2021

2122
const gitRemoteReference = [
2223
"github",
@@ -97,6 +98,31 @@ const getGitStatus = async (repoPath) => {
9798
gitRemoteHost = "No Remote Host Set";
9899
}
99100

101+
//Module to get all branch list
102+
gitAllBranchList =
103+
isGitLogAvailable &&
104+
(await execPromised(`git branch --all`, {
105+
cwd: repoPath,
106+
windowsHide: true,
107+
})
108+
.then((res) => {
109+
const { stdout, stderr } = res;
110+
if (stdout && !stderr) {
111+
let localBranchList = stdout.trim().split("\n");
112+
localBranchList = localBranchList.map((branch) => {
113+
return branch;
114+
});
115+
return localBranchList;
116+
} else {
117+
console.log(stderr);
118+
return [];
119+
}
120+
})
121+
.catch((err) => {
122+
console.log(err);
123+
return [];
124+
}));
125+
100126
// Module to get all available branches
101127
gitBranchList =
102128
isGitLogAvailable &&
@@ -163,7 +189,7 @@ const getGitStatus = async (repoPath) => {
163189
//Module to get latest git commit
164190

165191
isGitLogAvailable &&
166-
(await execPromised(`git log -1 --oneline`, {
192+
(await execPromised(`git log -1 --oneline --pretty=format:"%s"`, {
167193
cwd: repoPath,
168194
windowsHide: true,
169195
}).then((res) => {
@@ -282,6 +308,7 @@ const getGitStatus = async (repoPath) => {
282308
gitTrackedFiles,
283309
gitFileBasedCommit,
284310
gitTotalTrackedFiles,
311+
gitAllBranchList,
285312
};
286313

287314
console.log(gitRepoDetails);

global/globalAPIHandler.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const {
4949
settingsGetPortDetails,
5050
settingsUpdatePortDetail,
5151
gitAddRemoteRepoApi,
52+
gitDeleteBranchApi,
5253
} = require("./globalFunctionStore");
5354

5455
app.use(
@@ -154,6 +155,10 @@ app.use(
154155
const { repoId, remoteName, remoteUrl } = args;
155156
return gitAddRemoteRepoApi(repoId, remoteName, remoteUrl);
156157
},
158+
deleteBranch: (args) => {
159+
const { repoId, branchName, forceFlag } = args;
160+
return gitDeleteBranchApi(repoId, branchName, forceFlag);
161+
},
157162
},
158163
})
159164
);

global/globalFunctionStore.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const { gitCommitChangesApi } = require("../git/gitCommitChangesAPI");
1313
const { gitPushToRemoteApi } = require("../git/gitPushToRemoteAPI");
1414
const { gitStageItem } = require("../git/gitStageItem");
1515
const { gitAddRemoteApi } = require("../git/gitAddRemoteApi");
16+
const { gitDeleteBranchApi } = require("../git/gitBranchDeleteApi");
1617
const {
1718
fetchDatabaseFile,
1819
fetchRepoDetails,
@@ -245,12 +246,15 @@ module.exports.gitPullFromRemote = gitPullFromRemote = async (
245246
return await gitPullApi(repoId, remoteUrl, remoteBranch);
246247
};
247248

248-
module.exports.deleteRepo = deleteRepo = async (
249+
module.exports.gitDeleteBranchApi = gitDeleteBranchFunction = async (
249250
repoId,
250-
name,
251-
pathName,
252-
time
251+
branchName,
252+
forceFlag
253253
) => {
254+
return gitDeleteBranchApi(repoId, branchName, forceFlag);
255+
};
256+
257+
module.exports.deleteRepo = deleteRepo = async (repoId) => {
254258
return await deleteRepoApi(repoId);
255259
};
256260

global/gqlGlobalAPISchema.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const globalAPISchema = new buildSchema(
5757
gitRemoteData: String
5858
gitRepoName: String
5959
gitBranchList: [String]
60+
gitAllBranchList: [String]
6061
gitCurrentBranch: String
6162
gitRemoteHost: String
6263
gitTotalCommits: Int
@@ -108,6 +109,7 @@ const globalAPISchema = new buildSchema(
108109
updateRepoDataFile(newDbFile: String!): String!
109110
deleteRepo(repoId: String!): deleteRepoStatus!
110111
addRemoteRepo(repoId: String!, remoteName: String!, remoteUrl: String!): String!
112+
deleteBranch(repoId: String!, branchName: String!, forceFlag: Boolean!): deleteBranchStatus!
111113
}
112114
113115
type gitFetchStatus{
@@ -125,6 +127,11 @@ const globalAPISchema = new buildSchema(
125127
repoId: String
126128
}
127129
130+
type deleteBranchStatus{
131+
status: String!,
132+
deletionResponse: String
133+
}
134+
128135
schema{
129136
query: GitConvexAPI
130137
mutation: GitConvexMutation

0 commit comments

Comments
 (0)