Skip to content

Commit f30ef1d

Browse files
Updates : Updated the staging area only to add changed files and skip the unchanged file
1 parent 625eebb commit f30ef1d

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

server/Controllers/VCS/index.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const add = async (req: customRequest, res: Response) => {
1010
const { user_id } = req;
1111

1212
const files = await FileModel.find({ room: id }, { fileName: 1, content: 1, file: "$_id", _id: 0 });
13+
const lastCommit = await CommitModel.findOne({ room: id, status: "committed" }).sort({ createdAt: -1 });
1314

1415
if (!files) {
1516
return res.status(200).json({
@@ -20,6 +21,30 @@ const add = async (req: customRequest, res: Response) => {
2021
})
2122
}
2223

24+
let changedFiles;
25+
//check for new file creation, deletion and fileChanges
26+
if (lastCommit) {
27+
changedFiles = files.filter((file: any) => {
28+
const fileInCommit = lastCommit.changes.find((change: any) => change.fileName === file.fileName);
29+
if (!fileInCommit) {
30+
return file;
31+
} else if (fileInCommit.content !== file.content) {
32+
return file;
33+
}
34+
});
35+
} else {
36+
changedFiles = files;
37+
}
38+
39+
if (changedFiles.length === 0) {
40+
return res.status(200).json({
41+
data: null,
42+
message: NO_CHANGES_FOUND,
43+
success: false,
44+
status: 404
45+
})
46+
}
47+
2348
const existingCommit = await CommitModel.findOne({ room: id, status: "staging" });
2449

2550

@@ -33,7 +58,7 @@ const add = async (req: customRequest, res: Response) => {
3358
room: id,
3459
stagedBy: user_id,
3560
status: "staging",
36-
changes: files
61+
changes: changedFiles
3762
});
3863
await newCommit.save();
3964
commitId = newCommit._id;

0 commit comments

Comments
 (0)