@ibgib/vcs-gib 0.0.30 → 0.0.33

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.
Files changed (216) hide show
  1. package/dist/AUTO-GENERATED-version.d.mts +1 -1
  2. package/dist/AUTO-GENERATED-version.mjs +1 -1
  3. package/dist/bootstrap/node-bootstrap.d.mts.map +1 -1
  4. package/dist/bootstrap/node-bootstrap.mjs +7 -21
  5. package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
  6. package/dist/cli/commands/{add-cmd.d.mts → cli-add-cmd.d.mts} +3 -4
  7. package/dist/cli/commands/cli-add-cmd.d.mts.map +1 -0
  8. package/dist/cli/commands/cli-add-cmd.mjs +45 -0
  9. package/dist/cli/commands/cli-add-cmd.mjs.map +1 -0
  10. package/dist/cli/commands/{branch-cmd.d.mts → cli-branch-cmd.d.mts} +9 -9
  11. package/dist/cli/commands/cli-branch-cmd.d.mts.map +1 -0
  12. package/dist/cli/commands/cli-branch-cmd.mjs +59 -0
  13. package/dist/cli/commands/cli-branch-cmd.mjs.map +1 -0
  14. package/dist/cli/commands/cli-checkout-cmd.d.mts +20 -0
  15. package/dist/cli/commands/cli-checkout-cmd.d.mts.map +1 -0
  16. package/dist/cli/commands/cli-checkout-cmd.mjs +50 -0
  17. package/dist/cli/commands/cli-checkout-cmd.mjs.map +1 -0
  18. package/dist/cli/commands/cli-commit-cmd.d.mts +23 -0
  19. package/dist/cli/commands/cli-commit-cmd.d.mts.map +1 -0
  20. package/dist/cli/commands/cli-commit-cmd.mjs +52 -0
  21. package/dist/cli/commands/cli-commit-cmd.mjs.map +1 -0
  22. package/dist/cli/commands/{generate-comment-cmd.d.mts → cli-generate-comment-cmd.d.mts} +1 -1
  23. package/dist/cli/commands/cli-generate-comment-cmd.d.mts.map +1 -0
  24. package/dist/cli/commands/{generate-comment-cmd.mjs → cli-generate-comment-cmd.mjs} +11 -6
  25. package/dist/cli/commands/cli-generate-comment-cmd.mjs.map +1 -0
  26. package/dist/cli/commands/{init-cmd.d.mts → cli-init-cmd.d.mts} +3 -3
  27. package/dist/cli/commands/cli-init-cmd.d.mts.map +1 -0
  28. package/dist/cli/commands/cli-init-cmd.mjs +47 -0
  29. package/dist/cli/commands/cli-init-cmd.mjs.map +1 -0
  30. package/dist/cli/commands/{log-cmd.d.mts → cli-log-cmd.d.mts} +3 -4
  31. package/dist/cli/commands/cli-log-cmd.d.mts.map +1 -0
  32. package/dist/cli/commands/cli-log-cmd.mjs +90 -0
  33. package/dist/cli/commands/cli-log-cmd.mjs.map +1 -0
  34. package/dist/cli/commands/cli-merge-cmd.d.mts +22 -0
  35. package/dist/cli/commands/cli-merge-cmd.d.mts.map +1 -0
  36. package/dist/cli/commands/cli-merge-cmd.mjs +66 -0
  37. package/dist/cli/commands/cli-merge-cmd.mjs.map +1 -0
  38. package/dist/cli/commands/{reset-cmd.d.mts → cli-reset-cmd.d.mts} +2 -2
  39. package/dist/cli/commands/cli-reset-cmd.d.mts.map +1 -0
  40. package/dist/cli/commands/cli-reset-cmd.mjs +63 -0
  41. package/dist/cli/commands/cli-reset-cmd.mjs.map +1 -0
  42. package/dist/cli/commands/cli-restore-cmd.d.mts +23 -0
  43. package/dist/cli/commands/cli-restore-cmd.d.mts.map +1 -0
  44. package/dist/cli/commands/cli-restore-cmd.mjs +55 -0
  45. package/dist/cli/commands/cli-restore-cmd.mjs.map +1 -0
  46. package/dist/cli/commands/{status-cmd.d.mts → cli-status-cmd.d.mts} +3 -3
  47. package/dist/cli/commands/cli-status-cmd.d.mts.map +1 -0
  48. package/dist/cli/commands/cli-status-cmd.mjs +96 -0
  49. package/dist/cli/commands/cli-status-cmd.mjs.map +1 -0
  50. package/dist/cli/vcs-cli-main.d.mts.map +1 -1
  51. package/dist/cli/vcs-cli-main.mjs +18 -15
  52. package/dist/cli/vcs-cli-main.mjs.map +1 -1
  53. package/dist/cli/vcs-projection-helper.d.mts +23 -0
  54. package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
  55. package/dist/cli/vcs-projection-helper.mjs +91 -0
  56. package/dist/cli/vcs-projection-helper.mjs.map +1 -0
  57. package/dist/cli/vcs-repo-helper.d.mts +19 -0
  58. package/dist/cli/vcs-repo-helper.d.mts.map +1 -0
  59. package/dist/cli/vcs-repo-helper.mjs +74 -0
  60. package/dist/cli/vcs-repo-helper.mjs.map +1 -0
  61. package/dist/test/test-helpers.d.mts +11 -2
  62. package/dist/test/test-helpers.d.mts.map +1 -1
  63. package/dist/test/test-helpers.mjs +35 -0
  64. package/dist/test/test-helpers.mjs.map +1 -1
  65. package/package.json +6 -6
  66. package/src/AUTO-GENERATED-version.mts +1 -1
  67. package/src/bootstrap/node-bootstrap.mts +7 -21
  68. package/src/bootstrap/node-bootstrap.respec.mts +2 -2
  69. package/src/cli/cli-arg-parser.respec.mts +2 -2
  70. package/src/cli/cli-e2e.respec.mts +12 -12
  71. package/src/cli/commands/branch-checkout-cmd.respec.mts +426 -412
  72. package/src/cli/commands/cli-add-cmd.mts +65 -0
  73. package/src/cli/commands/cli-branch-cmd.mts +87 -0
  74. package/src/cli/commands/cli-checkout-cmd.mts +72 -0
  75. package/src/cli/commands/cli-commit-cmd.mts +77 -0
  76. package/src/cli/commands/{generate-comment-cmd.mts → cli-generate-comment-cmd.mts} +12 -6
  77. package/src/cli/commands/cli-init-cmd.mts +78 -0
  78. package/src/cli/commands/cli-log-cmd.mts +126 -0
  79. package/src/cli/commands/cli-merge-cmd.mts +99 -0
  80. package/src/cli/commands/cli-reset-cmd.mts +94 -0
  81. package/src/cli/commands/cli-restore-cmd.mts +87 -0
  82. package/src/cli/commands/cli-status-cmd.mts +131 -0
  83. package/src/cli/commands/commit-log-cmd.respec.mts +85 -28
  84. package/src/cli/commands/init-cmd.respec.mts +3 -3
  85. package/src/cli/commands/reset-restore-cmd.respec.mts +9 -9
  86. package/src/cli/commands/status-add-cmd.respec.mts +21 -17
  87. package/src/cli/vcs-cli-main.mts +18 -15
  88. package/src/cli/vcs-projection-helper.mts +112 -0
  89. package/src/cli/vcs-repo-helper.mts +99 -0
  90. package/src/engine/branch/branch-space.respec.mts +23 -21
  91. package/src/engine/merge/b2tfs-sync-comments.respec.mts +11 -11
  92. package/src/test/test-helpers.mts +50 -2
  93. package/src/vcs-gib.respec.mts +25 -16
  94. package/tsconfig.test.tsbuildinfo +1 -1
  95. package/tsconfig.tsbuildinfo +1 -1
  96. package/vcs-gib_test_output.md +58 -0
  97. package/dist/cli/commands/add-cmd.d.mts.map +0 -1
  98. package/dist/cli/commands/add-cmd.mjs +0 -346
  99. package/dist/cli/commands/add-cmd.mjs.map +0 -1
  100. package/dist/cli/commands/branch-cmd.d.mts.map +0 -1
  101. package/dist/cli/commands/branch-cmd.mjs +0 -238
  102. package/dist/cli/commands/branch-cmd.mjs.map +0 -1
  103. package/dist/cli/commands/checkout-cmd.d.mts +0 -21
  104. package/dist/cli/commands/checkout-cmd.d.mts.map +0 -1
  105. package/dist/cli/commands/checkout-cmd.mjs +0 -174
  106. package/dist/cli/commands/checkout-cmd.mjs.map +0 -1
  107. package/dist/cli/commands/commit-cmd.d.mts +0 -24
  108. package/dist/cli/commands/commit-cmd.d.mts.map +0 -1
  109. package/dist/cli/commands/commit-cmd.mjs +0 -449
  110. package/dist/cli/commands/commit-cmd.mjs.map +0 -1
  111. package/dist/cli/commands/generate-comment-cmd.d.mts.map +0 -1
  112. package/dist/cli/commands/generate-comment-cmd.mjs.map +0 -1
  113. package/dist/cli/commands/init-cmd.d.mts.map +0 -1
  114. package/dist/cli/commands/init-cmd.mjs +0 -119
  115. package/dist/cli/commands/init-cmd.mjs.map +0 -1
  116. package/dist/cli/commands/log-cmd.d.mts.map +0 -1
  117. package/dist/cli/commands/log-cmd.mjs +0 -349
  118. package/dist/cli/commands/log-cmd.mjs.map +0 -1
  119. package/dist/cli/commands/merge-cmd.d.mts +0 -36
  120. package/dist/cli/commands/merge-cmd.d.mts.map +0 -1
  121. package/dist/cli/commands/merge-cmd.mjs +0 -292
  122. package/dist/cli/commands/merge-cmd.mjs.map +0 -1
  123. package/dist/cli/commands/reset-cmd.d.mts.map +0 -1
  124. package/dist/cli/commands/reset-cmd.mjs +0 -93
  125. package/dist/cli/commands/reset-cmd.mjs.map +0 -1
  126. package/dist/cli/commands/restore-cmd.d.mts +0 -22
  127. package/dist/cli/commands/restore-cmd.d.mts.map +0 -1
  128. package/dist/cli/commands/restore-cmd.mjs +0 -115
  129. package/dist/cli/commands/restore-cmd.mjs.map +0 -1
  130. package/dist/cli/commands/status-cmd.d.mts.map +0 -1
  131. package/dist/cli/commands/status-cmd.mjs +0 -132
  132. package/dist/cli/commands/status-cmd.mjs.map +0 -1
  133. package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
  134. package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
  135. package/dist/engine/branch/branch-graph-helper.mjs +0 -81
  136. package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
  137. package/dist/engine/branch/branch-helper.d.mts +0 -40
  138. package/dist/engine/branch/branch-helper.d.mts.map +0 -1
  139. package/dist/engine/branch/branch-helper.mjs +0 -78
  140. package/dist/engine/branch/branch-helper.mjs.map +0 -1
  141. package/dist/engine/branch/branch-space-helper.d.mts +0 -23
  142. package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
  143. package/dist/engine/branch/branch-space-helper.mjs +0 -78
  144. package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
  145. package/dist/engine/branch/branch-types.d.mts +0 -26
  146. package/dist/engine/branch/branch-types.d.mts.map +0 -1
  147. package/dist/engine/branch/branch-types.mjs +0 -7
  148. package/dist/engine/branch/branch-types.mjs.map +0 -1
  149. package/dist/engine/diff/line-diff-helper.d.mts +0 -76
  150. package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
  151. package/dist/engine/diff/line-diff-helper.mjs +0 -144
  152. package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
  153. package/dist/engine/filter/glob-helper.d.mts +0 -51
  154. package/dist/engine/filter/glob-helper.d.mts.map +0 -1
  155. package/dist/engine/filter/glob-helper.mjs +0 -132
  156. package/dist/engine/filter/glob-helper.mjs.map +0 -1
  157. package/dist/engine/index/index-helper.d.mts +0 -113
  158. package/dist/engine/index/index-helper.d.mts.map +0 -1
  159. package/dist/engine/index/index-helper.mjs +0 -533
  160. package/dist/engine/index/index-helper.mjs.map +0 -1
  161. package/dist/engine/index/index-types.d.mts +0 -63
  162. package/dist/engine/index/index-types.d.mts.map +0 -1
  163. package/dist/engine/index/index-types.mjs +0 -7
  164. package/dist/engine/index/index-types.mjs.map +0 -1
  165. package/dist/engine/item/item-atom-helper.d.mts +0 -20
  166. package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
  167. package/dist/engine/item/item-atom-helper.mjs +0 -30
  168. package/dist/engine/item/item-atom-helper.mjs.map +0 -1
  169. package/dist/engine/item/item-helper.d.mts +0 -94
  170. package/dist/engine/item/item-helper.d.mts.map +0 -1
  171. package/dist/engine/item/item-helper.mjs +0 -424
  172. package/dist/engine/item/item-helper.mjs.map +0 -1
  173. package/dist/engine/item/item-types.d.mts +0 -128
  174. package/dist/engine/item/item-types.d.mts.map +0 -1
  175. package/dist/engine/item/item-types.mjs +0 -16
  176. package/dist/engine/item/item-types.mjs.map +0 -1
  177. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
  178. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
  179. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
  180. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
  181. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
  182. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
  183. package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
  184. package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
  185. package/dist/engine/status/status-helper.d.mts +0 -90
  186. package/dist/engine/status/status-helper.d.mts.map +0 -1
  187. package/dist/engine/status/status-helper.mjs +0 -286
  188. package/dist/engine/status/status-helper.mjs.map +0 -1
  189. package/src/cli/commands/add-cmd.mts +0 -435
  190. package/src/cli/commands/branch-cmd.mts +0 -311
  191. package/src/cli/commands/checkout-cmd.mts +0 -227
  192. package/src/cli/commands/commit-cmd.mts +0 -557
  193. package/src/cli/commands/init-cmd.mts +0 -152
  194. package/src/cli/commands/log-cmd.mts +0 -449
  195. package/src/cli/commands/merge-cmd.mts +0 -363
  196. package/src/cli/commands/reset-cmd.mts +0 -128
  197. package/src/cli/commands/restore-cmd.mts +0 -155
  198. package/src/cli/commands/status-cmd.mts +0 -168
  199. package/src/engine/branch/branch-graph-helper.mts +0 -117
  200. package/src/engine/branch/branch-helper.mts +0 -112
  201. package/src/engine/branch/branch-space-helper.mts +0 -110
  202. package/src/engine/branch/branch-types.mts +0 -29
  203. package/src/engine/diff/line-diff-helper.mts +0 -210
  204. package/src/engine/diff/line-diff-helper.respec.mts +0 -84
  205. package/src/engine/filter/glob-helper.mts +0 -165
  206. package/src/engine/filter/glob-helper.respec.mts +0 -94
  207. package/src/engine/index/index-helper.mts +0 -705
  208. package/src/engine/index/index-types.mts +0 -66
  209. package/src/engine/item/item-atom-helper.mts +0 -30
  210. package/src/engine/item/item-helper.mts +0 -544
  211. package/src/engine/item/item-types.mts +0 -137
  212. package/src/engine/item/item.respec.mts +0 -92
  213. package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
  214. package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
  215. package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
  216. package/src/engine/status/status-helper.mts +0 -383
