diff --git a/bin/add.mjs b/bin/add.mjs index 3d02160..cd47ea1 100644 --- a/bin/add.mjs +++ b/bin/add.mjs @@ -1,3 +1,4 @@ + import fs from "fs"; import { workingDir, @@ -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; }, {}); diff --git a/bin/commit.mjs b/bin/commit.mjs index 8cfbcfc..f688bd1 100644 --- a/bin/commit.mjs +++ b/bin/commit.mjs @@ -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 = []; @@ -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) => { @@ -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; }, []); diff --git a/bin/init.mjs b/bin/init.mjs index 99f026b..9b7663e 100644 --- a/bin/init.mjs +++ b/bin/init.mjs @@ -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, @@ -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(); diff --git a/bin/status.mjs b/bin/status.mjs index f259dc0..1edc14d 100644 --- a/bin/status.mjs +++ b/bin/status.mjs @@ -1,3 +1,5 @@ +//damn its a modern code + import fs from "fs"; import { workingDir, @@ -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, @@ -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); } diff --git a/package.json b/package.json index 206b015..6fdc93d 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/src/one.txt b/src/one.txt index 303ff98..a56cfa1 100644 --- a/src/one.txt +++ b/src/one.txt @@ -1 +1,2 @@ -first file +m,wsdk.skdskldswlkdwsksxkasc;lacn;wvliwrlvwrfirst file +hahahaa diff --git a/src/two/four.txt b/src/two/four.txt deleted file mode 100644 index 02f7874..0000000 --- a/src/two/four.txt +++ /dev/null @@ -1 +0,0 @@ -fourth file