easegit-cli 1.1.0 → 1.2.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/dist/init.js +5 -2
- package/hooks/pre-push +9 -39
- package/package.json +1 -1
- package/hooks/pre-commit +0 -45
package/dist/init.js
CHANGED
|
@@ -52,9 +52,12 @@ async function init() {
|
|
|
52
52
|
const packageRoot = path.join(__dirname, '..');
|
|
53
53
|
const config = { packageRoot };
|
|
54
54
|
fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
|
|
55
|
-
// Hook definitions
|
|
55
|
+
// Hook definitions - only hooks that protect against losing work
|
|
56
|
+
// pre-rebase: rebase can destroy uncommitted work
|
|
57
|
+
// pre-merge-commit: merge can create conflicts and lose work
|
|
58
|
+
// pre-push: checkpoint before pushing (safety net)
|
|
59
|
+
// post-checkout: checkout can discard uncommitted changes
|
|
56
60
|
const hooks = [
|
|
57
|
-
'pre-commit',
|
|
58
61
|
'pre-rebase',
|
|
59
62
|
'pre-merge-commit',
|
|
60
63
|
'pre-push',
|
package/hooks/pre-push
CHANGED
|
@@ -1,45 +1,15 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// Pre-push hook - creates checkpoint before push
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const path = require('path');
|
|
5
|
+
const fs = require('fs');
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
}
|
|
7
|
+
// Find package root from .git/easegit.json
|
|
8
|
+
const gitDir = process.env.GIT_DIR || '.git';
|
|
9
|
+
const configPath = path.join(gitDir, 'easegit.json');
|
|
21
10
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
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("push");
|
|
39
|
-
} catch (err) {
|
|
40
|
-
console.error(
|
|
41
|
-
"EaseGit pre-push hook failed. Run `easegit init` to reinstall hooks."
|
|
42
|
-
);
|
|
43
|
-
console.error(`Error: ${err.message}`);
|
|
44
|
-
process.exit(1);
|
|
11
|
+
if (fs.existsSync(configPath)) {
|
|
12
|
+
const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
|
|
13
|
+
const { createCheckpoint } = require(path.join(config.packageRoot, 'dist', 'snapshot', 'create'));
|
|
14
|
+
createCheckpoint('push');
|
|
45
15
|
}
|
package/package.json
CHANGED
package/hooks/pre-commit
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|