easegit-cli 1.0.2 → 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',
@@ -57,17 +62,14 @@ async function init() {
57
62
  // Get the hooks template directory (from installed package)
58
63
  // This will be in node_modules/easegit/hooks or local hooks/ during development
59
64
  const packageHooksDir = path.join(__dirname, '..', 'hooks');
60
- const packageRoot = path.join(__dirname, '..');
61
65
  // Install hooks
62
66
  for (const hookName of hooks) {
63
67
  const hookPath = path.join(hooksDir, hookName);
64
68
  const templatePath = path.join(packageHooksDir, hookName);
65
69
  if (fs.existsSync(templatePath)) {
66
- // Copy the hook template and stamp in the absolute package root so hooks work even when the
67
- // package is installed globally (no node_modules in the target repo).
70
+ // Copy the hook template as-is; hooks will read .git/easegit.json for package root
68
71
  const hookContent = fs.readFileSync(templatePath, 'utf8');
69
- const stampedContent = hookContent.replace(/__EASEGIT_PACKAGE_ROOT__/g, packageRoot.replace(/\\/g, '/'));
70
- fs.writeFileSync(hookPath, stampedContent, { mode: 0o755 });
72
+ fs.writeFileSync(hookPath, hookContent, { mode: 0o755 });
71
73
  }
72
74
  }
73
75
  console.log('EaseGit initialized successfully');
@@ -2,26 +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 defaultRoot = path.join(__dirname, '..', '..');
7
- const configuredRoot = process.env.EASEGIT_PACKAGE_ROOT || "__EASEGIT_PACKAGE_ROOT__";
8
- const packageRoot = configuredRoot.startsWith('__EASEGIT_PACKAGE_ROOT__') ? defaultRoot : configuredRoot;
9
- const { createCheckpoint } = require(path.join(packageRoot, 'dist', 'snapshot', 'create'));
10
- const { hasMergeConflicts, isDetachedHead, isDirty } = require(path.join(packageRoot, 'dist', 'git', 'plumbing'));
5
+ const fs = require("fs");
6
+ const path = require("path");
11
7
 
12
- // Create checkpoint for the new state
13
- createCheckpoint('checkout');
14
-
15
- // Check for problems after checkout
16
8
  try {
17
- const hasConflicts = hasMergeConflicts();
18
- const detached = isDetachedHead();
19
- const dirty = isDirty();
20
-
21
- if (hasConflicts || (detached && dirty)) {
22
- console.error('⚠ EaseGit: last Git operation damaged your working state.');
23
- 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
24
63
  }
25
- } catch {
26
- // 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);
27
70
  }
@@ -1,10 +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 defaultRoot = path.join(__dirname, '..', '..');
6
- const configuredRoot = process.env.EASEGIT_PACKAGE_ROOT || "__EASEGIT_PACKAGE_ROOT__";
7
- const packageRoot = configuredRoot.startsWith('__EASEGIT_PACKAGE_ROOT__') ? defaultRoot : configuredRoot;
8
- const { createCheckpoint } = require(path.join(packageRoot, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
9
6
 
10
- 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,10 +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 defaultRoot = path.join(__dirname, '..', '..');
6
- const configuredRoot = process.env.EASEGIT_PACKAGE_ROOT || "__EASEGIT_PACKAGE_ROOT__";
7
- const packageRoot = configuredRoot.startsWith('__EASEGIT_PACKAGE_ROOT__') ? defaultRoot : configuredRoot;
8
- const { createCheckpoint } = require(path.join(packageRoot, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
9
6
 
10
- 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,10 +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 defaultRoot = path.join(__dirname, '..', '..');
6
- const configuredRoot = process.env.EASEGIT_PACKAGE_ROOT || "__EASEGIT_PACKAGE_ROOT__";
7
- const packageRoot = configuredRoot.startsWith('__EASEGIT_PACKAGE_ROOT__') ? defaultRoot : configuredRoot;
8
- const { createCheckpoint } = require(path.join(packageRoot, 'dist', 'snapshot', 'create'));
4
+ const fs = require("fs");
5
+ const path = require("path");
9
6
 
10
- 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.2",
3
+ "version": "1.0.3",
4
4
  "description": "Automatic checkpoints before Git can hurt you",
5
5
  "main": "dist/index.js",
6
6
  "bin": {