-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
53 lines (36 loc) · 1004 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require("fs");
const path = require("path");
const zlib = require("zlib");
const crypto = require("crypto");
const { getCatFile } = require("./cat-file");
const { createGitDirectory } = require("./createDirectory");
const { writeTree } = require("./writeTree");
const { lsTree } = require("./lsTree");
const { createHashObject } = require("./createHash");
const { commitTree } = require("./commitTree");
const command = process.argv[2];
switch (command) {
case "init":
createGitDirectory();
break;
case "cat-file":
getCatFile();
break;
case "hash-object":
createHashObject();
break;
case "ls-tree":
lsTree();
break;
case "write-tree":
process.stdout.write(writeTree());
break;
case "commit-tree":
const treeSha = process.argv[3];
const parent = process.argv[5];
const message = process.argv[7];
commitTree(treeSha, parent, message);
break;
default:
throw new Error(`Unknown command ${command}`);
}