repoify-js
Version:
Repoify is a custom-built Version Control System (VCS) created as a fun learning project to explore core concepts of version control, file management, and cloud storage integration using modern technologies.
28 lines (21 loc) • 784 B
JavaScript
import fs from "fs";
import path from "path";
import { promisify } from "util";
const readdir = promisify(fs.readdir);
const copyFile = promisify(fs.copyFile);
const revertRepo = async (commitID) => {
const repoPath = path.resolve(process.cwd(), ".VCSBIN");
const commitPath = path.join(repoPath, "commits");
try {
const commitDir = path.join(commitPath, commitID);
const files = await readdir(commitDir);
const parentDir = path.resolve(repoPath, "..");
for (const file of files) {
await copyFile(path.join(commitDir, file), path.join(parentDir, file));
}
console.log(`Commit ${commitID} reverted successfully`);
} catch (error) {
console.error("Unable to revert: ", error);
}
};
export default revertRepo;