@ibgib/vcs-gib 0.0.30 → 0.0.32

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 (151) 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.mjs +1 -1
  4. package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
  5. package/dist/cli/commands/add-cmd.d.mts +2 -3
  6. package/dist/cli/commands/add-cmd.d.mts.map +1 -1
  7. package/dist/cli/commands/add-cmd.mjs +30 -283
  8. package/dist/cli/commands/add-cmd.mjs.map +1 -1
  9. package/dist/cli/commands/branch-cmd.d.mts +8 -8
  10. package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
  11. package/dist/cli/commands/branch-cmd.mjs +45 -176
  12. package/dist/cli/commands/branch-cmd.mjs.map +1 -1
  13. package/dist/cli/commands/checkout-cmd.d.mts +2 -4
  14. package/dist/cli/commands/checkout-cmd.d.mts.map +1 -1
  15. package/dist/cli/commands/checkout-cmd.mjs +31 -110
  16. package/dist/cli/commands/checkout-cmd.mjs.map +1 -1
  17. package/dist/cli/commands/commit-cmd.d.mts +7 -8
  18. package/dist/cli/commands/commit-cmd.d.mts.map +1 -1
  19. package/dist/cli/commands/commit-cmd.mjs +40 -390
  20. package/dist/cli/commands/commit-cmd.mjs.map +1 -1
  21. package/dist/cli/commands/generate-comment-cmd.d.mts.map +1 -1
  22. package/dist/cli/commands/generate-comment-cmd.mjs +5 -2
  23. package/dist/cli/commands/generate-comment-cmd.mjs.map +1 -1
  24. package/dist/cli/commands/init-cmd.d.mts +2 -2
  25. package/dist/cli/commands/init-cmd.d.mts.map +1 -1
  26. package/dist/cli/commands/init-cmd.mjs +20 -70
  27. package/dist/cli/commands/init-cmd.mjs.map +1 -1
  28. package/dist/cli/commands/log-cmd.d.mts +2 -3
  29. package/dist/cli/commands/log-cmd.d.mts.map +1 -1
  30. package/dist/cli/commands/log-cmd.mjs +42 -271
  31. package/dist/cli/commands/log-cmd.mjs.map +1 -1
  32. package/dist/cli/commands/merge-cmd.d.mts +3 -17
  33. package/dist/cli/commands/merge-cmd.d.mts.map +1 -1
  34. package/dist/cli/commands/merge-cmd.mjs +32 -218
  35. package/dist/cli/commands/merge-cmd.mjs.map +1 -1
  36. package/dist/cli/commands/reset-cmd.d.mts +1 -1
  37. package/dist/cli/commands/reset-cmd.d.mts.map +1 -1
  38. package/dist/cli/commands/reset-cmd.mjs +17 -19
  39. package/dist/cli/commands/reset-cmd.mjs.map +1 -1
  40. package/dist/cli/commands/restore-cmd.d.mts +8 -7
  41. package/dist/cli/commands/restore-cmd.d.mts.map +1 -1
  42. package/dist/cli/commands/restore-cmd.mjs +44 -62
  43. package/dist/cli/commands/restore-cmd.mjs.map +1 -1
  44. package/dist/cli/commands/status-cmd.d.mts +2 -2
  45. package/dist/cli/commands/status-cmd.d.mts.map +1 -1
  46. package/dist/cli/commands/status-cmd.mjs +63 -62
  47. package/dist/cli/commands/status-cmd.mjs.map +1 -1
  48. package/dist/cli/vcs-projection-helper.d.mts +23 -0
  49. package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
  50. package/dist/cli/vcs-projection-helper.mjs +91 -0
  51. package/dist/cli/vcs-projection-helper.mjs.map +1 -0
  52. package/dist/test/test-helpers.d.mts +2 -2
  53. package/dist/test/test-helpers.d.mts.map +1 -1
  54. package/package.json +3 -3
  55. package/src/AUTO-GENERATED-version.mts +1 -1
  56. package/src/bootstrap/node-bootstrap.mts +1 -1
  57. package/src/cli/cli-e2e.respec.mts +4 -4
  58. package/src/cli/commands/add-cmd.mts +32 -347
  59. package/src/cli/commands/branch-cmd.mts +56 -225
  60. package/src/cli/commands/checkout-cmd.mts +34 -138
  61. package/src/cli/commands/commit-cmd.mts +46 -473
  62. package/src/cli/commands/commit-log-cmd.respec.mts +11 -7
  63. package/src/cli/commands/generate-comment-cmd.mts +6 -2
  64. package/src/cli/commands/init-cmd.mts +20 -73
  65. package/src/cli/commands/log-cmd.mts +41 -331
  66. package/src/cli/commands/merge-cmd.mts +32 -252
  67. package/src/cli/commands/reset-cmd.mts +17 -19
  68. package/src/cli/commands/restore-cmd.mts +52 -72
  69. package/src/cli/commands/status-add-cmd.respec.mts +3 -3
  70. package/src/cli/commands/status-cmd.mts +68 -63
  71. package/src/cli/vcs-projection-helper.mts +112 -0
  72. package/src/engine/branch/branch-space.respec.mts +5 -5
  73. package/src/engine/merge/b2tfs-sync-comments.respec.mts +4 -4
  74. package/src/test/test-helpers.mts +2 -2
  75. package/src/vcs-gib.respec.mts +11 -8
  76. package/tsconfig.test.tsbuildinfo +1 -1
  77. package/tsconfig.tsbuildinfo +1 -1
  78. package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
  79. package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
  80. package/dist/engine/branch/branch-graph-helper.mjs +0 -81
  81. package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
  82. package/dist/engine/branch/branch-helper.d.mts +0 -40
  83. package/dist/engine/branch/branch-helper.d.mts.map +0 -1
  84. package/dist/engine/branch/branch-helper.mjs +0 -78
  85. package/dist/engine/branch/branch-helper.mjs.map +0 -1
  86. package/dist/engine/branch/branch-space-helper.d.mts +0 -23
  87. package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
  88. package/dist/engine/branch/branch-space-helper.mjs +0 -78
  89. package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
  90. package/dist/engine/branch/branch-types.d.mts +0 -26
  91. package/dist/engine/branch/branch-types.d.mts.map +0 -1
  92. package/dist/engine/branch/branch-types.mjs +0 -7
  93. package/dist/engine/branch/branch-types.mjs.map +0 -1
  94. package/dist/engine/diff/line-diff-helper.d.mts +0 -76
  95. package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
  96. package/dist/engine/diff/line-diff-helper.mjs +0 -144
  97. package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
  98. package/dist/engine/filter/glob-helper.d.mts +0 -51
  99. package/dist/engine/filter/glob-helper.d.mts.map +0 -1
  100. package/dist/engine/filter/glob-helper.mjs +0 -132
  101. package/dist/engine/filter/glob-helper.mjs.map +0 -1
  102. package/dist/engine/index/index-helper.d.mts +0 -113
  103. package/dist/engine/index/index-helper.d.mts.map +0 -1
  104. package/dist/engine/index/index-helper.mjs +0 -533
  105. package/dist/engine/index/index-helper.mjs.map +0 -1
  106. package/dist/engine/index/index-types.d.mts +0 -63
  107. package/dist/engine/index/index-types.d.mts.map +0 -1
  108. package/dist/engine/index/index-types.mjs +0 -7
  109. package/dist/engine/index/index-types.mjs.map +0 -1
  110. package/dist/engine/item/item-atom-helper.d.mts +0 -20
  111. package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
  112. package/dist/engine/item/item-atom-helper.mjs +0 -30
  113. package/dist/engine/item/item-atom-helper.mjs.map +0 -1
  114. package/dist/engine/item/item-helper.d.mts +0 -94
  115. package/dist/engine/item/item-helper.d.mts.map +0 -1
  116. package/dist/engine/item/item-helper.mjs +0 -424
  117. package/dist/engine/item/item-helper.mjs.map +0 -1
  118. package/dist/engine/item/item-types.d.mts +0 -128
  119. package/dist/engine/item/item-types.d.mts.map +0 -1
  120. package/dist/engine/item/item-types.mjs +0 -16
  121. package/dist/engine/item/item-types.mjs.map +0 -1
  122. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
  123. package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
  124. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
  125. package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
  126. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
  127. package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
  128. package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
  129. package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
  130. package/dist/engine/status/status-helper.d.mts +0 -90
  131. package/dist/engine/status/status-helper.d.mts.map +0 -1
  132. package/dist/engine/status/status-helper.mjs +0 -286
  133. package/dist/engine/status/status-helper.mjs.map +0 -1
  134. package/src/engine/branch/branch-graph-helper.mts +0 -117
  135. package/src/engine/branch/branch-helper.mts +0 -112
  136. package/src/engine/branch/branch-space-helper.mts +0 -110
  137. package/src/engine/branch/branch-types.mts +0 -29
  138. package/src/engine/diff/line-diff-helper.mts +0 -210
  139. package/src/engine/diff/line-diff-helper.respec.mts +0 -84
  140. package/src/engine/filter/glob-helper.mts +0 -165
  141. package/src/engine/filter/glob-helper.respec.mts +0 -94
  142. package/src/engine/index/index-helper.mts +0 -705
  143. package/src/engine/index/index-types.mts +0 -66
  144. package/src/engine/item/item-atom-helper.mts +0 -30
  145. package/src/engine/item/item-helper.mts +0 -544
  146. package/src/engine/item/item-types.mts +0 -137
  147. package/src/engine/item/item.respec.mts +0 -92
  148. package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
  149. package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
  150. package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
  151. package/src/engine/status/status-helper.mts +0 -383