@@ -1,363 +0,0 @@
1
- /**
2
- * @module merge-cmd
3
- *
4
- * Command handler for `vcs merge <branchName>`.
5
- * Merges the incoming branch into the base (active/current) branch using
6
- * SyncSagaCoordinator sync and 3-way graft merge strategy.
7
- * Projects merged branch snapshot onto the base branch physical worktree path.
8
- *
9
- * ## Terminology (matches standard git usage)
10
- *
11
- * * **base** branch / space — the branch currently checked out, the one being
12
- * merged INTO (analogous to `ours` / `HEAD` in git)
13
- * * **incoming** branch / space — the branch whose changes are being merged IN
14
- * (analogous to `theirs` / the topic branch in git)
15
- */
16
-
17
- import path from 'node:path';
18
- import fs from 'node:fs/promises';
19
-
20
- import { clone, extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
21
- import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
22
- import { putInSpace, getLatestAddrs, persistTransformResult, registerNewIbGib } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
23
- import { rel8 } from '@ibgib/ts-gib/dist/V1/transforms/rel8.mjs';
24
- import { SyncSagaCoordinator } from '@ibgib/core-gib/dist/sync/sync-saga-coordinator.mjs';
25
- import { SyncPeerInnerspace_V1 } from '@ibgib/core-gib/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-v1.mjs';
26
- import { SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1 } from '@ibgib/core-gib/dist/sync/sync-peer/sync-peer-innerspace/sync-peer-innerspace-constants.mjs';
27
- import { SyncConflictStrategy } from '@ibgib/core-gib/dist/sync/sync-constants.mjs';
28
- import { GraftPreference } from '@ibgib/core-gib/dist/sync/graft-info/graft-info-types.mjs';
29
-
30
-
31
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
32
- import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
33
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
34
- import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
35
- import { writeB2tFSItemToFS, getIbGibWithMetaspaceFallback, reifyB2tFSHierarchy } from '../../engine/item/item-helper.mjs';
36
- import { getB2tFSIndexIbGib, updateB2tFSIndexIbGib } from '../../engine/index/index-helper.mjs';
37
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
38
- import { logBranchState, logItemState, logCheckpoint, logAddr, logAddrs } from '../../test/test-helpers.mjs';
39
-
40
-
41
- const lcFile = `[merge-cmd]`;
42
- const logalot = GLOBAL_LOG_A_LOT;
43
-
44
- export interface MergeCmdOpts {
45
- /** The incoming branch name — the branch whose changes will be merged in. */
46
- incomingBranchName?: string;
47
- targetDir?: string;
48
- vcsFolderName?: string;
49
- quiet?: boolean;
50
- /** When true, emit diagnostic checkpoint logging (useful in tests). */
51
- diagLog?: boolean;
52
- }
53
-
54
- export interface MergeCmdResult {
55
- /** The base (current/active) branch name — merged into. */
56
- baseBranch: string;
57
- /** The incoming branch name — merged from. */
58
- incomingBranch: string;
59
- baseSpaceId: string;
60
- incomingSpaceId: string;
61
- mergedBranchAddr?: string;
62
- worktreePath: string;
63
- }
64
-
65
- export async function executeMergeCmd({
66
- incomingBranchName,
67
- targetDir = process.cwd(),
68
- vcsFolderName = '.vcsgib',
69
- quiet = false,
70
- diagLog = false,
71
- }: MergeCmdOpts = {}): Promise<MergeCmdResult> {
72
- const lc = `${lcFile}[${executeMergeCmd.name}]`;
73
- const diag = (label: string) => { if (diagLog) logCheckpoint(`merge-cmd: ${label}`); };
74
- try {
75
- if (logalot) {
76
- console.log(`${lc} starting... (I: 4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f)`);
77
- }
78
-
79
- const trimmedIncomingBranch = incomingBranchName?.trim();
80
- if (!trimmedIncomingBranch) {
81
- throw new Error(`Branch name is required for merge (E: 5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a)`);
82
- }
83
-
84
- const absTargetDir = path.resolve(targetDir);
85
-
86
- const { metaspace, localSpace, repoRoot, vcsPath } = await bootstrapVcsMetaspace({
87
- repoPath: absTargetDir,
88
- vcsFolderName,
89
- });
90
-
91
- // Verify repo exists
92
- try {
93
- await fs.access(vcsPath);
94
- } catch {
95
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b)`);
96
- }
97
-
98
- // 1. Fetch authoritative repository index from localSpace
99
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
100
- if (!indexIbGib) {
101
- throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c)`);
102
- }
103
-
104
- const baseBranchName = indexIbGib.data?.activeBranch || 'main';
105
-
106
- if (baseBranchName === trimmedIncomingBranch) {
107
- throw new Error(`Cannot merge branch '${trimmedIncomingBranch}' into itself (E: 8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d)`);
108
- }
109
-
110
- // 2. Fetch all registered branch ibgibs
111
- const branchAddrs = [
112
- ...(indexIbGib.rel8ns?.branch || []),
113
- ...(indexIbGib.rel8ns?.branch_tjp || []),
114
- ];
115
-
116
- let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
117
- if (branchAddrs.length > 0) {
118
- for (const bAddr of branchAddrs) {
119
- const bIbGib = await getIbGibWithMetaspaceFallback({
120
- addr: bAddr,
121
- space: localSpace,
122
- metaspace,
123
- });
124
- if (bIbGib) {
125
- branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
126
- }
127
- }
128
- }
129
-
130
- // Resolve base branch node & incoming branch node
131
- const baseBranchIbGib = branchIbGibs.findLast(
132
- (b) => b?.data?.name === baseBranchName,
133
- );
134
- if (!baseBranchIbGib) {
135
- throw new Error(`Base branch '${baseBranchName}' not found in repository (E: 9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e)`);
136
- }
137
-
138
- const incomingBranchIbGib = branchIbGibs.findLast(
139
- (b) => b?.data?.name === trimmedIncomingBranch,
140
- );
141
-
142
- if (!incomingBranchIbGib) {
143
- throw new Error(`Branch '${trimmedIncomingBranch}' does not exist (E: 0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f)`);
144
- }
145
-
146
- // 3. Resolve base branch space & incoming branch space
147
- const baseSpaceRes = await getOrCreateBranchSpace({
148
- metaspace,
149
- vcsPath,
150
- branchName: baseBranchName,
151
- });
152
- const baseSpace = baseSpaceRes.space;
153
-
154
- const incomingSpaceRes = await getOrCreateBranchSpace({
155
- metaspace,
156
- vcsPath,
157
- branchName: trimmedIncomingBranch,
158
- });
159
- const incomingSpace = incomingSpaceRes.space;
160
-
161
- await putInSpace({ space: baseSpace, ibGib: baseBranchIbGib });
162
- await putInSpace({ space: incomingSpace, ibGib: incomingBranchIbGib });
163
-
164
- // Resolve latest branch tip inside incomingSpace (in case commits occurred on incoming branch)
165
- const incomingBranchTjpAddr = incomingBranchIbGib.rel8ns?.tjp?.at(0) || getIbGibAddr({ ibGib: incomingBranchIbGib });
166
- const latestIncomingBranchRes = await getLatestAddrs({ space: incomingSpace, addrs: [incomingBranchTjpAddr] });
167
- const latestIncomingBranchAddr = (latestIncomingBranchRes?.data as any)?.latestAddrs?.[0] || getIbGibAddr({ ibGib: incomingBranchIbGib });
168
-
169
- const latestIncomingBranchIbGib = (await getIbGibWithMetaspaceFallback({
170
- addr: latestIncomingBranchAddr,
171
- space: incomingSpace,
172
- metaspace,
173
- })) as B2tFSBranchIbGib_V1 || incomingBranchIbGib;
174
-
175
- const incomingRootAddr = latestIncomingBranchIbGib.rel8ns?.b2tfs_item?.at(-1);
176
-
177
- if (!incomingRootAddr) {
178
- throw new Error(`Incoming branch '${trimmedIncomingBranch}' has no valid root item address (E: 3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e)`);
179
- }
180
- const incomingRootItem = await getIbGibWithMetaspaceFallback({
181
- addr: incomingRootAddr,
182
- space: incomingSpace,
183
- metaspace,
184
- });
185
- if (!incomingRootItem) {
186
- throw new Error(`Incoming root item '${incomingRootAddr}' not found in incoming space (E: 4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f)`);
187
- }
188
-
189
- if (diagLog) {
190
- diag('resolving branches & spaces');
191
- await logBranchState({ label: 'baseBranch (main)', branchIbGib: baseBranchIbGib, space: baseSpace });
192
- await logBranchState({ label: 'incomingBranch (feature-merge)', branchIbGib: incomingBranchIbGib, space: incomingSpace });
193
- await logItemState({ label: 'incomingRootItem', itemIbGib: incomingRootItem, space: incomingSpace });
194
- }
195
-
196
- // 4. Setup SyncPeerInnerspace and SyncSagaCoordinator syncing incoming branch space into base branch space
197
- const peer = new SyncPeerInnerspace_V1(clone(SYNC_PEER_INNERSPACE_DEFAULT_DATA_V1));
198
- await peer.initialized;
199
- await peer.initializeOpts({
200
- localMetaspace: metaspace,
201
- localSpace: incomingSpace,
202
- receiverSpace: baseSpace,
203
- receiverCoordinator: new SyncSagaCoordinator(),
204
- receiverMetaspace: metaspace,
205
- });
206
-
207
- const senderCoordinator = new SyncSagaCoordinator();
208
- const syncSaga = await senderCoordinator.sync({
209
- peer,
210
- localSpace: incomingSpace,
211
- metaspace,
212
- domainIbGibs: [incomingRootItem],
213
- conflictStrategy: SyncConflictStrategy.optimisticWithLCS,
214
- graftPreference: GraftPreference.receiver,
215
- });
216
-
217
- await syncSaga.done;
218
-
219
- // 5. Reify the base branch filesystem hierarchy.
220
- // After sync, any child timelines (files or subfolders) that were merged/advanced
221
- // in baseSpace will have newer tips. reifyB2tFSHierarchy bubbles all updated child tips
222
- // up through the folder DAG, evolving parents in-place and returning the newly reified root item.
223
- const currentBaseRootItemAddr = baseBranchIbGib.rel8ns?.b2tfs_item?.at(-1);
224
- if (!currentBaseRootItemAddr) {
225
- throw new Error(`Base branch '${baseBranchName}' has no root item address (E: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
226
- }
227
-
228
- const reifyRes = await reifyB2tFSHierarchy({
229
- rootItemAddr: currentBaseRootItemAddr,
230
- space: baseSpace,
231
- metaspace,
232
- });
233
-
234
- const reifiedRootItem = reifyRes.reifiedRootItem;
235
- const reifiedRootAddr = getIbGibAddr({ ibGib: reifiedRootItem });
236
-
237
- if (diagLog) {
238
- diag('after reification');
239
- logAddr('currentBaseRootItemAddr', currentBaseRootItemAddr);
240
- logAddr('reifiedRootAddr', reifiedRootAddr);
241
- console.log(`[merge-cmd] reification hasChanges:`, reifyRes.hasChanges);
242
- console.log(`[merge-cmd] reifiedAddrsMap:`, JSON.stringify(reifyRes.reifiedAddrsMap));
243
- }
244
-
245
- // 5b. Evolve the base branch ibgib to point at the reified root item tip.
246
- // The sync engine does not update branch ibgibs — branches live in
247
- // their own space and are never domain ibgibs in the sync. We advance
248
- // the branch pointer to the reified root item.
249
- let mergedBranchAddr: string = getIbGibAddr({ ibGib: baseBranchIbGib });
250
- if (reifyRes.hasChanges && reifiedRootAddr !== currentBaseRootItemAddr) {
251
- if (diagLog) {
252
- console.log(`[merge-cmd] Evolving base branch: root item changing from ${currentBaseRootItemAddr} -> ${reifiedRootAddr}`);
253
- }
254
- const resRel8Branch = await rel8({
255
- src: baseBranchIbGib,
256
- rel8nsToReplaceByAddr: {
257
- b2tfs_item: [{ oldAddr: currentBaseRootItemAddr, newAddr: reifiedRootAddr }],
258
- },
259
- dna: true,
260
- nCounter: true,
261
- });
262
- const evolvedBranchIbGib = resRel8Branch.newIbGib;
263
- await persistTransformResult({ resTransform: resRel8Branch, space: baseSpace });
264
- await registerNewIbGib({ ibGib: evolvedBranchIbGib, space: baseSpace });
265
- mergedBranchAddr = getIbGibAddr({ ibGib: evolvedBranchIbGib });
266
- if (diagLog) {
267
- console.log(`[merge-cmd] Base branch evolved to addr: ${mergedBranchAddr}`);
268
- }
269
- } else {
270
- if (diagLog) {
271
- console.log(`[merge-cmd] Base branch root item unchanged (${currentBaseRootItemAddr})`);
272
- }
273
- }
274
-
275
- // Update indexIbGib to reference new merged branch node
276
- await updateB2tFSIndexIbGib({
277
- space: baseSpace,
278
- metaspace,
279
- indexIbGib,
280
- rel8nsToUpdate: {
281
- branch: [mergedBranchAddr],
282
- },
283
- vcsPath,
284
- });
285
-
286
- const mergedRootItemAddr = reifiedRootAddr;
287
-
288
- if (diagLog) {
289
- diag('projecting onto disk');
290
- logAddr('mergedRootItemAddr', mergedRootItemAddr);
291
- }
292
-
293
- // 6. Project merged branch snapshot files onto physical worktree disk
294
- const isDefaultBranch = baseBranchName === 'main';
295
- const worktreePath = isDefaultBranch
296
- ? repoRoot
297
- : path.join(repoRoot, 'b', baseBranchName);
298
-
299
- await fs.mkdir(worktreePath, { recursive: true });
300
-
301
- if (mergedRootItemAddr) {
302
- const mergedRootItem = await getIbGibWithMetaspaceFallback({
303
- addr: mergedRootItemAddr,
304
- space: baseSpace,
305
- metaspace,
306
- }) as B2tFSItemIbGib_V1;
307
-
308
- if (diagLog) {
309
- await logItemState({ label: 'mergedRootItem to write', itemIbGib: mergedRootItem, space: baseSpace });
310
- }
311
-
312
- if (mergedRootItem) {
313
- if (mergedRootItem.data?.fsType === 'file') {
314
- await writeB2tFSItemToFS({
315
- item: mergedRootItem,
316
- destPath: worktreePath,
317
- space: baseSpace,
318
- metaspace,
319
- });
320
- } else {
321
- const childAddrs = mergedRootItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
322
- for (const childAddr of childAddrs) {
323
- const childItem = await getIbGibWithMetaspaceFallback({
324
- addr: childAddr,
325
- space: baseSpace,
326
- metaspace,
327
- }) as B2tFSItemIbGib_V1;
328
-
329
- if (childItem) {
330
- await writeB2tFSItemToFS({
331
- item: childItem,
332
- destPath: worktreePath,
333
- space: baseSpace,
334
- metaspace,
335
- });
336
- }
337
- }
338
- }
339
- }
340
- }
341
-
342
- if (!quiet) {
343
- console.log(`Successfully merged branch '${trimmedIncomingBranch}' into '${baseBranchName}' (I: 1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a)`);
344
- console.log(` Worktree projection: ${worktreePath}`);
345
- }
346
-
347
- return {
348
- baseBranch: baseBranchName,
349
- incomingBranch: trimmedIncomingBranch,
350
- baseSpaceId: baseSpaceRes.spaceId,
351
- incomingSpaceId: incomingSpaceRes.spaceId,
352
- mergedBranchAddr,
353
- worktreePath,
354
- };
355
- } catch (error) {
356
- console.error(`${lc} ${extractErrorMsg(error)} (E: 2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b)`);
357
- throw error;
358
- } finally {
359
- if (logalot) {
360
- console.log(`${lc} complete. (I: 3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c)`);
361
- }
362
- }
363
- }
@@ -1,128 +0,0 @@
1
- /**
2
- * @module reset-cmd
3
- *
4
- * Command handler for `vcs reset [path...]`.
5
- * Unstages specified files (or all files) from active branch index in localSpace.
6
- */
7
-
8
- import path from 'node:path';
9
- import fs from 'node:fs/promises';
10
-
11
- import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
- import { promptForConfirm } from '@ibgib/helper-gib/dist/helpers/node-helper.mjs';
13
- import { putInSpace } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
14
-
15
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
16
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
17
- import { getB2tFSIndexIbGib, unstagePathsFromIndex } from '../../engine/index/index-helper.mjs';
18
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
19
-
20
- const lcFile = `[reset-cmd]`;
21
- const logalot = GLOBAL_LOG_A_LOT;
22
-
23
- export interface ResetCmdOpts {
24
- paths?: string[];
25
- targetDir?: string;
26
- vcsFolderName?: string;
27
- all?: boolean;
28
- yes?: boolean;
29
- force?: boolean;
30
- quiet?: boolean;
31
- }
32
-
33
- export interface ResetCmdResult {
34
- unstagedPaths: string[];
35
- stagedCount: number;
36
- }
37
-
38
- export async function executeResetCmd({
39
- paths = [],
40
- targetDir = process.cwd(),
41
- vcsFolderName = '.vcsgib',
42
- all = false,
43
- yes = false,
44
- force = false,
45
- quiet = false,
46
- }: ResetCmdOpts = {}): Promise<ResetCmdResult> {
47
- const lc = `${lcFile}[${executeResetCmd.name}]`;
48
- try {
49
- if (logalot) {
50
- console.log(`${lc} starting... (I: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
51
- }
52
-
53
- const absTargetDir = path.resolve(targetDir);
54
-
55
- const { metaspace, localSpace, vcsPath, repoRoot } = await bootstrapVcsMetaspace({
56
- repoPath: absTargetDir,
57
- vcsFolderName,
58
- });
59
-
60
- // Verify repo exists
61
- try {
62
- await fs.access(vcsPath);
63
- } catch {
64
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b)`);
65
- }
66
-
67
- // Retrieve authoritative B2tFSIndexIbGib_V1 from space
68
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
69
- if (!indexIbGib) {
70
- throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b)`);
71
- }
72
-
73
- const activeBranch = indexIbGib.data?.activeBranch || 'main';
74
- const activeWorktreeDir = activeBranch === 'main' ? repoRoot : path.join(repoRoot, 'b', activeBranch);
75
-
76
- const { space: activeSpace } = await getOrCreateBranchSpace({
77
- metaspace,
78
- vcsPath,
79
- branchName: activeBranch,
80
- });
81
-
82
- const skipPrompt = yes || force || quiet || !process.stdin.isTTY;
83
- if (!skipPrompt) {
84
- const confirmed = await promptForConfirm({ msg: 'Unstage specified files from index?' });
85
- if (!confirmed) {
86
- if (!quiet) {
87
- console.log('Operation cancelled.');
88
- }
89
- const stagedCount = Object.keys(indexIbGib.data?.stagedPaths || {}).length;
90
- return { unstagedPaths: [], stagedCount };
91
- }
92
- }
93
-
94
- const unstageRes = await unstagePathsFromIndex({
95
- indexIbGib,
96
- paths,
97
- targetDir,
98
- activeWorktreeDir,
99
- vcsPath,
100
- space: activeSpace,
101
- metaspace,
102
- all,
103
- });
104
-
105
- if (localSpace !== activeSpace) {
106
- await putInSpace({ space: localSpace, ibGib: unstageRes.updatedIndex });
107
- }
108
-
109
- if (!quiet) {
110
- for (const unstagedPath of unstageRes.unstagedPaths) {
111
- console.log(`unstaged: ${unstagedPath}`);
112
- }
113
- }
114
-
115
- const finalStagedCount = Object.keys(unstageRes.updatedIndex.data?.stagedPaths || {}).length;
116
- return {
117
- unstagedPaths: unstageRes.unstagedPaths,
118
- stagedCount: finalStagedCount,
119
- };
120
- } catch (error) {
121
- console.error(`${lc} ${extractErrorMsg(error)} (E: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
122
- throw error;
123
- } finally {
124
- if (logalot) {
125
- console.log(`${lc} complete. (I: 5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c)`);
126
- }
127
- }
128
- }
@@ -1,155 +0,0 @@
1
- /**
2
- * @module restore-cmd
3
- *
4
- * Command handler for `vcs restore [path...]`.
5
- * Restores working tree files from committed branch snapshot, or unstages files if `--staged` is set.
6
- */
7
-
8
- import path from 'node:path';
9
- import fs from 'node:fs/promises';
10
-
11
- import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
- import { promptForConfirm } from '@ibgib/helper-gib/dist/helpers/node-helper.mjs';
13
- import { putInSpace } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
14
-
15
- import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
16
- import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
17
- import { getB2tFSIndexIbGib, unstagePathsFromIndex, restoreWorktreePathsFromSnapshot } from '../../engine/index/index-helper.mjs';
18
- import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
19
-
20
- const lcFile = `[restore-cmd]`;
21
- const logalot = GLOBAL_LOG_A_LOT;
22
-
23
- export interface RestoreCmdOpts {
24
- paths?: string[];
25
- targetDir?: string;
26
- vcsFolderName?: string;
27
- staged?: boolean;
28
- worktree?: boolean;
29
- yes?: boolean;
30
- force?: boolean;
31
- quiet?: boolean;
32
- }
33
-
34
- export interface RestoreCmdResult {
35
- unstagedPaths?: string[];
36
- restoredPaths?: string[];
37
- }
38
-
39
- export async function executeRestoreCmd({
40
- paths = [],
41
- targetDir = process.cwd(),
42
- vcsFolderName = '.vcsgib',
43
- staged = false,
44
- worktree = false,
45
- yes = false,
46
- force = false,
47
- quiet = false,
48
- }: RestoreCmdOpts = {}): Promise<RestoreCmdResult> {
49
- const lc = `${lcFile}[${executeRestoreCmd.name}]`;
50
- try {
51
- if (logalot) {
52
- console.log(`${lc} starting... (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1e)`);
53
- }
54
-
55
- const absTargetDir = path.resolve(targetDir);
56
-
57
- const { metaspace, localSpace, vcsPath, repoRoot } = await bootstrapVcsMetaspace({
58
- repoPath: absTargetDir,
59
- vcsFolderName,
60
- });
61
-
62
- // Verify repo exists
63
- try {
64
- await fs.access(vcsPath);
65
- } catch {
66
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2e)`);
67
- }
68
-
69
- // Retrieve authoritative B2tFSIndexIbGib_V1 from space
70
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
71
- if (!indexIbGib) {
72
- throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3e)`);
73
- }
74
-
75
- const activeBranch = indexIbGib.data?.activeBranch || 'main';
76
- const activeWorktreeDir = activeBranch === 'main' ? repoRoot : path.join(repoRoot, 'b', activeBranch);
77
-
78
- const { space: activeSpace } = await getOrCreateBranchSpace({
79
- metaspace,
80
- vcsPath,
81
- branchName: activeBranch,
82
- });
83
-
84
- const skipPrompt = yes || force || quiet || !process.stdin.isTTY;
85
- if (!skipPrompt) {
86
- const msg = staged
87
- ? 'Unstage specified files from index?'
88
- : 'Revert working tree files to committed snapshot?';
89
- const confirmed = await promptForConfirm({ msg });
90
- if (!confirmed) {
91
- if (!quiet) {
92
- console.log('Operation cancelled.');
93
- }
94
- return { unstagedPaths: [], restoredPaths: [] };
95
- }
96
- }
97
-
98
- let unstagedPaths: string[] | undefined;
99
- let restoredPaths: string[] | undefined;
100
-
101
- if (staged) {
102
- const unstageRes = await unstagePathsFromIndex({
103
- indexIbGib,
104
- paths,
105
- targetDir,
106
- activeWorktreeDir,
107
- vcsPath,
108
- space: activeSpace,
109
- metaspace,
110
- });
111
-
112
- if (localSpace !== activeSpace) {
113
- await putInSpace({ space: localSpace, ibGib: unstageRes.updatedIndex });
114
- }
115
-
116
- unstagedPaths = unstageRes.unstagedPaths;
117
- if (!quiet) {
118
- for (const p of unstagedPaths) {
119
- console.log(`unstaged: ${p}`);
120
- }
121
- }
122
- }
123
-
124
- if (!staged || worktree) {
125
- const restoreRes = await restoreWorktreePathsFromSnapshot({
126
- paths,
127
- targetDir,
128
- activeWorktreeDir,
129
- activeBranchSpace: activeSpace,
130
- metaspace,
131
- indexIbGib,
132
- vcsPath,
133
- });
134
-
135
- restoredPaths = restoreRes.restoredPaths;
136
- if (!quiet) {
137
- for (const p of restoredPaths) {
138
- console.log(`restored: ${p}`);
139
- }
140
- }
141
- }
142
-
143
- return {
144
- unstagedPaths,
145
- restoredPaths,
146
- };
147
- } catch (error) {
148
- console.error(`${lc} ${extractErrorMsg(error)} (E: 9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4e)`);
149
- throw error;
150
- } finally {
151
- if (logalot) {
152
- console.log(`${lc} complete. (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5e)`);
153
- }
154
- }
155
- }