Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

some changes made in the init script #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/add.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

import fs from "fs";
import {
workingDir,
Expand Down Expand Up @@ -58,7 +59,7 @@ const add = () => {
acc[curr] = {
cwd: indexData[curr].cwd,
staging: updatedFiles.find((item) => item.file === curr).hash,
repository: indexData[curr].repository,
repository: indexData[curr].repository
};
return acc;
}, {});
Expand Down
6 changes: 3 additions & 3 deletions bin/commit.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import { type } from "os";

// array of dir (name) and files (children), ordered by bottom-up
const buildTree = (paths) => {
return paths.reduce(
(parent, path, key) => {
return paths.reduce( (parent, path, key) => {
path.split("/").reduce((r, name, i, { length }) => {
if (!r.children) {
r.children = [];
Expand Down Expand Up @@ -52,6 +51,7 @@ const commit = () => {

// console.log(`[commit] - paths`, paths);
const rootTrees = buildTree(paths);
console.log(rootTrees);
// console.log(`[commit] - rootTrees`, rootTrees);

const flattenedTrees = rootTrees.reverse().reduce((acc, curr, key) => {
Expand All @@ -67,7 +67,7 @@ const commit = () => {
} else {
// key so pushed with any previous tree
// TODO clean
acc[key].push(curr);
acc.push(curr);
}
return acc;
}, []);
Expand Down
11 changes: 9 additions & 2 deletions bin/init.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const init = () => {
const files = glob.sync("**/*.txt", { cwd: workingDirectory });

console.log("[init] - build index data");
const indexData = files.reduce((acc, curr) => {
const indexData = files.reduce((acc, curr) => { //acc is the accumulator whreas curr is the current elemnet
const hash = hashFileStats(curr);
acc[curr] = {
cwd: hash,
Expand All @@ -18,11 +18,18 @@ const init = () => {
return acc;
}, {});

let data = {
title: "",
};
console.log("[init] - write .repo");
console.log(workingDirectory);
fs.mkdirSync(`${workingDirectory}/.repo`);
updateIndex(indexData);
fs.writeFileSync(`${workingDirectory}/.repo/HEAD`);
console.log(workingDirectory);
fs.writeFileSync(`${workingDirectory}/.repo/HEAD`,JSON.stringify(data));
console.log(workingDirectory);
fs.mkdirSync(`${workingDirectory}/.repo/objects`);
console.log(workingDirectory);
};

init();
4 changes: 4 additions & 0 deletions bin/status.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//damn its a modern code

import fs from "fs";
import {
workingDir,
Expand All @@ -16,6 +18,7 @@ const status = () => {
const notComitted = [];
const updatedIndexData = Object.keys(indexData).reduce((acc, curr) => {
const hash = hashFileStats(curr);
console.log(hash);
if (hash !== indexData[curr].cwd) {
acc[curr] = {
cwd: hash,
Expand All @@ -27,6 +30,7 @@ const status = () => {
if (indexData[curr].cwd !== indexData[curr].staging) {
notStaged.push(curr);
// THIS OK??
// i like really didnt get this part
} else if (indexData[curr].staging !== indexData[curr].repository) {
notComitted.push(curr);
}
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"author": "",
"license": "ISC",
"dependencies": {
"glob": "^7.1.6",
"jest": "^26.6.3"
"glob": "^7.2.0",
"jest": "^26.6.3",
"zest": "^0.1.3"
}
}
3 changes: 2 additions & 1 deletion src/one.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
first file
m,wsdk.skdskldswlkdwsksxkasc;lacn;wvliwrlvwrfirst file
hahahaa
1 change: 0 additions & 1 deletion src/two/four.txt

This file was deleted.