@@ -1,60 +1,34 @@
1
1
  /**
2
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)
3
+ *
4
+ * CLI command handler for `vcs merge <branchName>`.
5
+ * Merges incoming branch into base branch and delegates to executeVcsMerge.
15
6
  */
16
7
 
17
8
  import path from 'node:path';
18
9
  import fs from 'node:fs/promises';
19
10
 
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
-
11
+ import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
+ import { executeVcsMerge } from '@ibgib/core-gib/dist/vcs/commands/merge-cmd.mjs';
30
13
 
31
14
  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';
15
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
16
+ import { getOrCreateWorkspaceProjectionSpace } from '@ibgib/node-gib/dist/vcs/workspace-space-helper.mjs';
17
+ import { readVcsIndexProjectionFromDisk, writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
37
18
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
38
- import { logBranchState, logItemState, logCheckpoint, logAddr, logAddrs } from '../../test/test-helpers.mjs';
39
-
40
19
 
41
20
  const lcFile = `[merge-cmd]`;
42
21
  const logalot = GLOBAL_LOG_A_LOT;
43
22
 
44
23
  export interface MergeCmdOpts {
45
- /** The incoming branch name — the branch whose changes will be merged in. */
46
24
  incomingBranchName?: string;
47
25
  targetDir?: string;
48
26
  vcsFolderName?: string;
49
27
  quiet?: boolean;
50
- /** When true, emit diagnostic checkpoint logging (useful in tests). */
51
- diagLog?: boolean;
52
28
  }
53
29
 
54
30
  export interface MergeCmdResult {
55
- /** The base (current/active) branch name — merged into. */
56
31
  baseBranch: string;
57
- /** The incoming branch name — merged from. */
58
32
  incomingBranch: string;
59
33
  baseSpaceId: string;
60
34
  incomingSpaceId: string;
@@ -67,10 +41,8 @@ export async function executeMergeCmd({
67
41
  targetDir = process.cwd(),
68
42
  vcsFolderName = '.vcsgib',
69
43
  quiet = false,
70
- diagLog = false,
71
44
  }: MergeCmdOpts = {}): Promise<MergeCmdResult> {
72
45
  const lc = `${lcFile}[${executeMergeCmd.name}]`;
73
- const diag = (label: string) => { if (diagLog) logCheckpoint(`merge-cmd: ${label}`); };
74
46
  try {
75
47
  if (logalot) {
76
48
  console.log(`${lc} starting... (I: 4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f)`);
@@ -96,54 +68,14 @@ export async function executeMergeCmd({
96
68
  }
97
69
 
98
70
  // 1. Fetch authoritative repository index from localSpace
99
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
71
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
100
72
  if (!indexIbGib) {
101
73
  throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c)`);
102
74
  }
103
75
 
104
76
  const baseBranchName = indexIbGib.data?.activeBranch || 'main';
105
77
 
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
78
+ // 2. Resolve base branch space & incoming branch space
147
79
  const baseSpaceRes = await getOrCreateBranchSpace({
148
80
  metaspace,
149
81
  vcsPath,
@@ -158,139 +90,6 @@ export async function executeMergeCmd({
158
90
  });
159
91
  const incomingSpace = incomingSpaceRes.space;
160
92
 
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
93
  const isDefaultBranch = baseBranchName === 'main';
295
94
  const worktreePath = isDefaultBranch
296
95
  ? repoRoot
@@ -298,46 +97,27 @@ export async function executeMergeCmd({
298
97
 
299
98
  await fs.mkdir(worktreePath, { recursive: true });
300
99
 
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
- }
100
+ const { space: workspaceSpace } = await getOrCreateWorkspaceProjectionSpace({
101
+ metaspace,
102
+ workspaceRoot: worktreePath,
103
+ vcsFolderName,
104
+ backingSpace: baseSpace,
105
+ });
311
106
 
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;
107
+ const mergeRes = await executeVcsMerge({
108
+ metaspace,
109
+ localSpace,
110
+ baseBranchSpace: baseSpace,
111
+ incomingBranchSpace: incomingSpace,
112
+ workspaceSpace,
113
+ indexIbGib,
114
+ incomingBranchName: trimmedIncomingBranch,
115
+ repoRoot,
116
+ targetDir: absTargetDir,
117
+ vcsFolderName,
118
+ });
328
119
 
329
- if (childItem) {
330
- await writeB2tFSItemToFS({
331
- item: childItem,
332
- destPath: worktreePath,
333
- space: baseSpace,
334
- metaspace,
335
- });
336
- }
337
- }
338
- }
339
- }
340
- }
120
+ await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: mergeRes.updatedIndex });
341
121
 
342
122
  if (!quiet) {
343
123
  console.log(`Successfully merged branch '${trimmedIncomingBranch}' into '${baseBranchName}' (I: 1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a)`);
@@ -345,11 +125,11 @@ export async function executeMergeCmd({
345
125
  }
346
126
 
347
127
  return {
348
- baseBranch: baseBranchName,
349
- incomingBranch: trimmedIncomingBranch,
128
+ baseBranch: mergeRes.baseBranch,
129
+ incomingBranch: mergeRes.incomingBranch,
350
130
  baseSpaceId: baseSpaceRes.spaceId,
351
131
  incomingSpaceId: incomingSpaceRes.spaceId,
352
- mergedBranchAddr,
132
+ mergedBranchAddr: mergeRes.mergeCommitAddr,
353
133
  worktreePath,
354
134
  };
355
135
  } catch (error) {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @module reset-cmd
3
3
  *
4
- * Command handler for `vcs reset [path...]`.
4
+ * CLI command handler for `vcs reset [path...]`.
5
5
  * Unstages specified files (or all files) from active branch index in localSpace.
6
6
  */
7
7
 
@@ -10,11 +10,12 @@ import fs from 'node:fs/promises';
10
10
 
11
11
  import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
12
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';
13
+ import { executeVcsReset } from '@ibgib/core-gib/dist/vcs/commands/reset-cmd.mjs';
14
+ import { resolveContextualBranchName } from '@ibgib/core-gib/dist/vcs/branch/branch-helper.mjs';
14
15
 
15
16
  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';
17
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
18
+ import { readVcsIndexProjectionFromDisk, writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
18
19
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
19
20
 
20
21
  const lcFile = `[reset-cmd]`;
@@ -65,12 +66,12 @@ export async function executeResetCmd({
65
66
  }
66
67
 
67
68
  // Retrieve authoritative B2tFSIndexIbGib_V1 from space
68
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
69
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
69
70
  if (!indexIbGib) {
70
71
  throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 3e4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b)`);
71
72
  }
72
73
 
73
- const activeBranch = indexIbGib.data?.activeBranch || 'main';
74
+ const activeBranch = resolveContextualBranchName({ targetDir: absTargetDir, repoRoot, indexIbGib });
74
75
  const activeWorktreeDir = activeBranch === 'main' ? repoRoot : path.join(repoRoot, 'b', activeBranch);
75
76
 
76
77
  const { space: activeSpace } = await getOrCreateBranchSpace({
@@ -91,31 +92,28 @@ export async function executeResetCmd({
91
92
  }
92
93
  }
93
94
 
94
- const unstageRes = await unstagePathsFromIndex({
95
+ const resetRes = await executeVcsReset({
96
+ metaspace,
97
+ localSpace,
98
+ activeBranchSpace: activeSpace,
95
99
  indexIbGib,
96
100
  paths,
97
- targetDir,
98
- activeWorktreeDir,
99
- vcsPath,
100
- space: activeSpace,
101
- metaspace,
102
101
  all,
102
+ targetDir: absTargetDir,
103
+ activeWorktreeDir,
103
104
  });
104
105
 
105
- if (localSpace !== activeSpace) {
106
- await putInSpace({ space: localSpace, ibGib: unstageRes.updatedIndex });
107
- }
106
+ await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: resetRes.updatedIndex });
108
107
 
109
108
  if (!quiet) {
110
- for (const unstagedPath of unstageRes.unstagedPaths) {
109
+ for (const unstagedPath of resetRes.unstagedPaths) {
111
110
  console.log(`unstaged: ${unstagedPath}`);
112
111
  }
113
112
  }
114
113
 
115
- const finalStagedCount = Object.keys(unstageRes.updatedIndex.data?.stagedPaths || {}).length;
116
114
  return {
117
- unstagedPaths: unstageRes.unstagedPaths,
118
- stagedCount: finalStagedCount,
115
+ unstagedPaths: resetRes.unstagedPaths,
116
+ stagedCount: resetRes.stagedCount,
119
117
  };
120
118
  } catch (error) {
121
119
  console.error(`${lc} ${extractErrorMsg(error)} (E: 4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b)`);
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * @module restore-cmd
3
3
  *
4
- * Command handler for `vcs restore [path...]`.
5
- * Restores working tree files from committed branch snapshot, or unstages files if `--staged` is set.
4
+ * CLI command handler for `vcs restore [path...]`.
5
+ * Delegates to executeVcsRestore and formats terminal output.
6
6
  */
7
7
 
8
8
  import path from 'node:path';
9
9
  import fs from 'node:fs/promises';
10
10
 
11
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';
12
+ import { executeVcsRestore } from '@ibgib/core-gib/dist/vcs/commands/restore-cmd.mjs';
13
+ import { resolveContextualBranchName } from '@ibgib/core-gib/dist/vcs/branch/branch-helper.mjs';
14
14
 
15
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';
16
+ import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
17
+ import { getOrCreateWorkspaceProjectionSpace } from '@ibgib/node-gib/dist/vcs/workspace-space-helper.mjs';
18
+ import { readVcsIndexProjectionFromDisk, writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
18
19
  import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
19
20
 
20
21
  const lcFile = `[restore-cmd]`;
@@ -22,34 +23,36 @@ const logalot = GLOBAL_LOG_A_LOT;
22
23
 
23
24
  export interface RestoreCmdOpts {
24
25
  paths?: string[];
25
- targetDir?: string;
26
- vcsFolderName?: string;
27
26
  staged?: boolean;
28
27
  worktree?: boolean;
28
+ all?: boolean;
29
29
  yes?: boolean;
30
30
  force?: boolean;
31
+ targetDir?: string;
32
+ vcsFolderName?: string;
31
33
  quiet?: boolean;
32
34
  }
33
35
 
34
36
  export interface RestoreCmdResult {
35
- unstagedPaths?: string[];
36
- restoredPaths?: string[];
37
+ restoredPaths: string[];
38
+ unstagedPaths: string[];
37
39
  }
38
40
 
39
41
  export async function executeRestoreCmd({
40
42
  paths = [],
41
- targetDir = process.cwd(),
42
- vcsFolderName = '.vcsgib',
43
43
  staged = false,
44
44
  worktree = false,
45
+ all = false,
45
46
  yes = false,
46
47
  force = false,
48
+ targetDir = process.cwd(),
49
+ vcsFolderName = '.vcsgib',
47
50
  quiet = false,
48
51
  }: RestoreCmdOpts = {}): Promise<RestoreCmdResult> {
49
52
  const lc = `${lcFile}[${executeRestoreCmd.name}]`;
50
53
  try {
51
54
  if (logalot) {
52
- console.log(`${lc} starting... (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1e)`);
55
+ console.log(`${lc} starting... (I: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
53
56
  }
54
57
 
55
58
  const absTargetDir = path.resolve(targetDir);
@@ -63,93 +66,70 @@ export async function executeRestoreCmd({
63
66
  try {
64
67
  await fs.access(vcsPath);
65
68
  } catch {
66
- throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2e)`);
69
+ throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d)`);
67
70
  }
68
71
 
69
72
  // Retrieve authoritative B2tFSIndexIbGib_V1 from space
70
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
73
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
71
74
  if (!indexIbGib) {
72
- throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3e)`);
75
+ throw new Error(`Repository not initialized. Run 'vcs init' first. (E: 3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d)`);
73
76
  }
74
77
 
75
- const activeBranch = indexIbGib.data?.activeBranch || 'main';
78
+ const activeBranch = resolveContextualBranchName({ targetDir: absTargetDir, repoRoot, indexIbGib });
76
79
  const activeWorktreeDir = activeBranch === 'main' ? repoRoot : path.join(repoRoot, 'b', activeBranch);
77
80
 
78
- const { space: activeSpace } = await getOrCreateBranchSpace({
81
+ const { space: activeBranchSpace } = await getOrCreateBranchSpace({
79
82
  metaspace,
80
83
  vcsPath,
81
84
  branchName: activeBranch,
82
85
  });
83
86
 
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
- }
87
+ const { space: workspaceSpace } = await getOrCreateWorkspaceProjectionSpace({
88
+ metaspace,
89
+ workspaceRoot: activeWorktreeDir,
90
+ vcsFolderName,
91
+ backingSpace: activeBranchSpace,
92
+ });
97
93
 
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
- }
94
+ const restoreRes = await executeVcsRestore({
95
+ metaspace,
96
+ localSpace,
97
+ activeBranchSpace,
98
+ workspaceSpace,
99
+ indexIbGib,
100
+ paths,
101
+ staged,
102
+ all,
103
+ targetDir: absTargetDir,
104
+ activeWorktreeDir,
105
+ });
115
106
 
116
- unstagedPaths = unstageRes.unstagedPaths;
117
- if (!quiet) {
118
- for (const p of unstagedPaths) {
119
- console.log(`unstaged: ${p}`);
120
- }
121
- }
107
+ if (staged && restoreRes.updatedIndex) {
108
+ await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: restoreRes.updatedIndex });
122
109
  }
123
110
 
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}`);
111
+ if (!quiet) {
112
+ if (staged) {
113
+ for (const unstagedPath of restoreRes.unstagedPaths) {
114
+ console.log(`unstaged: ${unstagedPath}`);
115
+ }
116
+ } else {
117
+ for (const restoredPath of restoreRes.restoredPaths) {
118
+ console.log(`restored: ${restoredPath}`);
139
119
  }
140
120
  }
141
121
  }
142
122
 
143
123
  return {
144
- unstagedPaths,
145
- restoredPaths,
124
+ restoredPaths: restoreRes.restoredPaths,
125
+ unstagedPaths: restoreRes.unstagedPaths,
146
126
  };
147
127
  } catch (error) {
148
128
  console.error(`${lc} ${extractErrorMsg(error)} (E: 9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4e)`);
149
129
  throw error;
150
130
  } finally {
151
131
  if (logalot) {
152
- console.log(`${lc} complete. (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5e)`);
132
+ console.log(`${lc} complete. (I: 0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5f)`);
153
133
  }
154
134
  }
155
135
  }
@@ -8,7 +8,7 @@ import path from 'node:path';
8
8
  import fs from 'node:fs/promises';
9
9
 
10
10
  import {
11
- respecfully, ifWe, iReckon
11
+ respecfully, ifWe, ifWeMight, iReckon
12
12
  } from '@ibgib/helper-gib/dist/respec-gib/respec-gib.mjs';
13
13
 
14
14
  import { executeInitCmd } from './init-cmd.mjs';
@@ -16,7 +16,7 @@ import { executeStatusCmd } from './status-cmd.mjs';
16
16
  import { executeAddCmd } from './add-cmd.mjs';
17
17
  import { executeCommitCmd } from './commit-cmd.mjs';
18
18
  import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
19
- import { getB2tFSIndexIbGib } from '../../engine/index/index-helper.mjs';
19
+ import { readVcsIndexProjectionFromDisk } from '../vcs-projection-helper.mjs';
20
20
 
21
21
  const lc = `[apps/vcs-gib/src/cli/commands/status-add-cmd.respec.node.mts]`;
22
22
 
@@ -142,7 +142,7 @@ await respecfully(lc, `vcs status and vcs add Command Handlers`, async () => {
142
142
  repoPath: testDir,
143
143
  vcsFolderName,
144
144
  });
145
- const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
145
+ const indexIbGib = await readVcsIndexProjectionFromDisk({ space: localSpace, vcsPath });
146
146
  iReckon(lc, Boolean(indexIbGib?.data?.staged_item && indexIbGib.data.staged_item.length > 0)).isGonnaBeTrue();
147
147
  iReckon(lc, indexIbGib?.rel8ns?.staged_item).isGonnaBeFalsy();
148
148