easegit-cli 1.0.1 → 1.0.3

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 CHANGED
@@ -43,10 +43,15 @@ async function init() {
43
43
  }
44
44
  const gitDir = (0, plumbing_1.getGitDir)();
45
45
  const hooksDir = path.join(gitDir, 'hooks');
46
+ const configPath = path.join(gitDir, 'easegit.json');
46
47
  // Ensure hooks directory exists
47
48
  if (!fs.existsSync(hooksDir)) {
48
49
  fs.mkdirSync(hooksDir, { recursive: true });
49
50
  }
51
+ // Write config file so hooks can find the package
52
+ const packageRoot = path.join(__dirname, '..');
53
+ const config = { packageRoot };
54
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
50
55
  // Hook definitions
51
56
  const hooks = [
52
57
  'pre-rebase',
@@ -62,7 +67,7 @@ async function init() {
62
67
  const hookPath = path.join(hooksDir, hookName);
63
68
  const templatePath = path.join(packageHooksDir, hookName);
64
69
  if (fs.existsSync(templatePath)) {
65
- // Copy the hook template
70
+ // Copy the hook template as-is; hooks will read .git/easegit.json for package root
66
71
  const hookContent = fs.readFileSync(templatePath, 'utf8');
67
72
  fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
68
73
  }
@@ -2,24 +2,69 @@
2
2
 
3
3
  // Post-checkout hook - creates checkpoint after checkout
4
4
  // Also detects failures and warns user
5
- const path = require('path');
6
- const mainPath = path.join(__dirname, '..', '..');
7
- const { createCheckpoint } = require(path.join(mainPath, 'dist', 'snapshot', 'create'));
8
- const { hasMergeConflicts, isDetachedHead, isDirty } = require(path.join(mainPath, 'dist', 'git', 'plumbing'));
5
+ const fs = require("fs");
6
+ const path = require("path");
9
7
 
10
- // Create checkpoint for the new state
11
- createCheckpoint('checkout');
12
-
13
- // Check for problems after checkout
14
8
  try {
15
- const hasConflicts = hasMergeConflicts();
16
- const detached = isDetachedHead();
17
- const dirty = isDirty();
18
-
19
- if (hasConflicts || (detached && dirty)) {
20
- console.error('⚠ EaseGit: last Git operation damaged your working state.');
21
- console.error('Run `easegit undo` to restore the last safe checkpoint.');
9
+ // Find .git directory by walking up from cwd
10
+ let gitDir = ".git";
11
+ if (!fs.existsSync(gitDir)) {
12
+ let current = process.cwd();
13
+ while (current !== path.dirname(current)) {
14
+ const candidate = path.join(current, ".git");
15
+ if (fs.existsSync(candidate)) {
16
+ gitDir = candidate;
17
+ break;
18
+ }
19
+ current = path.dirname(current);
20
+ }
21
+ }
22
+
23
+ // Read config written by easegit init
24
+ const configPath = path.join(gitDir, "easegit.json");
25
+ const config = JSON.parse(fs.readFileSync(configPath, "utf8"));
26
+ const packageRoot = config.packageRoot;
27
+
28
+ if (!packageRoot || !fs.existsSync(packageRoot)) {
29
+ throw new Error(`Invalid easegit config: packageRoot=${packageRoot}`);
30
+ }
31
+
32
+ // Now require the modules using the known package root
33
+ const { createCheckpoint } = require(path.join(
34
+ packageRoot,
35
+ "dist",
36
+ "snapshot",
37
+ "create"
38
+ ));
39
+ const { hasMergeConflicts, isDetachedHead, isDirty } = require(path.join(
40
+ packageRoot,
41
+ "dist",
42
+ "git",
43
+ "plumbing"
44
+ ));
45
+
46
+ // Create checkpoint for the new state
47
+ createCheckpoint("checkout");
48
+
49
+ // Check for problems after checkout
50
+ try {
51
+ const hasConflicts = hasMergeConflicts();
52
+ const detached = isDetachedHead();
53
+ const dirty = isDirty();
54
+
55
+ if (hasConflicts || (detached && dirty)) {
56
+ console.error(
57
+ "⚠ EaseGit: last Git operation damaged your working state."
58
+ );
59
+ console.error("Run `easegit undo` to restore the last safe checkpoint.");
60
+ }
61
+ } catch {
62
+ // Silent fail
22
63
  }
23
- } catch {
24
- // Silent fail
64
+ } catch (err) {
65
+ console.error(
66
+ "EaseGit post-checkout hook failed. Run `easegit init` to reinstall hooks."
67
+ );
68
+ console.error(`Error: ${err.message}`);
69
+ process.exit(1);
25
70
  }
@@ -1,8 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Pre-merge hook - creates checkpoint before merge
4
- const path = require('path');
5
- const mainPath = path.join(__dirname, '..', '..');
6
- const { createCheckpoint } = require(path.join(mainPath, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
7
6
 
8
- createCheckpoint('merge');
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("merge");
39
+ } catch (err) {
40
+ console.error(
41
+ "EaseGit pre-merge hook failed. Run `easegit init` to reinstall hooks."
42
+ );
43
+ console.error(`Error: ${err.message}`);
44
+ process.exit(1);
45
+ }
package/hooks/pre-push CHANGED
@@ -1,8 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Pre-push hook - creates checkpoint before push
4
- const path = require('path');
5
- const mainPath = path.join(__dirname, '..', '..');
6
- const { createCheckpoint } = require(path.join(mainPath, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
7
6
 
8
- createCheckpoint('push');
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("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);
45
+ }
package/hooks/pre-rebase CHANGED
@@ -1,8 +1,45 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  // Pre-rebase hook - creates checkpoint before rebase
4
- const path = require('path');
5
- const mainPath = path.join(__dirname, '..', '..');
6
- const { createCheckpoint } = require(path.join(mainPath, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
7
6
 
8
- createCheckpoint('rebase');
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("rebase");
39
+ } catch (err) {
40
+ console.error(
41
+ "EaseGit pre-rebase 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.1",
3
+ "version": "1.0.3",
4
4
  "description": "Automatic checkpoints before Git can hurt you",
5
5
  "main": "dist/index.js",
6
6
  "bin": {