jvcs 1.7.3 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/controllers/add.js +14 -48
- package/controllers/begin.js +7 -33
- package/controllers/init.js +23 -32
- package/controllers/status.js +70 -126
- package/package.json +1 -1
package/controllers/add.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { getGlobalConfig, checkforjvcs } = require("./utility")
|
|
1
|
+
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility")
|
|
2
2
|
const path = require("path")
|
|
3
3
|
const fssync = require("fs")
|
|
4
4
|
const chalk = require("chalk")
|
|
@@ -15,7 +15,7 @@ async function getFileHash(filepath) {
|
|
|
15
15
|
// load .jvcsignore file
|
|
16
16
|
async function loadIgnorePatterns() {
|
|
17
17
|
const ignorePath = path.join(process.cwd(), ".jvcsignore")
|
|
18
|
-
if
|
|
18
|
+
if(!fssync.existsSync(ignorePath)) return []
|
|
19
19
|
|
|
20
20
|
const content = await fs.readFile(ignorePath, "utf-8")
|
|
21
21
|
return content
|
|
@@ -61,20 +61,26 @@ async function addCmd(paths) {
|
|
|
61
61
|
|
|
62
62
|
if (!paths || paths.length === 0) {
|
|
63
63
|
console.log(chalk.yellow("Please specify files or folders to add."));
|
|
64
|
-
|
|
64
|
+
return
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
67
|
+
if (!checkGlobalConfig()) {
|
|
68
|
+
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
69
|
+
console.log(chalk.green("jvcs --help for help"))
|
|
70
|
+
return
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
let configData = getGlobalConfig()
|
|
68
74
|
|
|
69
75
|
if (!configData) {
|
|
70
76
|
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
71
77
|
console.log(chalk.green("jvcs --help for help"))
|
|
72
|
-
|
|
78
|
+
return
|
|
73
79
|
}
|
|
74
80
|
|
|
75
81
|
if (!checkforjvcs()) {
|
|
76
82
|
console.log(chalk.red("Repository is not initialized or is deleted. Please create it."))
|
|
77
|
-
|
|
83
|
+
return
|
|
78
84
|
}
|
|
79
85
|
|
|
80
86
|
const repoPath = path.join(process.cwd(), ".jvcs")
|
|
@@ -93,43 +99,6 @@ async function addCmd(paths) {
|
|
|
93
99
|
// load ignore patterns
|
|
94
100
|
const ignorePatterns = await loadIgnorePatterns()
|
|
95
101
|
|
|
96
|
-
// -------------------------------------------------------------
|
|
97
|
-
// NEW: Handle Deletions sync before adding new files
|
|
98
|
-
// -------------------------------------------------------------
|
|
99
|
-
let deletionHandledFor = new Set();
|
|
100
|
-
|
|
101
|
-
for (const key of Object.keys(hashData)) {
|
|
102
|
-
const cwdPath = path.join(process.cwd(), key);
|
|
103
|
-
|
|
104
|
-
// Check if the staged file falls under any of the target paths
|
|
105
|
-
let isUnderTarget = false;
|
|
106
|
-
if (paths.length === 1 && paths[0] === ".") {
|
|
107
|
-
isUnderTarget = true;
|
|
108
|
-
} else {
|
|
109
|
-
for (const p of paths) {
|
|
110
|
-
const targetPath = path.resolve(process.cwd(), p);
|
|
111
|
-
const relToTarget = path.relative(targetPath, cwdPath);
|
|
112
|
-
// If it's the exact file or inside the target directory
|
|
113
|
-
if (relToTarget === "" || (!relToTarget.startsWith("..") && !path.isAbsolute(relToTarget))) {
|
|
114
|
-
isUnderTarget = true;
|
|
115
|
-
break;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (isUnderTarget && !fssync.existsSync(cwdPath)) {
|
|
121
|
-
// File was deleted from working directory, remove it from staging
|
|
122
|
-
delete hashData[key];
|
|
123
|
-
const stagedTarget = path.join(staging, key);
|
|
124
|
-
if (fssync.existsSync(stagedTarget)) {
|
|
125
|
-
await fs.rm(stagedTarget);
|
|
126
|
-
}
|
|
127
|
-
console.log(chalk.red(`Removed deleted file: ${key}`));
|
|
128
|
-
deletionHandledFor.add(cwdPath);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
|
|
133
102
|
let targets = []
|
|
134
103
|
if (paths.length === 1 && paths[0] === ".") {
|
|
135
104
|
let rootEntries = await fs.readdir(process.cwd(), { withFileTypes: true })
|
|
@@ -145,10 +114,7 @@ async function addCmd(paths) {
|
|
|
145
114
|
try {
|
|
146
115
|
|
|
147
116
|
if (!fssync.existsSync(target)) {
|
|
148
|
-
|
|
149
|
-
if (!deletionHandledFor.has(target)) {
|
|
150
|
-
console.log(chalk.yellow(`Path not found: ${path.relative(process.cwd(), target)}`));
|
|
151
|
-
}
|
|
117
|
+
console.log(chalk.red(`Path not found: ${target}`))
|
|
152
118
|
continue
|
|
153
119
|
}
|
|
154
120
|
|
|
@@ -189,7 +155,7 @@ async function addCmd(paths) {
|
|
|
189
155
|
}
|
|
190
156
|
}
|
|
191
157
|
catch (error) {
|
|
192
|
-
console.log(chalk.red(`Unexpected error
|
|
158
|
+
console.log(chalk.red(`Unexpected error: ${error.message}`));
|
|
193
159
|
}
|
|
194
160
|
}
|
|
195
161
|
|
package/controllers/begin.js
CHANGED
|
@@ -10,24 +10,14 @@ const fs = require("fs")
|
|
|
10
10
|
|
|
11
11
|
async function beginCmd() {
|
|
12
12
|
|
|
13
|
-
const config = path.join(require("os").homedir(),
|
|
13
|
+
const config = path.join(require("os").homedir(),".jvcs","config.json")
|
|
14
14
|
let isInitialized = false
|
|
15
15
|
let configData = null
|
|
16
|
-
if
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
isInitialized = true
|
|
20
|
-
}
|
|
21
|
-
catch (error) {
|
|
22
|
-
// corrupted file, delete it and force re-login
|
|
23
|
-
try {
|
|
24
|
-
fs.unlinkSync(config)
|
|
25
|
-
}
|
|
26
|
-
catch (e) { }
|
|
27
|
-
isInitialized = false
|
|
28
|
-
}
|
|
16
|
+
if(fs.existsSync(config)) {
|
|
17
|
+
isInitialized = true
|
|
18
|
+
configData = JSON.parse(fs.readFileSync(config,"utf-8"))
|
|
29
19
|
}
|
|
30
|
-
|
|
20
|
+
|
|
31
21
|
if (isInitialized) {
|
|
32
22
|
console.log(chalk.green(`You are already logged in as ${configData.username} (${configData.email})`))
|
|
33
23
|
console.log(chalk.yellow(`[1] Continue \n[2] Logout \nChoose an option (1/2) : `))
|
|
@@ -48,20 +38,14 @@ async function beginCmd() {
|
|
|
48
38
|
}
|
|
49
39
|
])
|
|
50
40
|
|
|
41
|
+
console.log(`Your choice was ${answer.choice}`)
|
|
51
42
|
if (answer.choice === "1") {
|
|
52
43
|
console.log(chalk.green("Continuing as current user..."))
|
|
53
44
|
console.log(chalk.green("jvcs --help for help"))
|
|
54
45
|
}
|
|
55
46
|
else {
|
|
56
47
|
console.log(chalk.green("logging out..."))
|
|
57
|
-
|
|
58
|
-
if (fs.existsSync(config)) {
|
|
59
|
-
fs.unlinkSync(config)
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
catch (error) {
|
|
63
|
-
console.log(chalk.yellow("Warning: Could not remove config file properly."));
|
|
64
|
-
}
|
|
48
|
+
fs.unlinkSync(config)
|
|
65
49
|
console.log(chalk.green("Logged out Successfully"))
|
|
66
50
|
console.log(chalk.green("Please login or signup again (jvcs begin) to use version control system"))
|
|
67
51
|
console.log(chalk.green("jvcs --help for help"))
|
|
@@ -96,14 +80,6 @@ async function beginCmd() {
|
|
|
96
80
|
{
|
|
97
81
|
type: 'input',
|
|
98
82
|
name: 'username',
|
|
99
|
-
validate: function (input) {
|
|
100
|
-
// Ensure no spaces or weird special characters in username
|
|
101
|
-
if (!/^[a-zA-Z0-9_]+$/.test(input)) {
|
|
102
|
-
return "Username can only contain alphanumeric characters and underscores";
|
|
103
|
-
}
|
|
104
|
-
if (input.length < 3) return "Username must be at least 3 characters long";
|
|
105
|
-
return true;
|
|
106
|
-
},
|
|
107
83
|
filter: function (input) {
|
|
108
84
|
return input.trim()
|
|
109
85
|
}
|
|
@@ -163,7 +139,6 @@ async function beginCmd() {
|
|
|
163
139
|
}
|
|
164
140
|
catch (error) {
|
|
165
141
|
console.log(chalk.red(error))
|
|
166
|
-
process.exit(1);
|
|
167
142
|
}
|
|
168
143
|
}
|
|
169
144
|
else {
|
|
@@ -219,7 +194,6 @@ async function beginCmd() {
|
|
|
219
194
|
}
|
|
220
195
|
catch (error) {
|
|
221
196
|
console.log(chalk.red(error))
|
|
222
|
-
process.exit(1);
|
|
223
197
|
}
|
|
224
198
|
}
|
|
225
199
|
}
|
package/controllers/init.js
CHANGED
|
@@ -6,16 +6,16 @@ const { getGlobalConfig, checkGlobalConfig } = require("./utility")
|
|
|
6
6
|
|
|
7
7
|
async function initCmd() {
|
|
8
8
|
|
|
9
|
-
if
|
|
9
|
+
if(!checkGlobalConfig()) {
|
|
10
10
|
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
11
11
|
console.log(chalk.green("jvcs --help for help"))
|
|
12
12
|
return
|
|
13
13
|
}
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
let configData = null
|
|
16
16
|
configData = getGlobalConfig()
|
|
17
|
-
|
|
18
|
-
if
|
|
17
|
+
|
|
18
|
+
if(!configData) {
|
|
19
19
|
console.log(chalk.red("No existing session found. Please login or signup."))
|
|
20
20
|
console.log(chalk.green("jvcs --help for help"))
|
|
21
21
|
return
|
|
@@ -25,45 +25,36 @@ async function initCmd() {
|
|
|
25
25
|
const cwd = process.cwd()
|
|
26
26
|
const home = require("os").homedir()
|
|
27
27
|
|
|
28
|
-
if
|
|
28
|
+
if(cwd === home) {
|
|
29
29
|
console.log(chalk.red("Cannot initialize a repository in your home directory."));
|
|
30
30
|
console.log(chalk.yellow("Hint: navigate to a project folder and run 'jvcs init' there."));
|
|
31
31
|
process.exit(1);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
const repoPath = path.join(cwd,
|
|
35
|
-
if
|
|
34
|
+
const repoPath = path.join(cwd,".jvcs")
|
|
35
|
+
if(fssync.existsSync(repoPath)) {
|
|
36
36
|
console.log(chalk.yellow("Repository already is initialized."));
|
|
37
|
-
process.exit(
|
|
37
|
+
process.exit(1);
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
email: configData.email
|
|
52
|
-
}
|
|
40
|
+
fssync.mkdirSync(repoPath)
|
|
41
|
+
fssync.mkdirSync(path.join(repoPath,"commits"))
|
|
42
|
+
fssync.mkdirSync(path.join(repoPath,"staging"))
|
|
43
|
+
|
|
44
|
+
const config = {
|
|
45
|
+
repoName: path.basename(cwd),
|
|
46
|
+
createdAt: new Date().toISOString(),
|
|
47
|
+
remote: null,
|
|
48
|
+
owner : {
|
|
49
|
+
username: configData.username,
|
|
50
|
+
email: configData.email
|
|
53
51
|
}
|
|
52
|
+
}
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
54
|
+
fssync.writeFileSync(path.join(repoPath, "config.json"), JSON.stringify(config, null, 2))
|
|
55
|
+
fssync.writeFileSync(path.join(repoPath, "HEAD"), "");
|
|
57
56
|
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
catch (error) {
|
|
61
|
-
if (fssync.existsSync(repoPath)) {
|
|
62
|
-
fssync.rmSync(repoPath, { recursive: true, force: true });
|
|
63
|
-
}
|
|
64
|
-
console.log(chalk.red(`Failed to initialize repository: ${error.message}`));
|
|
65
|
-
process.exit(1);
|
|
66
|
-
}
|
|
57
|
+
console.log(chalk.green(`Initialized empty JVCS repository`));
|
|
67
58
|
}
|
|
68
59
|
|
|
69
60
|
module.exports = initCmd
|
package/controllers/status.js
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
+
// Untracked files
|
|
2
|
+
// Files that exist in your working directory (project folder) but have never been added to staging or committed.
|
|
3
|
+
|
|
4
|
+
// Changes to be committed
|
|
5
|
+
// Files that are in the staging area (.jvcs/staging) — meaning, you’ve already added them using jvcs add, but haven’t committed yet.
|
|
6
|
+
|
|
7
|
+
// Changes not staged for commit
|
|
8
|
+
// Files that were already added to staging earlier, but you modified them again in your working directory after staging — i.e., the staged copy and working copy are different.
|
|
9
|
+
|
|
1
10
|
const fs = require("fs");
|
|
2
11
|
const path = require("path");
|
|
3
12
|
const crypto = require("crypto");
|
|
4
13
|
const chalk = require("chalk");
|
|
5
|
-
const { getGlobalConfig, checkforjvcs } = require("./utility");
|
|
6
|
-
const { minimatch } = require("minimatch");
|
|
14
|
+
const { checkGlobalConfig, getGlobalConfig, checkforjvcs } = require("./utility");
|
|
7
15
|
|
|
8
16
|
// normalize relative path to use forward slashes for consistent comparisons
|
|
9
17
|
function normalizeRel(p) {
|
|
@@ -16,26 +24,10 @@ function hashfile(filepath) {
|
|
|
16
24
|
return crypto.createHash("sha256").update(data).digest("hex")
|
|
17
25
|
}
|
|
18
26
|
catch(error) {
|
|
19
|
-
return null
|
|
27
|
+
// return null
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
|
|
23
|
-
function loadIgnorePatterns() {
|
|
24
|
-
const ignorePath = path.join(process.cwd(), ".jvcsignore");
|
|
25
|
-
if(!fs.existsSync(ignorePath)) return [];
|
|
26
|
-
|
|
27
|
-
const content = fs.readFileSync(ignorePath, "utf-8");
|
|
28
|
-
return content
|
|
29
|
-
.split(/[\n,]+/)
|
|
30
|
-
.map(line => line.trim())
|
|
31
|
-
.filter(line => line.length > 0 && !line.startsWith("#"));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isIgnored(relativePath, ignorePatterns = []) {
|
|
35
|
-
return ignorePatterns.some(pattern =>
|
|
36
|
-
minimatch(relativePath, pattern, { dot: true })
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
31
|
|
|
40
32
|
function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
41
33
|
|
|
@@ -47,12 +39,11 @@ function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
|
47
39
|
const fullPath = path.join(dir,entry.name)
|
|
48
40
|
const rel = normalizeRel(path.relative(rootDir,fullPath))
|
|
49
41
|
|
|
50
|
-
if(entry.isDirectory() && (entry.name === ".jvcs" || entry.name === "
|
|
51
|
-
|
|
42
|
+
if(entry.isDirectory() && (entry.name === ".jvcs" || entry.name === "node_modules"))
|
|
43
|
+
continue;
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
continue;
|
|
45
|
+
if(entry.isFile() && (entry.name === "meta.json" || entry.name === "jvcs_hashcode.json"))
|
|
46
|
+
continue;
|
|
56
47
|
|
|
57
48
|
if(entry.isFile()) {
|
|
58
49
|
collected.push(rel);
|
|
@@ -60,6 +51,7 @@ function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
|
60
51
|
else if(entry.isDirectory()) {
|
|
61
52
|
getAllFiles(fullPath, rootDir, collected);
|
|
62
53
|
}
|
|
54
|
+
|
|
63
55
|
}
|
|
64
56
|
|
|
65
57
|
return collected
|
|
@@ -67,16 +59,21 @@ function getAllFiles(dir, rootDir=dir, collected=[]) {
|
|
|
67
59
|
|
|
68
60
|
async function statusCmd() {
|
|
69
61
|
|
|
62
|
+
if(!checkGlobalConfig()) {
|
|
63
|
+
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
64
|
+
console.log(chalk.green("jvcs --help for help"));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
70
68
|
const configData = getGlobalConfig();
|
|
71
69
|
if(!configData) {
|
|
72
70
|
console.log(chalk.red("No existing session found. Please login or signup."));
|
|
73
|
-
|
|
74
|
-
process.exit(1);
|
|
71
|
+
return;
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
if(!checkforjvcs()) {
|
|
78
|
-
console.log(chalk.red("Repository is not initialized or is deleted.
|
|
79
|
-
|
|
75
|
+
console.log(chalk.red("Repository is not initialized or is deleted."));
|
|
76
|
+
return;
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
const cwd = process.cwd()
|
|
@@ -87,130 +84,77 @@ async function statusCmd() {
|
|
|
87
84
|
|
|
88
85
|
if(!fs.existsSync(jvcsDir)) {
|
|
89
86
|
console.log(chalk.red("No repository exists. Please create one using 'jvcs init'"))
|
|
90
|
-
|
|
87
|
+
return
|
|
91
88
|
}
|
|
92
89
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// 1. Collect hashes for CWD
|
|
90
|
+
// collect files (all relative to cwd, normalized)
|
|
96
91
|
const cwdFiles = getAllFiles(cwd, cwd, []);
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
// 2. Collect hashes for HEAD
|
|
106
|
-
const headMap = new Map();
|
|
107
|
-
if (fs.existsSync(commitDir) && fs.existsSync(headFile)) {
|
|
108
|
-
const headFileContent = fs.readFileSync(headFile, "utf-8").trim();
|
|
109
|
-
if (headFileContent) {
|
|
110
|
-
const commitPath = path.join(commitDir, headFileContent);
|
|
111
|
-
if (fs.existsSync(commitPath)) {
|
|
112
|
-
const commitFiles = getAllFiles(commitPath, commitPath, []);
|
|
113
|
-
for (const f of commitFiles) {
|
|
114
|
-
const h = hashfile(path.join(commitPath, f));
|
|
115
|
-
if (h) headMap.set(f, h);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
92
|
+
const stagedFiles = fs.existsSync(stagingDir) ? getAllFiles(stagingDir, stagingDir, []).map(f => normalizeRel(f)) : [];
|
|
93
|
+
let commitedFiles = []
|
|
94
|
+
if(fs.existsSync(commitDir)) {
|
|
95
|
+
const commits = fs.readdirSync(commitDir)
|
|
96
|
+
if(commits.length > 0) {
|
|
97
|
+
const lastCommit = `${fs.readFileSync(headFile, "utf-8").trim()}`;
|
|
98
|
+
const commitPath = path.join(commitDir, lastCommit);
|
|
99
|
+
commitedFiles = getAllFiles(commitPath, commitPath, []).map(f => normalizeRel(f))
|
|
118
100
|
}
|
|
119
101
|
}
|
|
120
102
|
|
|
121
|
-
//
|
|
122
|
-
const
|
|
123
|
-
const
|
|
124
|
-
if (fs.existsSync(hashPath)) {
|
|
125
|
-
try {
|
|
126
|
-
const data = JSON.parse(fs.readFileSync(hashPath, "utf-8"));
|
|
127
|
-
for (const [key, val] of Object.entries(data)) {
|
|
128
|
-
stagingMap.set(normalizeRel(key), val.hash);
|
|
129
|
-
}
|
|
130
|
-
} catch(e) {}
|
|
131
|
-
} else {
|
|
132
|
-
// Fallback
|
|
133
|
-
if (fs.existsSync(stagingDir)) {
|
|
134
|
-
const stFiles = getAllFiles(stagingDir, stagingDir, []);
|
|
135
|
-
for(const f of stFiles) {
|
|
136
|
-
const h = hashfile(path.join(stagingDir, f));
|
|
137
|
-
if (h) stagingMap.set(f, h);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
}
|
|
103
|
+
// use Sets for fast looku
|
|
104
|
+
const committedSet = new Set(commitedFiles);
|
|
105
|
+
const stagedSet = new Set(stagedFiles);
|
|
141
106
|
|
|
142
|
-
//
|
|
107
|
+
// Untracked: present in cwd but not in staging or commits
|
|
108
|
+
const untracked = cwdFiles.filter(f => !stagedSet.has(f) && !committedSet.has(f));
|
|
143
109
|
|
|
144
|
-
//
|
|
145
|
-
const
|
|
146
|
-
for (const f of cwdMap.keys()) {
|
|
147
|
-
if (!stagingMap.has(f)) {
|
|
148
|
-
untracked.push(f);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
110
|
+
// Changes to be committed: present in staging but not in (any) commits
|
|
111
|
+
const toBeCommitted = stagedFiles.filter(f => !committedSet.has(f));
|
|
151
112
|
|
|
152
|
-
//
|
|
153
|
-
const
|
|
154
|
-
|
|
155
|
-
|
|
113
|
+
// Changes not staged for commit: present in staging and in cwd, but changed in cwd compared to staged copy
|
|
114
|
+
const modified = stagedFiles.filter((file)=> {
|
|
115
|
+
const cwdFilePath = path.join(process.cwd(),file)
|
|
116
|
+
const stagedFilePath = path.join(stagingDir,file)
|
|
117
|
+
|
|
118
|
+
if(!fs.existsSync(cwdFilePath) || !fs.existsSync(stagedFilePath))
|
|
119
|
+
return false
|
|
156
120
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
stagedAdded.push(f);
|
|
160
|
-
} else if (headMap.get(f) !== sHash) {
|
|
161
|
-
stagedModified.push(f);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
for (const f of headMap.keys()) {
|
|
165
|
-
if (!stagingMap.has(f)) {
|
|
166
|
-
stagedDeleted.push(f);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
121
|
+
const cwdHash = hashfile(cwdFilePath)
|
|
122
|
+
const stagingHash = hashfile(stagedFilePath)
|
|
169
123
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const unstagedDeleted = [];
|
|
124
|
+
return cwdHash !== stagingHash
|
|
125
|
+
})
|
|
173
126
|
|
|
174
|
-
for (const [f, sHash] of stagingMap.entries()) {
|
|
175
|
-
if (!cwdMap.has(f)) {
|
|
176
|
-
unstagedDeleted.push(f);
|
|
177
|
-
} else if (cwdMap.get(f) !== sHash) {
|
|
178
|
-
unstagedModified.push(f);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
127
|
|
|
182
|
-
//
|
|
128
|
+
// output
|
|
183
129
|
console.log(chalk.bold.blue(`\nOn branch: main (default)`));
|
|
184
130
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
stagedDeleted.forEach(f => console.log(chalk.green(`\tdeleted: ${f}`)));
|
|
191
|
-
} else {
|
|
131
|
+
console.log(chalk.bold.green("\nChanges to be committed (files that are staged but not commited):"));
|
|
132
|
+
if(toBeCommitted.length > 0) {
|
|
133
|
+
toBeCommitted.forEach(f => console.log(chalk.green(`\t${f}`)));
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
192
136
|
console.log(chalk.gray("\tNo changes added to commit"));
|
|
193
137
|
}
|
|
194
138
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
} else {
|
|
139
|
+
console.log(chalk.bold.yellow("\nChanges not staged for commit (files that are modified after adding to staging area):"));
|
|
140
|
+
if(modified.length > 0) {
|
|
141
|
+
modified.forEach(f => console.log(chalk.yellow(`\t${f}`)));
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
201
144
|
console.log(chalk.gray("\tNo modified files detected"));
|
|
202
145
|
}
|
|
203
146
|
|
|
204
|
-
console.log(chalk.bold.red("\nUntracked files:"));
|
|
205
|
-
if
|
|
147
|
+
console.log(chalk.bold.red("\nUntracked files (files that are not staged or commited):"));
|
|
148
|
+
if(untracked.length > 0) {
|
|
206
149
|
untracked.forEach(f => console.log(chalk.red(`\t${f}`)));
|
|
207
|
-
}
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
208
152
|
console.log(chalk.gray("\tNo untracked files"));
|
|
209
153
|
}
|
|
210
154
|
|
|
211
155
|
console.log(chalk.gray("\n(use 'jvcs add <file>' to stage changes)"));
|
|
212
156
|
console.log(chalk.gray("(use 'jvcs commit -m \"message\"' to commit changes)"));
|
|
213
|
-
console.log(chalk.gray("(use 'jvcs unstage <file>/<folder>
|
|
157
|
+
console.log(chalk.gray("(use 'jvcs unstage <file>/<folder> to unstage a file/folder')"))
|
|
214
158
|
}
|
|
215
159
|
|
|
216
|
-
module.exports = statusCmd
|
|
160
|
+
module.exports = statusCmd
|