easegit-cli 1.0.6 → 1.1.0
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/README.md +1 -0
- package/dist/git/plumbing.js +13 -10
- package/dist/init.js +1 -0
- package/hooks/pre-commit +45 -0
- package/package.json +1 -2
package/README.md
CHANGED
package/dist/git/plumbing.js
CHANGED
|
@@ -51,16 +51,19 @@ const path = __importStar(require("path"));
|
|
|
51
51
|
* Execute a Git command and return output
|
|
52
52
|
*/
|
|
53
53
|
function gitExec(args, cwd) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
54
|
+
const result = (0, child_process_1.spawnSync)('git', args, {
|
|
55
|
+
cwd: cwd || process.cwd(),
|
|
56
|
+
encoding: 'utf8',
|
|
57
|
+
stdio: ['pipe', 'pipe', 'pipe']
|
|
58
|
+
});
|
|
59
|
+
if (result.error) {
|
|
60
|
+
throw new Error(`Git command failed: ${result.error.message}`);
|
|
61
|
+
}
|
|
62
|
+
if (result.status !== 0) {
|
|
63
|
+
const stderr = result.stderr ? result.stderr.toString().trim() : '';
|
|
64
|
+
throw new Error(`Git command failed: ${stderr || 'Unknown error'}`);
|
|
65
|
+
}
|
|
66
|
+
return (result.stdout || '').toString().trim();
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* Check if current directory is a Git repository
|
package/dist/init.js
CHANGED
package/hooks/pre-commit
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// Pre-commit hook - creates checkpoint before commit
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const path = require("path");
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
// Find .git directory by walking up from cwd
|
|
9
|
+
let gitDir = ".git";
|
|
10
|
+
if (!fs.existsSync(gitDir)) {
|
|
11
|
+
let current = process.cwd();
|
|
12
|
+
while (current !== path.dirname(current)) {
|
|
13
|
+
const candidate = path.join(current, ".git");
|
|
14
|
+
if (fs.existsSync(candidate)) {
|
|
15
|
+
gitDir = candidate;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
current = path.dirname(current);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Read config written by easegit init
|
|
23
|
+
const configPath = path.join(gitDir, "easegit.json");
|
|
24
|
+
const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
|
|
25
|
+
const packageRoot = config.packageRoot;
|
|
26
|
+
|
|
27
|
+
if (!packageRoot || !fs.existsSync(packageRoot)) {
|
|
28
|
+
throw new Error(`Invalid easegit config: packageRoot=${packageRoot}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Now require the module using the known package root
|
|
32
|
+
const { createCheckpoint } = require(path.join(
|
|
33
|
+
packageRoot,
|
|
34
|
+
"dist",
|
|
35
|
+
"snapshot",
|
|
36
|
+
"create"
|
|
37
|
+
));
|
|
38
|
+
createCheckpoint("commit");
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error(
|
|
41
|
+
"EaseGit pre-commit hook failed. Run `easegit init` to reinstall hooks."
|
|
42
|
+
);
|
|
43
|
+
console.error(`Error: ${err.message}`);
|
|
44
|
+
process.exit(1);
|
|
45
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "easegit-cli",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Automatic checkpoints before Git can hurt you",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": {
|
|
@@ -39,7 +39,6 @@
|
|
|
39
39
|
"@types/node": "^20.0.0",
|
|
40
40
|
"typescript": "^5.0.0"
|
|
41
41
|
},
|
|
42
|
-
"dependencies": {},
|
|
43
42
|
"engines": {
|
|
44
43
|
"node": ">=16.0.0"
|
|
45
44
|
}
|