@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.
- package/dist/AUTO-GENERATED-version.d.mts +1 -1
- package/dist/AUTO-GENERATED-version.mjs +1 -1
- package/dist/bootstrap/node-bootstrap.d.mts.map +1 -1
- package/dist/bootstrap/node-bootstrap.mjs +7 -21
- package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
- package/dist/cli/commands/{add-cmd.d.mts → cli-add-cmd.d.mts} +3 -4
- package/dist/cli/commands/cli-add-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-add-cmd.mjs +45 -0
- package/dist/cli/commands/cli-add-cmd.mjs.map +1 -0
- package/dist/cli/commands/{branch-cmd.d.mts → cli-branch-cmd.d.mts} +9 -9
- package/dist/cli/commands/cli-branch-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-branch-cmd.mjs +59 -0
- package/dist/cli/commands/cli-branch-cmd.mjs.map +1 -0
- package/dist/cli/commands/cli-checkout-cmd.d.mts +20 -0
- package/dist/cli/commands/cli-checkout-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-checkout-cmd.mjs +50 -0
- package/dist/cli/commands/cli-checkout-cmd.mjs.map +1 -0
- package/dist/cli/commands/cli-commit-cmd.d.mts +23 -0
- package/dist/cli/commands/cli-commit-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-commit-cmd.mjs +52 -0
- package/dist/cli/commands/cli-commit-cmd.mjs.map +1 -0
- package/dist/cli/commands/{generate-comment-cmd.d.mts → cli-generate-comment-cmd.d.mts} +1 -1
- package/dist/cli/commands/cli-generate-comment-cmd.d.mts.map +1 -0
- package/dist/cli/commands/{generate-comment-cmd.mjs → cli-generate-comment-cmd.mjs} +11 -6
- package/dist/cli/commands/cli-generate-comment-cmd.mjs.map +1 -0
- package/dist/cli/commands/{init-cmd.d.mts → cli-init-cmd.d.mts} +3 -3
- package/dist/cli/commands/cli-init-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-init-cmd.mjs +47 -0
- package/dist/cli/commands/cli-init-cmd.mjs.map +1 -0
- package/dist/cli/commands/{log-cmd.d.mts → cli-log-cmd.d.mts} +3 -4
- package/dist/cli/commands/cli-log-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-log-cmd.mjs +90 -0
- package/dist/cli/commands/cli-log-cmd.mjs.map +1 -0
- package/dist/cli/commands/cli-merge-cmd.d.mts +22 -0
- package/dist/cli/commands/cli-merge-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-merge-cmd.mjs +66 -0
- package/dist/cli/commands/cli-merge-cmd.mjs.map +1 -0
- package/dist/cli/commands/{reset-cmd.d.mts → cli-reset-cmd.d.mts} +2 -2
- package/dist/cli/commands/cli-reset-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-reset-cmd.mjs +63 -0
- package/dist/cli/commands/cli-reset-cmd.mjs.map +1 -0
- package/dist/cli/commands/cli-restore-cmd.d.mts +23 -0
- package/dist/cli/commands/cli-restore-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-restore-cmd.mjs +55 -0
- package/dist/cli/commands/cli-restore-cmd.mjs.map +1 -0
- package/dist/cli/commands/{status-cmd.d.mts → cli-status-cmd.d.mts} +3 -3
- package/dist/cli/commands/cli-status-cmd.d.mts.map +1 -0
- package/dist/cli/commands/cli-status-cmd.mjs +96 -0
- package/dist/cli/commands/cli-status-cmd.mjs.map +1 -0
- package/dist/cli/vcs-cli-main.d.mts.map +1 -1
- package/dist/cli/vcs-cli-main.mjs +18 -15
- package/dist/cli/vcs-cli-main.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/cli/vcs-repo-helper.d.mts +19 -0
- package/dist/cli/vcs-repo-helper.d.mts.map +1 -0
- package/dist/cli/vcs-repo-helper.mjs +74 -0
- package/dist/cli/vcs-repo-helper.mjs.map +1 -0
- package/dist/test/test-helpers.d.mts +11 -2
- package/dist/test/test-helpers.d.mts.map +1 -1
- package/dist/test/test-helpers.mjs +35 -0
- package/dist/test/test-helpers.mjs.map +1 -1
- package/package.json +6 -6
- package/src/AUTO-GENERATED-version.mts +1 -1
- package/src/bootstrap/node-bootstrap.mts +7 -21
- package/src/bootstrap/node-bootstrap.respec.mts +2 -2
- package/src/cli/cli-arg-parser.respec.mts +2 -2
- package/src/cli/cli-e2e.respec.mts +12 -12
- package/src/cli/commands/branch-checkout-cmd.respec.mts +426 -412
- package/src/cli/commands/cli-add-cmd.mts +65 -0
- package/src/cli/commands/cli-branch-cmd.mts +87 -0
- package/src/cli/commands/cli-checkout-cmd.mts +72 -0
- package/src/cli/commands/cli-commit-cmd.mts +77 -0
- package/src/cli/commands/{generate-comment-cmd.mts → cli-generate-comment-cmd.mts} +12 -6
- package/src/cli/commands/cli-init-cmd.mts +78 -0
- package/src/cli/commands/cli-log-cmd.mts +126 -0
- package/src/cli/commands/cli-merge-cmd.mts +99 -0
- package/src/cli/commands/cli-reset-cmd.mts +94 -0
- package/src/cli/commands/cli-restore-cmd.mts +87 -0
- package/src/cli/commands/cli-status-cmd.mts +131 -0
- package/src/cli/commands/commit-log-cmd.respec.mts +85 -28
- package/src/cli/commands/init-cmd.respec.mts +3 -3
- package/src/cli/commands/reset-restore-cmd.respec.mts +9 -9
- package/src/cli/commands/status-add-cmd.respec.mts +21 -17
- package/src/cli/vcs-cli-main.mts +18 -15
- package/src/cli/vcs-projection-helper.mts +112 -0
- package/src/cli/vcs-repo-helper.mts +99 -0
- package/src/engine/branch/branch-space.respec.mts +23 -21
- package/src/engine/merge/b2tfs-sync-comments.respec.mts +11 -11
- package/src/test/test-helpers.mts +50 -2
- package/src/vcs-gib.respec.mts +25 -16
- package/tsconfig.test.tsbuildinfo +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vcs-gib_test_output.md +58 -0
- package/dist/cli/commands/add-cmd.d.mts.map +0 -1
- package/dist/cli/commands/add-cmd.mjs +0 -346
- package/dist/cli/commands/add-cmd.mjs.map +0 -1
- package/dist/cli/commands/branch-cmd.d.mts.map +0 -1
- package/dist/cli/commands/branch-cmd.mjs +0 -238
- package/dist/cli/commands/branch-cmd.mjs.map +0 -1
- package/dist/cli/commands/checkout-cmd.d.mts +0 -21
- package/dist/cli/commands/checkout-cmd.d.mts.map +0 -1
- package/dist/cli/commands/checkout-cmd.mjs +0 -174
- package/dist/cli/commands/checkout-cmd.mjs.map +0 -1
- package/dist/cli/commands/commit-cmd.d.mts +0 -24
- package/dist/cli/commands/commit-cmd.d.mts.map +0 -1
- package/dist/cli/commands/commit-cmd.mjs +0 -449
- package/dist/cli/commands/commit-cmd.mjs.map +0 -1
- package/dist/cli/commands/generate-comment-cmd.d.mts.map +0 -1
- package/dist/cli/commands/generate-comment-cmd.mjs.map +0 -1
- package/dist/cli/commands/init-cmd.d.mts.map +0 -1
- package/dist/cli/commands/init-cmd.mjs +0 -119
- package/dist/cli/commands/init-cmd.mjs.map +0 -1
- package/dist/cli/commands/log-cmd.d.mts.map +0 -1
- package/dist/cli/commands/log-cmd.mjs +0 -349
- package/dist/cli/commands/log-cmd.mjs.map +0 -1
- package/dist/cli/commands/merge-cmd.d.mts +0 -36
- package/dist/cli/commands/merge-cmd.d.mts.map +0 -1
- package/dist/cli/commands/merge-cmd.mjs +0 -292
- package/dist/cli/commands/merge-cmd.mjs.map +0 -1
- package/dist/cli/commands/reset-cmd.d.mts.map +0 -1
- package/dist/cli/commands/reset-cmd.mjs +0 -93
- package/dist/cli/commands/reset-cmd.mjs.map +0 -1
- package/dist/cli/commands/restore-cmd.d.mts +0 -22
- package/dist/cli/commands/restore-cmd.d.mts.map +0 -1
- package/dist/cli/commands/restore-cmd.mjs +0 -115
- package/dist/cli/commands/restore-cmd.mjs.map +0 -1
- package/dist/cli/commands/status-cmd.d.mts.map +0 -1
- package/dist/cli/commands/status-cmd.mjs +0 -132
- package/dist/cli/commands/status-cmd.mjs.map +0 -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/cli/commands/add-cmd.mts +0 -435
- package/src/cli/commands/branch-cmd.mts +0 -311
- package/src/cli/commands/checkout-cmd.mts +0 -227
- package/src/cli/commands/commit-cmd.mts +0 -557
- package/src/cli/commands/init-cmd.mts +0 -152
- package/src/cli/commands/log-cmd.mts +0 -449
- package/src/cli/commands/merge-cmd.mts +0 -363
- package/src/cli/commands/reset-cmd.mts +0 -128
- package/src/cli/commands/restore-cmd.mts +0 -155
- package/src/cli/commands/status-cmd.mts +0 -168
- 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,311 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module branch-cmd
|
|
3
|
-
*
|
|
4
|
-
* Command handler for `vcs branch [branchName]`.
|
|
5
|
-
* Lists registered branches or creates a new B2tFSBranchIbGib_V1 node registered in B2tFSIndexIbGib_V1.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import path from 'node:path';
|
|
9
|
-
import fs from 'node:fs/promises';
|
|
10
|
-
|
|
11
|
-
import { extractErrorMsg, getUUID } from '@ibgib/helper-gib/dist/helpers/utils-helper.mjs';
|
|
12
|
-
import { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
13
|
-
import { getIbGibsFromCache_fallbackToSpaces } from '@ibgib/core-gib/dist/common/other/ibgib-helper.mjs';
|
|
14
|
-
import { putInSpace } from '@ibgib/core-gib/dist/witness/space/space-helper.mjs';
|
|
15
|
-
|
|
16
|
-
import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
|
|
17
|
-
import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
|
|
18
|
-
import { createB2tFSBranchIbGib } from '../../engine/branch/branch-helper.mjs';
|
|
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';
|
|
24
|
-
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
25
|
-
|
|
26
|
-
const lcFile = `[branch-cmd]`;
|
|
27
|
-
const logalot = GLOBAL_LOG_A_LOT;
|
|
28
|
-
|
|
29
|
-
export interface BranchCmdOpts {
|
|
30
|
-
branchName?: string;
|
|
31
|
-
itemPath?: string;
|
|
32
|
-
targetDir?: string;
|
|
33
|
-
vcsFolderName?: string;
|
|
34
|
-
quiet?: boolean;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export interface BranchInfo {
|
|
38
|
-
name: string;
|
|
39
|
-
isActive: boolean;
|
|
40
|
-
addr: string;
|
|
41
|
-
rootItemAddr?: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export interface BranchCmdResult {
|
|
45
|
-
branches: BranchInfo[];
|
|
46
|
-
createdBranchName?: string;
|
|
47
|
-
createdBranchAddr?: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function executeBranchCmd({
|
|
51
|
-
branchName,
|
|
52
|
-
itemPath,
|
|
53
|
-
targetDir = process.cwd(),
|
|
54
|
-
vcsFolderName = '.vcsgib',
|
|
55
|
-
quiet = false,
|
|
56
|
-
}: BranchCmdOpts = {}): Promise<BranchCmdResult> {
|
|
57
|
-
const lc = `${lcFile}[${executeBranchCmd.name}]`;
|
|
58
|
-
try {
|
|
59
|
-
if (logalot) { console.log(`${lc} starting... (I: 4c3d2e1f0a9b8c7d6e5f4a3b2c1d0e9f)`); }
|
|
60
|
-
|
|
61
|
-
const absTargetDir = path.resolve(targetDir);
|
|
62
|
-
|
|
63
|
-
const { metaspace, localSpace, vcsPath } = await bootstrapVcsMetaspace({
|
|
64
|
-
repoPath: absTargetDir,
|
|
65
|
-
vcsFolderName,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Verify repo exists
|
|
69
|
-
try {
|
|
70
|
-
await fs.access(vcsPath);
|
|
71
|
-
} catch {
|
|
72
|
-
throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 5d4e3f2a1b0c9d8e7f6a5b4c3d2e1f0a)`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 1. Fetch authoritative repository index from localSpace
|
|
76
|
-
const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
|
|
77
|
-
if (!indexIbGib) {
|
|
78
|
-
throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 6e5f4a3b2c1d0e9f8a7b6c5d4e3f2a1b)`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const activeBranchName = indexIbGib.data?.activeBranch || 'main';
|
|
82
|
-
|
|
83
|
-
// Resolve active branch space b2s_<activeBranch>
|
|
84
|
-
const { space: activeBranchSpace } = await getOrCreateBranchSpace({
|
|
85
|
-
metaspace,
|
|
86
|
-
vcsPath,
|
|
87
|
-
branchName: activeBranchName,
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// 2. Fetch all registered branch ibgibs
|
|
91
|
-
const branchAddrs = [
|
|
92
|
-
...(indexIbGib.rel8ns?.branch || []),
|
|
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,
|
|
176
|
-
metaspace,
|
|
177
|
-
currentRelPath: '',
|
|
178
|
-
outMap: committedBranchItemsMap,
|
|
179
|
-
});
|
|
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
|
-
}
|
|
187
|
-
|
|
188
|
-
// Instantiate new branch space b2s_<newBranch>
|
|
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,
|
|
223
|
-
metaspace,
|
|
224
|
-
indexIbGib,
|
|
225
|
-
rel8nsToUpdate: {
|
|
226
|
-
branch: [sqNewBranchAddr],
|
|
227
|
-
branch_tjp: [sqNewBranchAddr],
|
|
228
|
-
},
|
|
229
|
-
vcsPath,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
if (!quiet) {
|
|
233
|
-
console.log(`Created branch '${trimmedBranchName}' (I: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5e)`);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// Return updated branch list
|
|
237
|
-
branchMap.set(trimmedBranchName, newBranchIbGib);
|
|
238
|
-
const branches: BranchInfo[] = [];
|
|
239
|
-
for (const [name, bNode] of branchMap.entries()) {
|
|
240
|
-
const addr = getIbGibAddr({ ibGib: bNode });
|
|
241
|
-
const itemAddr = bNode.rel8ns?.b2tfs_item?.at(0);
|
|
242
|
-
branches.push({
|
|
243
|
-
name,
|
|
244
|
-
isActive: name === activeBranchName,
|
|
245
|
-
addr,
|
|
246
|
-
rootItemAddr: itemAddr,
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
return {
|
|
251
|
-
branches,
|
|
252
|
-
createdBranchName: trimmedBranchName,
|
|
253
|
-
createdBranchAddr: newBranchAddr,
|
|
254
|
-
};
|
|
255
|
-
} catch (error) {
|
|
256
|
-
console.error(`${lc} ${extractErrorMsg(error)} (E: 1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a)`);
|
|
257
|
-
throw error;
|
|
258
|
-
} 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
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
// #endregion executeBranchCmd_walkBranchGraphForItems
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module checkout-cmd
|
|
3
|
-
*
|
|
4
|
-
* Command handler for `vcs checkout <branchName>`.
|
|
5
|
-
* Switches activeBranch in B2tFSIndexIbGib_V1 in localSpace and projects branch snapshot onto worktree path.
|
|
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 { getIbGibAddr } from '@ibgib/ts-gib/dist/helper.mjs';
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
import { bootstrapVcsMetaspace } from '../../bootstrap/node-bootstrap.mjs';
|
|
18
|
-
import { B2tFSBranchIbGib_V1 } from '../../engine/branch/branch-types.mjs';
|
|
19
|
-
import { getB2tFSBranchSpaceName } from '../../engine/branch/branch-helper.mjs';
|
|
20
|
-
import { getOrCreateBranchSpace } from '../../engine/branch/branch-space-helper.mjs';
|
|
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';
|
|
24
|
-
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
25
|
-
|
|
26
|
-
const lcFile = `[checkout-cmd]`;
|
|
27
|
-
const logalot = GLOBAL_LOG_A_LOT;
|
|
28
|
-
|
|
29
|
-
export interface CheckoutCmdOpts {
|
|
30
|
-
branchName?: string;
|
|
31
|
-
targetDir?: string;
|
|
32
|
-
vcsFolderName?: string;
|
|
33
|
-
quiet?: boolean;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export interface CheckoutCmdResult {
|
|
37
|
-
previousBranch: string;
|
|
38
|
-
currentBranch: string;
|
|
39
|
-
branchAddr: string;
|
|
40
|
-
rootItemAddr: string;
|
|
41
|
-
worktreePath: string;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export async function executeCheckoutCmd({
|
|
45
|
-
branchName,
|
|
46
|
-
targetDir = process.cwd(),
|
|
47
|
-
vcsFolderName = '.vcsgib',
|
|
48
|
-
quiet = false,
|
|
49
|
-
}: CheckoutCmdOpts = {}): Promise<CheckoutCmdResult> {
|
|
50
|
-
const lc = `${lcFile}[${executeCheckoutCmd.name}]`;
|
|
51
|
-
try {
|
|
52
|
-
if (logalot) {
|
|
53
|
-
console.log(`${lc} starting... (I: 3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8e)`);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const trimmedBranchName = branchName?.trim();
|
|
57
|
-
if (!trimmedBranchName) {
|
|
58
|
-
throw new Error(`Branch name is required for checkout (E: 4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d)`);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const absTargetDir = path.resolve(targetDir);
|
|
62
|
-
|
|
63
|
-
const { metaspace, localSpace, repoRoot, vcsPath } = await bootstrapVcsMetaspace({
|
|
64
|
-
repoPath: absTargetDir,
|
|
65
|
-
vcsFolderName,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Verify repo exists
|
|
69
|
-
try {
|
|
70
|
-
await fs.access(vcsPath);
|
|
71
|
-
} catch {
|
|
72
|
-
throw new Error(`Not an ibgib repository (directory ${vcsPath} does not exist) (E: 5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c0e)`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// 1. Fetch authoritative repository index from localSpace
|
|
76
|
-
const indexIbGib = await getB2tFSIndexIbGib({ space: localSpace, vcsPath });
|
|
77
|
-
if (!indexIbGib) {
|
|
78
|
-
throw new Error(`Repository index B2tFSIndexIbGib_V1 not found in localSpace (E: 6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f)`);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const previousBranch = indexIbGib.data?.activeBranch || 'main';
|
|
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>
|
|
114
|
-
const targetBranchSpaceRes = await getOrCreateBranchSpace({
|
|
115
|
-
metaspace,
|
|
116
|
-
vcsPath,
|
|
117
|
-
branchName: trimmedBranchName,
|
|
118
|
-
});
|
|
119
|
-
const targetBranchSpace = targetBranchSpaceRes.space;
|
|
120
|
-
|
|
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
|
-
const isDefaultBranch = trimmedBranchName === 'main';
|
|
163
|
-
const worktreePath = isDefaultBranch
|
|
164
|
-
? repoRoot
|
|
165
|
-
: path.join(repoRoot, 'b', trimmedBranchName);
|
|
166
|
-
|
|
167
|
-
await fs.mkdir(worktreePath, { recursive: true });
|
|
168
|
-
|
|
169
|
-
// Retrieve root item and project branch snapshot onto worktree subfolder:
|
|
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,
|
|
175
|
-
metaspace,
|
|
176
|
-
}) as B2tFSItemIbGib_V1;
|
|
177
|
-
|
|
178
|
-
if (rootItem) {
|
|
179
|
-
if (rootItem.data?.fsType === 'file') {
|
|
180
|
-
await writeB2tFSItemToFS({
|
|
181
|
-
item: rootItem,
|
|
182
|
-
destPath: worktreePath,
|
|
183
|
-
space: targetBranchSpace,
|
|
184
|
-
metaspace,
|
|
185
|
-
});
|
|
186
|
-
} else {
|
|
187
|
-
const childAddrs = rootItem.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
188
|
-
for (const childAddr of childAddrs) {
|
|
189
|
-
const childItem = await getIbGibWithMetaspaceFallback({
|
|
190
|
-
addr: childAddr,
|
|
191
|
-
space: targetBranchSpace,
|
|
192
|
-
metaspace,
|
|
193
|
-
}) as B2tFSItemIbGib_V1;
|
|
194
|
-
|
|
195
|
-
if (childItem) {
|
|
196
|
-
await writeB2tFSItemToFS({
|
|
197
|
-
item: childItem,
|
|
198
|
-
destPath: worktreePath,
|
|
199
|
-
space: targetBranchSpace,
|
|
200
|
-
metaspace,
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
if (!quiet) {
|
|
208
|
-
console.log(`Switched to branch '${trimmedBranchName}' (I: 9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c)`);
|
|
209
|
-
console.log(` Worktree projection: ${worktreePath}`);
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
return {
|
|
213
|
-
previousBranch,
|
|
214
|
-
currentBranch: trimmedBranchName,
|
|
215
|
-
branchAddr: targetBranchAddr,
|
|
216
|
-
rootItemAddr,
|
|
217
|
-
worktreePath,
|
|
218
|
-
};
|
|
219
|
-
} catch (error) {
|
|
220
|
-
console.error(`${lc} ${extractErrorMsg(error)} (E: 0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d)`);
|
|
221
|
-
throw error;
|
|
222
|
-
} finally {
|
|
223
|
-
if (logalot) {
|
|
224
|
-
console.log(`${lc} complete. (I: 1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e)`);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|