@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.
- package/dist/AUTO-GENERATED-version.d.mts +1 -1
- package/dist/AUTO-GENERATED-version.mjs +1 -1
- package/dist/bootstrap/node-bootstrap.mjs +1 -1
- package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
- package/dist/cli/commands/add-cmd.d.mts +2 -3
- package/dist/cli/commands/add-cmd.d.mts.map +1 -1
- package/dist/cli/commands/add-cmd.mjs +30 -283
- package/dist/cli/commands/add-cmd.mjs.map +1 -1
- package/dist/cli/commands/branch-cmd.d.mts +8 -8
- package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
- package/dist/cli/commands/branch-cmd.mjs +45 -176
- package/dist/cli/commands/branch-cmd.mjs.map +1 -1
- package/dist/cli/commands/checkout-cmd.d.mts +2 -4
- package/dist/cli/commands/checkout-cmd.d.mts.map +1 -1
- package/dist/cli/commands/checkout-cmd.mjs +31 -110
- package/dist/cli/commands/checkout-cmd.mjs.map +1 -1
- package/dist/cli/commands/commit-cmd.d.mts +7 -8
- package/dist/cli/commands/commit-cmd.d.mts.map +1 -1
- package/dist/cli/commands/commit-cmd.mjs +40 -390
- package/dist/cli/commands/commit-cmd.mjs.map +1 -1
- package/dist/cli/commands/generate-comment-cmd.d.mts.map +1 -1
- package/dist/cli/commands/generate-comment-cmd.mjs +5 -2
- package/dist/cli/commands/generate-comment-cmd.mjs.map +1 -1
- package/dist/cli/commands/init-cmd.d.mts +2 -2
- package/dist/cli/commands/init-cmd.d.mts.map +1 -1
- package/dist/cli/commands/init-cmd.mjs +20 -70
- package/dist/cli/commands/init-cmd.mjs.map +1 -1
- package/dist/cli/commands/log-cmd.d.mts +2 -3
- package/dist/cli/commands/log-cmd.d.mts.map +1 -1
- package/dist/cli/commands/log-cmd.mjs +42 -271
- package/dist/cli/commands/log-cmd.mjs.map +1 -1
- package/dist/cli/commands/merge-cmd.d.mts +3 -17
- package/dist/cli/commands/merge-cmd.d.mts.map +1 -1
- package/dist/cli/commands/merge-cmd.mjs +32 -218
- package/dist/cli/commands/merge-cmd.mjs.map +1 -1
- package/dist/cli/commands/reset-cmd.d.mts +1 -1
- package/dist/cli/commands/reset-cmd.d.mts.map +1 -1
- package/dist/cli/commands/reset-cmd.mjs +17 -19
- package/dist/cli/commands/reset-cmd.mjs.map +1 -1
- package/dist/cli/commands/restore-cmd.d.mts +8 -7
- package/dist/cli/commands/restore-cmd.d.mts.map +1 -1
- package/dist/cli/commands/restore-cmd.mjs +44 -62
- package/dist/cli/commands/restore-cmd.mjs.map +1 -1
- package/dist/cli/commands/status-cmd.d.mts +2 -2
- package/dist/cli/commands/status-cmd.d.mts.map +1 -1
- package/dist/cli/commands/status-cmd.mjs +63 -62
- package/dist/cli/commands/status-cmd.mjs.map +1 -1
- package/dist/cli/vcs-projection-helper.d.mts +23 -0
- package/dist/cli/vcs-projection-helper.d.mts.map +1 -0
- package/dist/cli/vcs-projection-helper.mjs +91 -0
- package/dist/cli/vcs-projection-helper.mjs.map +1 -0
- package/dist/test/test-helpers.d.mts +2 -2
- package/dist/test/test-helpers.d.mts.map +1 -1
- package/package.json +3 -3
- package/src/AUTO-GENERATED-version.mts +1 -1
- package/src/bootstrap/node-bootstrap.mts +1 -1
- package/src/cli/cli-e2e.respec.mts +4 -4
- package/src/cli/commands/add-cmd.mts +32 -347
- package/src/cli/commands/branch-cmd.mts +56 -225
- package/src/cli/commands/checkout-cmd.mts +34 -138
- package/src/cli/commands/commit-cmd.mts +46 -473
- package/src/cli/commands/commit-log-cmd.respec.mts +11 -7
- package/src/cli/commands/generate-comment-cmd.mts +6 -2
- package/src/cli/commands/init-cmd.mts +20 -73
- package/src/cli/commands/log-cmd.mts +41 -331
- package/src/cli/commands/merge-cmd.mts +32 -252
- package/src/cli/commands/reset-cmd.mts +17 -19
- package/src/cli/commands/restore-cmd.mts +52 -72
- package/src/cli/commands/status-add-cmd.respec.mts +3 -3
- package/src/cli/commands/status-cmd.mts +68 -63
- package/src/cli/vcs-projection-helper.mts +112 -0
- package/src/engine/branch/branch-space.respec.mts +5 -5
- package/src/engine/merge/b2tfs-sync-comments.respec.mts +4 -4
- package/src/test/test-helpers.mts +2 -2
- package/src/vcs-gib.respec.mts +11 -8
- package/tsconfig.test.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/engine/branch/branch-graph-helper.d.mts +0 -28
- package/dist/engine/branch/branch-graph-helper.d.mts.map +0 -1
- package/dist/engine/branch/branch-graph-helper.mjs +0 -81
- package/dist/engine/branch/branch-graph-helper.mjs.map +0 -1
- package/dist/engine/branch/branch-helper.d.mts +0 -40
- package/dist/engine/branch/branch-helper.d.mts.map +0 -1
- package/dist/engine/branch/branch-helper.mjs +0 -78
- package/dist/engine/branch/branch-helper.mjs.map +0 -1
- package/dist/engine/branch/branch-space-helper.d.mts +0 -23
- package/dist/engine/branch/branch-space-helper.d.mts.map +0 -1
- package/dist/engine/branch/branch-space-helper.mjs +0 -78
- package/dist/engine/branch/branch-space-helper.mjs.map +0 -1
- package/dist/engine/branch/branch-types.d.mts +0 -26
- package/dist/engine/branch/branch-types.d.mts.map +0 -1
- package/dist/engine/branch/branch-types.mjs +0 -7
- package/dist/engine/branch/branch-types.mjs.map +0 -1
- package/dist/engine/diff/line-diff-helper.d.mts +0 -76
- package/dist/engine/diff/line-diff-helper.d.mts.map +0 -1
- package/dist/engine/diff/line-diff-helper.mjs +0 -144
- package/dist/engine/diff/line-diff-helper.mjs.map +0 -1
- package/dist/engine/filter/glob-helper.d.mts +0 -51
- package/dist/engine/filter/glob-helper.d.mts.map +0 -1
- package/dist/engine/filter/glob-helper.mjs +0 -132
- package/dist/engine/filter/glob-helper.mjs.map +0 -1
- package/dist/engine/index/index-helper.d.mts +0 -113
- package/dist/engine/index/index-helper.d.mts.map +0 -1
- package/dist/engine/index/index-helper.mjs +0 -533
- package/dist/engine/index/index-helper.mjs.map +0 -1
- package/dist/engine/index/index-types.d.mts +0 -63
- package/dist/engine/index/index-types.d.mts.map +0 -1
- package/dist/engine/index/index-types.mjs +0 -7
- package/dist/engine/index/index-types.mjs.map +0 -1
- package/dist/engine/item/item-atom-helper.d.mts +0 -20
- package/dist/engine/item/item-atom-helper.d.mts.map +0 -1
- package/dist/engine/item/item-atom-helper.mjs +0 -30
- package/dist/engine/item/item-atom-helper.mjs.map +0 -1
- package/dist/engine/item/item-helper.d.mts +0 -94
- package/dist/engine/item/item-helper.d.mts.map +0 -1
- package/dist/engine/item/item-helper.mjs +0 -424
- package/dist/engine/item/item-helper.mjs.map +0 -1
- package/dist/engine/item/item-types.d.mts +0 -128
- package/dist/engine/item/item-types.d.mts.map +0 -1
- package/dist/engine/item/item-types.mjs +0 -16
- package/dist/engine/item/item-types.mjs.map +0 -1
- package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts +0 -74
- package/dist/engine/merge/b2tfs-3way-graft-strategy.d.mts.map +0 -1
- package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs +0 -570
- package/dist/engine/merge/b2tfs-3way-graft-strategy.mjs.map +0 -1
- package/dist/engine/merge/b2tfs-3way-graft-types.d.mts +0 -34
- package/dist/engine/merge/b2tfs-3way-graft-types.d.mts.map +0 -1
- package/dist/engine/merge/b2tfs-3way-graft-types.mjs +0 -2
- package/dist/engine/merge/b2tfs-3way-graft-types.mjs.map +0 -1
- package/dist/engine/status/status-helper.d.mts +0 -90
- package/dist/engine/status/status-helper.d.mts.map +0 -1
- package/dist/engine/status/status-helper.mjs +0 -286
- package/dist/engine/status/status-helper.mjs.map +0 -1
- package/src/engine/branch/branch-graph-helper.mts +0 -117
- package/src/engine/branch/branch-helper.mts +0 -112
- package/src/engine/branch/branch-space-helper.mts +0 -110
- package/src/engine/branch/branch-types.mts +0 -29
- package/src/engine/diff/line-diff-helper.mts +0 -210
- package/src/engine/diff/line-diff-helper.respec.mts +0 -84
- package/src/engine/filter/glob-helper.mts +0 -165
- package/src/engine/filter/glob-helper.respec.mts +0 -94
- package/src/engine/index/index-helper.mts +0 -705
- package/src/engine/index/index-types.mts +0 -66
- package/src/engine/item/item-atom-helper.mts +0 -30
- package/src/engine/item/item-helper.mts +0 -544
- package/src/engine/item/item-types.mts +0 -137
- package/src/engine/item/item.respec.mts +0 -92
- package/src/engine/merge/b2tfs-3way-graft-strategy.mts +0 -630
- package/src/engine/merge/b2tfs-3way-graft-strategy.respec.mts +0 -346
- package/src/engine/merge/b2tfs-3way-graft-types.mts +0 -34
- package/src/engine/status/status-helper.mts +0 -383
|
@@ -1,31 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module branch-cmd
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* CLI command handler for `vcs branch [branchName]`.
|
|
5
|
+
* Delegates to executeVcsBranch 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
|
-
import { extractErrorMsg
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import { putInSpace } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
11
|
+
import { extractErrorMsg } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
+
import { executeVcsBranch } from '@ibgib/core-gib/dist/vcs/commands/branch-cmd.mjs';
|
|
13
|
+
import { resolveContextualBranchName } from '@ibgib/core-gib/dist/vcs/branch/branch-helper.mjs';
|
|
15
14
|
|
|
16
15
|
import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
|
|
20
|
-
import { populateBranchSpaceFromGraph } from '../../engine/branch/branch-graph-helper.mjs';
|
|
21
|
-
import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
|
|
22
|
-
import { getIbGibWithMetaspaceFallback } from '../../engine/item/item-helper.mjs';
|
|
23
|
-
import { getB2tFSIndexIbGib, updateB2tFSIndexIbGib, getSpaceQualifiedIbGibAddr } from '../../engine/index/index-helper.mjs';
|
|
16
|
+
import { getOrCreateBranchSpace } from '@ibgib/node-gib/dist/vcs/branch-space-helper.mjs';
|
|
17
|
+
import { readVcsIndexProjectionFromDisk, writeVcsIndexProjectionToDisk } from '../vcs-projection-helper.mjs';
|
|
24
18
|
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
25
19
|
|
|
26
20
|
const lcFile = `[branch-cmd]`;
|
|
27
21
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
28
22
|
|
|
23
|
+
export interface BranchInfo {
|
|
24
|
+
name: string;
|
|
25
|
+
isActive: boolean;
|
|
26
|
+
addr: string;
|
|
27
|
+
rootItemAddr?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
29
30
|
export interface BranchCmdOpts {
|
|
30
31
|
branchName?: string;
|
|
31
32
|
itemPath?: string;
|
|
@@ -34,13 +35,6 @@ export interface BranchCmdOpts {
|
|
|
34
35
|
quiet?: boolean;
|
|
35
36
|
}
|
|
36
37
|
|
|
37
|
-
export interface BranchInfo {
|
|
38
|
-
name: string;
|
|
39
|
-
isActive: boolean;
|
|
40
|
-
addr: string;
|
|
41
|
-
rootItemAddr?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
38
|
export interface BranchCmdResult {
|
|
45
39
|
branches: BranchInfo[];
|
|
46
40
|
createdBranchName?: string;
|
|
@@ -60,7 +54,7 @@ export async function executeBranchCmd({
|
|
|
60
54
|
|
|
61
55
|
const absTargetDir = path.resolve(targetDir);
|
|
62
56
|
|
|
63
|
-
const { metaspace, localSpace, vcsPath } = await bootstrapVcsMetaspace({
|
|
57
|
+
const { metaspace, localSpace, vcsPath, repoRoot } = await bootstrapVcsMetaspace({
|
|
64
58
|
repoPath: absTargetDir,
|
|
65
59
|
vcsFolderName,
|
|
66
60
|
});
|
|
@@ -73,12 +67,16 @@ export async function executeBranchCmd({
|
|
|
73
67
|
}
|
|
74
68
|
|
|
75
69
|
// 1. Fetch authoritative repository index from localSpace
|
|
76
|
-
const indexIbGib = await
|
|
70
|
+
const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
|
|
77
71
|
if (!indexIbGib) {
|
|
78
72
|
throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b)`);
|
|
79
73
|
}
|
|
80
74
|
|
|
81
|
-
const activeBranchName =
|
|
75
|
+
const activeBranchName = resolveContextualBranchName({
|
|
76
|
+
targetDir: absTargetDir,
|
|
77
|
+
repoRoot,
|
|
78
|
+
indexIbGib,
|
|
79
|
+
});
|
|
82
80
|
|
|
83
81
|
// Resolve active branch space b2s_<activeBranch>
|
|
84
82
|
const { space: activeBranchSpace } = await getOrCreateBranchSpace({
|
|
@@ -87,225 +85,58 @@ export async function executeBranchCmd({
|
|
|
87
85
|
branchName: activeBranchName,
|
|
88
86
|
});
|
|
89
87
|
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
...(indexIbGib.rel8ns?.branch_tjp || []),
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
|
|
97
|
-
if (branchAddrs.length > 0) {
|
|
98
|
-
for (const bAddr of branchAddrs) {
|
|
99
|
-
const bIbGib = await getIbGibWithMetaspaceFallback({
|
|
100
|
-
addr: bAddr,
|
|
101
|
-
space: activeBranchSpace,
|
|
102
|
-
metaspace,
|
|
103
|
-
});
|
|
104
|
-
if (bIbGib) {
|
|
105
|
-
branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Deduplicate branch nodes by branch name
|
|
111
|
-
const branchMap = new Map<string, B2tFSBranchIbGib_V1>();
|
|
112
|
-
for (const b of branchIbGibs) {
|
|
113
|
-
if (b?.data?.name) {
|
|
114
|
-
branchMap.set(b.data.name, b);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
const trimmedBranchName = branchName?.trim();
|
|
119
|
-
|
|
120
|
-
if (!trimmedBranchName) {
|
|
121
|
-
// LIST BRANCHES
|
|
122
|
-
const branches: BranchInfo[] = [];
|
|
123
|
-
for (const [name, bNode] of branchMap.entries()) {
|
|
124
|
-
const addr = getIbGibAddr({ ibGib: bNode });
|
|
125
|
-
const rootItemAddr = bNode.rel8ns?.b2tfs_item?.at(-1);
|
|
126
|
-
const isActive = name === activeBranchName;
|
|
127
|
-
branches.push({
|
|
128
|
-
name,
|
|
129
|
-
isActive,
|
|
130
|
-
addr,
|
|
131
|
-
rootItemAddr,
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (!quiet) {
|
|
136
|
-
for (const b of branches) {
|
|
137
|
-
const prefix = b.isActive ? '* ' : ' ';
|
|
138
|
-
console.log(`${prefix}${b.name}`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
return { branches };
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// CREATE BRANCH
|
|
147
|
-
if (branchMap.has(trimmedBranchName)) {
|
|
148
|
-
throw new Error(`Branch '${trimmedBranchName}' already exists (E: 7f6a5b4c3d2e1f0a9b8c7d6e5f4a3b2c)`);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Find active branch root item to fork from
|
|
152
|
-
const activeBranchIbGib = branchMap.get(activeBranchName) || branchIbGibs.at(0);
|
|
153
|
-
const rootItemAddr = activeBranchIbGib?.rel8ns?.b2tfs_item?.at(-1);
|
|
154
|
-
|
|
155
|
-
if (!rootItemAddr) {
|
|
156
|
-
throw new Error(`Cannot find active branch root item to fork branch from (E: 8f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c)`);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const rootItem = await getIbGibWithMetaspaceFallback({
|
|
160
|
-
addr: rootItemAddr,
|
|
161
|
-
space: activeBranchSpace,
|
|
162
|
-
metaspace,
|
|
163
|
-
}) as B2tFSItemIbGib_V1;
|
|
164
|
-
|
|
165
|
-
if (!rootItem) {
|
|
166
|
-
throw new Error(`Root item node for address '${rootItemAddr}' not found in localSpace (E: 9b8c7d6e5f4a3b2c1d0e9f8a7b6c5d4e)`);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
let targetRootItem: B2tFSItemIbGib_V1 = rootItem;
|
|
170
|
-
if (itemPath && itemPath.trim().length > 0) {
|
|
171
|
-
const normalizedItemPath = itemPath.trim().replace(/\\/g, '/').replace(/^\.\//, '');
|
|
172
|
-
const committedBranchItemsMap = new Map<string, B2tFSItemIbGib_V1>();
|
|
173
|
-
await executeBranchCmd_walkBranchGraphForItems({
|
|
174
|
-
item: rootItem,
|
|
175
|
-
space: activeBranchSpace,
|
|
88
|
+
// If creating a branch, ensure target branch space exists on Node
|
|
89
|
+
if (branchName && branchName.trim().length > 0) {
|
|
90
|
+
await getOrCreateBranchSpace({
|
|
176
91
|
metaspace,
|
|
177
|
-
|
|
178
|
-
|
|
92
|
+
vcsPath,
|
|
93
|
+
branchName: branchName.trim(),
|
|
179
94
|
});
|
|
180
|
-
|
|
181
|
-
const targetItemNode = committedBranchItemsMap.get(normalizedItemPath);
|
|
182
|
-
if (!targetItemNode) {
|
|
183
|
-
throw new Error(`Item '${itemPath}' not found in active branch snapshot (E: 8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b3c)`);
|
|
184
|
-
}
|
|
185
|
-
targetRootItem = targetItemNode;
|
|
186
95
|
}
|
|
187
96
|
|
|
188
|
-
|
|
189
|
-
const { space: newBranchSpace, spaceId: newBranchSpaceId } = await getOrCreateBranchSpace({
|
|
190
|
-
metaspace,
|
|
191
|
-
vcsPath,
|
|
192
|
-
branchName: trimmedBranchName,
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
// Populate new branch space from live dependency graph of targetRootItem
|
|
196
|
-
await populateBranchSpaceFromGraph({
|
|
197
|
-
sourceSpace: activeBranchSpace,
|
|
198
|
-
targetBranchSpace: newBranchSpace,
|
|
199
|
-
rootItemIbGib: targetRootItem,
|
|
200
|
-
metaspace,
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
// Create new B2tFSBranchIbGib_V1 branch node inside newBranchSpace
|
|
204
|
-
const newBranchIbGib = await createB2tFSBranchIbGib({
|
|
205
|
-
branchName: trimmedBranchName,
|
|
206
|
-
rootItem: targetRootItem,
|
|
207
|
-
space: newBranchSpace,
|
|
208
|
-
metaspace,
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
// Put in activeBranchSpace so active index can reference it
|
|
212
|
-
await putInSpace({ space: activeBranchSpace, ibGib: newBranchIbGib });
|
|
213
|
-
|
|
214
|
-
const newBranchAddr = getIbGibAddr({ ibGib: newBranchIbGib });
|
|
215
|
-
const sqNewBranchAddr = getSpaceQualifiedIbGibAddr({
|
|
216
|
-
spaceId: newBranchSpaceId,
|
|
217
|
-
ibGibAddr: newBranchAddr,
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
// Register new branch node in B2tFSIndexIbGib_V1 using space-qualified address
|
|
221
|
-
await updateB2tFSIndexIbGib({
|
|
222
|
-
space: activeBranchSpace,
|
|
97
|
+
const branchRes = await executeVcsBranch({
|
|
223
98
|
metaspace,
|
|
99
|
+
localSpace,
|
|
100
|
+
activeBranchSpace,
|
|
224
101
|
indexIbGib,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
102
|
+
branchName,
|
|
103
|
+
itemPath,
|
|
104
|
+
repoRoot,
|
|
105
|
+
targetDir: absTargetDir,
|
|
106
|
+
vcsFolderName,
|
|
230
107
|
});
|
|
231
108
|
|
|
232
|
-
if (
|
|
233
|
-
|
|
109
|
+
if (branchRes.updatedIndex) {
|
|
110
|
+
await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: branchRes.updatedIndex });
|
|
234
111
|
}
|
|
235
112
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
113
|
+
const branches: BranchInfo[] = branchRes.branches.map(b => ({
|
|
114
|
+
name: b.name,
|
|
115
|
+
isActive: b.isActive,
|
|
116
|
+
addr: b.commitAddr || '',
|
|
117
|
+
rootItemAddr: b.rootItemAddr,
|
|
118
|
+
}));
|
|
119
|
+
|
|
120
|
+
if (!quiet) {
|
|
121
|
+
if (!branchName) {
|
|
122
|
+
for (const b of branches) {
|
|
123
|
+
const prefix = b.isActive ? '* ' : ' ';
|
|
124
|
+
console.log(`${prefix}${b.name}`);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
console.log(`Created branch '${branchRes.createdBranchName}'`);
|
|
128
|
+
}
|
|
248
129
|
}
|
|
249
130
|
|
|
250
131
|
return {
|
|
251
132
|
branches,
|
|
252
|
-
createdBranchName:
|
|
253
|
-
createdBranchAddr:
|
|
133
|
+
createdBranchName: branchRes.createdBranchName,
|
|
134
|
+
createdBranchAddr: branchRes.createdBranchAddr,
|
|
254
135
|
};
|
|
255
136
|
} catch (error) {
|
|
256
137
|
console.error(`${lc} ${extractErrorMsg(error)} (E: 1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a)`);
|
|
257
138
|
throw error;
|
|
258
139
|
} finally {
|
|
259
|
-
if (logalot) {
|
|
260
|
-
console.log(`${lc} complete. (I: 2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b)`);
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
// #region executeBranchCmd_walkBranchGraphForItems
|
|
266
|
-
async function executeBranchCmd_walkBranchGraphForItems({
|
|
267
|
-
item,
|
|
268
|
-
space,
|
|
269
|
-
metaspace,
|
|
270
|
-
currentRelPath,
|
|
271
|
-
outMap,
|
|
272
|
-
}: {
|
|
273
|
-
item: B2tFSItemIbGib_V1;
|
|
274
|
-
space: any;
|
|
275
|
-
metaspace?: any;
|
|
276
|
-
currentRelPath: string;
|
|
277
|
-
outMap: Map<string, B2tFSItemIbGib_V1>;
|
|
278
|
-
}): Promise<void> {
|
|
279
|
-
if (!item || !item.data) { return; }
|
|
280
|
-
|
|
281
|
-
const { fsType } = item.data;
|
|
282
|
-
|
|
283
|
-
if (currentRelPath) {
|
|
284
|
-
outMap.set(currentRelPath, item);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
if (fsType === 'folder') {
|
|
288
|
-
const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
289
|
-
for (const childAddr of childAddrs) {
|
|
290
|
-
const childItem = await getIbGibWithMetaspaceFallback({
|
|
291
|
-
addr: childAddr,
|
|
292
|
-
space,
|
|
293
|
-
metaspace,
|
|
294
|
-
}) as B2tFSItemIbGib_V1;
|
|
295
|
-
|
|
296
|
-
if (childItem && childItem.data) {
|
|
297
|
-
const childRelPath = currentRelPath
|
|
298
|
-
? `${currentRelPath}/${childItem.data.name}`
|
|
299
|
-
: childItem.data.name;
|
|
300
|
-
await executeBranchCmd_walkBranchGraphForItems({
|
|
301
|
-
item: childItem,
|
|
302
|
-
space,
|
|
303
|
-
metaspace,
|
|
304
|
-
currentRelPath: childRelPath,
|
|
305
|
-
outMap,
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
}
|
|
140
|
+
if (logalot) { console.log(`${lc} complete. (I: 2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b)`); }
|
|
309
141
|
}
|
|
310
142
|
}
|
|
311
|
-
// #endregion executeBranchCmd_walkBranchGraphForItems
|
|
@@ -1,26 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module checkout-cmd
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* CLI command handler for `vcs checkout <branchName>`.
|
|
5
|
+
* Bootstraps workspace projection space, delegates to executeVcsCheckout, and writes projection cache.
|
|
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 {
|
|
13
|
-
import { getIbGibsFromCache_fallbackToSpaces } from '@ibgib/core-gib/dist/common/other/ibgib-helper.mjs';
|
|
14
|
-
import { putInSpace, getLatestAddrs } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
15
|
-
|
|
12
|
+
import { executeVcsCheckout } from '@ibgib/core-gib/dist/vcs/commands/checkout-cmd.mjs';
|
|
16
13
|
|
|
17
14
|
import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
21
|
-
import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../../engine/item/item-types.mjs';
|
|
22
|
-
import { writeB2tFSItemToFS, getIbGibWithMetaspaceFallback } from '../../engine/item/item-helper.mjs';
|
|
23
|
-
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';
|
|
24
18
|
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
25
19
|
|
|
26
20
|
const lcFile = `[checkout-cmd]`;
|
|
@@ -36,8 +30,6 @@ export interface CheckoutCmdOpts {
|
|
|
36
30
|
export interface CheckoutCmdResult {
|
|
37
31
|
previousBranch: string;
|
|
38
32
|
currentBranch: string;
|
|
39
|
-
branchAddr: string;
|
|
40
|
-
rootItemAddr: string;
|
|
41
33
|
worktreePath: string;
|
|
42
34
|
}
|
|
43
35
|
|
|
@@ -49,9 +41,7 @@ export async function executeCheckoutCmd({
|
|
|
49
41
|
}: CheckoutCmdOpts = {}): Promise<CheckoutCmdResult> {
|
|
50
42
|
const lc = `${lcFile}[${executeCheckoutCmd.name}]`;
|
|
51
43
|
try {
|
|
52
|
-
if (logalot) {
|
|
53
|
-
console.log(`${lc} starting... (I: 3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8e)`);
|
|
54
|
-
}
|
|
44
|
+
if (logalot) { console.log(`${lc} starting... (I: 3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e)`); }
|
|
55
45
|
|
|
56
46
|
const trimmedBranchName = branchName?.trim();
|
|
57
47
|
if (!trimmedBranchName) {
|
|
@@ -73,44 +63,12 @@ export async function executeCheckoutCmd({
|
|
|
73
63
|
}
|
|
74
64
|
|
|
75
65
|
// 1. Fetch authoritative repository index from localSpace
|
|
76
|
-
const indexIbGib = await
|
|
66
|
+
const indexIbGib = await readVcsIndexProjectionFromDisk({ vcsPath, space: localSpace });
|
|
77
67
|
if (!indexIbGib) {
|
|
78
68
|
throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f)`);
|
|
79
69
|
}
|
|
80
70
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
// 2. Fetch all registered branch ibgibs
|
|
84
|
-
const branchAddrs = [
|
|
85
|
-
...(indexIbGib.rel8ns?.branch || []),
|
|
86
|
-
...(indexIbGib.rel8ns?.branch_tjp || []),
|
|
87
|
-
];
|
|
88
|
-
|
|
89
|
-
let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
|
|
90
|
-
if (branchAddrs.length > 0) {
|
|
91
|
-
for (const bAddr of branchAddrs) {
|
|
92
|
-
const bIbGib = await getIbGibWithMetaspaceFallback({
|
|
93
|
-
addr: bAddr,
|
|
94
|
-
space: localSpace,
|
|
95
|
-
metaspace,
|
|
96
|
-
});
|
|
97
|
-
if (bIbGib) {
|
|
98
|
-
branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Find target branch node
|
|
104
|
-
const targetBranchIbGib = branchIbGibs.findLast(
|
|
105
|
-
(b) => b?.data?.name === trimmedBranchName,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
if (!targetBranchIbGib) {
|
|
110
|
-
throw new Error(`Branch '${trimmedBranchName}' does not exist (E: 7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a)`);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// 3. Resolve target branch space b2s_<branchName>
|
|
71
|
+
// 2. Resolve target branch space b2s_<branchName>
|
|
114
72
|
const targetBranchSpaceRes = await getOrCreateBranchSpace({
|
|
115
73
|
metaspace,
|
|
116
74
|
vcsPath,
|
|
@@ -118,47 +76,6 @@ export async function executeCheckoutCmd({
|
|
|
118
76
|
});
|
|
119
77
|
const targetBranchSpace = targetBranchSpaceRes.space;
|
|
120
78
|
|
|
121
|
-
const targetBranchAddr = getIbGibAddr({ ibGib: targetBranchIbGib });
|
|
122
|
-
const targetBranchTjpAddr = targetBranchIbGib.rel8ns?.tjp?.at(0) || targetBranchAddr;
|
|
123
|
-
const latestTargetBranchRes = await getLatestAddrs({ space: targetBranchSpace, addrs: [targetBranchTjpAddr] });
|
|
124
|
-
const latestTargetBranchAddr = (latestTargetBranchRes?.data as any)?.latestAddrs?.[0] || targetBranchAddr;
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const latestTargetBranchIbGib = (await getIbGibWithMetaspaceFallback({
|
|
128
|
-
addr: latestTargetBranchAddr,
|
|
129
|
-
space: targetBranchSpace,
|
|
130
|
-
metaspace,
|
|
131
|
-
})) as B2tFSBranchIbGib_V1 || targetBranchIbGib;
|
|
132
|
-
|
|
133
|
-
const rootItemAddr = latestTargetBranchIbGib.rel8ns?.b2tfs_item?.at(-1);
|
|
134
|
-
|
|
135
|
-
if (!rootItemAddr) {
|
|
136
|
-
throw new Error(`Branch '${trimmedBranchName}' does not have a valid root item address (E: 8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b)`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
await putInSpace({ space: targetBranchSpace, ibGib: targetBranchIbGib });
|
|
141
|
-
|
|
142
|
-
// Update activeBranch in B2tFSIndexIbGib_V1 in targetBranchSpace and localSpace
|
|
143
|
-
const updatedIndex = await updateB2tFSIndexIbGib({
|
|
144
|
-
space: targetBranchSpace,
|
|
145
|
-
metaspace,
|
|
146
|
-
indexIbGib,
|
|
147
|
-
dataToUpdate: {
|
|
148
|
-
activeBranch: trimmedBranchName,
|
|
149
|
-
activeSpaceId: getB2tFSBranchSpaceName(trimmedBranchName),
|
|
150
|
-
mySpaceId: targetBranchSpaceRes.spaceId,
|
|
151
|
-
},
|
|
152
|
-
vcsPath,
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
if (localSpace !== targetBranchSpace) {
|
|
156
|
-
await putInSpace({ space: localSpace, ibGib: updatedIndex });
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// 4. Project branch snapshot onto worktree subfolder:
|
|
160
|
-
// 'main' -> repoRoot
|
|
161
|
-
// other branches -> repoRoot/b/<branch_name>/
|
|
162
79
|
const isDefaultBranch = trimmedBranchName === 'main';
|
|
163
80
|
const worktreePath = isDefaultBranch
|
|
164
81
|
? repoRoot
|
|
@@ -166,62 +83,41 @@ export async function executeCheckoutCmd({
|
|
|
166
83
|
|
|
167
84
|
await fs.mkdir(worktreePath, { recursive: true });
|
|
168
85
|
|
|
169
|
-
|
|
170
|
-
// If rootItem is a single file, write it directly to worktreePath (my-repo/b/<branchName>/<fileName>).
|
|
171
|
-
// If rootItem is a folder, write child items into worktreePath.
|
|
172
|
-
const rootItem = await getIbGibWithMetaspaceFallback({
|
|
173
|
-
addr: rootItemAddr,
|
|
174
|
-
space: targetBranchSpace,
|
|
86
|
+
const { space: workspaceSpace } = await getOrCreateWorkspaceProjectionSpace({
|
|
175
87
|
metaspace,
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (childItem) {
|
|
196
|
-
await writeB2tFSItemToFS({
|
|
197
|
-
item: childItem,
|
|
198
|
-
destPath: worktreePath,
|
|
199
|
-
space: targetBranchSpace,
|
|
200
|
-
metaspace,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
88
|
+
workspaceRoot: worktreePath,
|
|
89
|
+
vcsFolderName,
|
|
90
|
+
backingSpace: targetBranchSpace,
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const checkoutRes = await executeVcsCheckout({
|
|
94
|
+
metaspace,
|
|
95
|
+
localSpace,
|
|
96
|
+
targetBranchSpace,
|
|
97
|
+
workspaceSpace,
|
|
98
|
+
indexIbGib,
|
|
99
|
+
branchName: trimmedBranchName,
|
|
100
|
+
repoRoot,
|
|
101
|
+
targetDir: absTargetDir,
|
|
102
|
+
vcsFolderName,
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
await writeVcsIndexProjectionToDisk({ vcsPath, indexIbGib: checkoutRes.updatedIndex });
|
|
206
106
|
|
|
207
107
|
if (!quiet) {
|
|
208
|
-
console.log(`Switched to branch '${trimmedBranchName}' (I:
|
|
209
|
-
console.log(`
|
|
108
|
+
console.log(`Switched to branch '${trimmedBranchName}' (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d)`);
|
|
109
|
+
console.log(`Worktree path: ${worktreePath}`);
|
|
210
110
|
}
|
|
211
111
|
|
|
212
112
|
return {
|
|
213
|
-
previousBranch,
|
|
214
|
-
currentBranch:
|
|
215
|
-
branchAddr: targetBranchAddr,
|
|
216
|
-
rootItemAddr,
|
|
113
|
+
previousBranch: checkoutRes.previousBranch,
|
|
114
|
+
currentBranch: checkoutRes.currentBranch,
|
|
217
115
|
worktreePath,
|
|
218
116
|
};
|
|
219
117
|
} catch (error) {
|
|
220
|
-
console.error(`${lc} ${extractErrorMsg(error)} (E:
|
|
118
|
+
console.error(`${lc} ${extractErrorMsg(error)} (E: 1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d)`);
|
|
221
119
|
throw error;
|
|
222
120
|
} finally {
|
|
223
|
-
if (logalot) {
|
|
224
|
-
console.log(`${lc} complete. (I: 1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e)`);
|
|
225
|
-
}
|
|
121
|
+
if (logalot) { console.log(`${lc} complete. (I: 2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e)`); }
|
|
226
122
|
}
|
|
227
123
|
}
|