@ibgib/vcs-gib 0.0.6 → 0.0.18
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/README.md +24 -2
- package/VCS_CLI_USER_GUIDE.md +2 -2
- package/dist/AUTO-GENERATED-version.d.mts +1 -1
- package/dist/AUTO-GENERATED-version.d.mts.map +1 -1
- package/dist/AUTO-GENERATED-version.mjs +1 -1
- package/dist/AUTO-GENERATED-version.mjs.map +1 -1
- package/dist/bootstrap/node-bootstrap.d.mts.map +1 -1
- package/dist/bootstrap/node-bootstrap.mjs +9 -0
- package/dist/bootstrap/node-bootstrap.mjs.map +1 -1
- package/dist/bootstrap/{node-bootstrap.respec.node.d.mts → node-bootstrap.respec.d.mts} +1 -1
- package/dist/bootstrap/node-bootstrap.respec.d.mts.map +1 -0
- package/dist/bootstrap/{node-bootstrap.respec.node.mjs → node-bootstrap.respec.mjs} +1 -1
- package/dist/bootstrap/node-bootstrap.respec.mjs.map +1 -0
- package/dist/cli/cli-arg-parser.d.mts +3 -0
- package/dist/cli/cli-arg-parser.d.mts.map +1 -1
- package/dist/cli/cli-arg-parser.mjs +13 -1
- package/dist/cli/cli-arg-parser.mjs.map +1 -1
- package/dist/cli/{cli-arg-parser.respec.node.d.mts → cli-arg-parser.respec.d.mts} +1 -1
- package/dist/cli/cli-arg-parser.respec.d.mts.map +1 -0
- package/dist/cli/{cli-arg-parser.respec.node.mjs → cli-arg-parser.respec.mjs} +1 -1
- package/dist/cli/cli-arg-parser.respec.mjs.map +1 -0
- package/dist/cli/cli-constants.d.mts +6 -0
- package/dist/cli/cli-constants.d.mts.map +1 -1
- package/dist/cli/cli-constants.mjs +24 -0
- package/dist/cli/cli-constants.mjs.map +1 -1
- package/dist/cli/{cli-e2e.respec.node.d.mts → cli-e2e.respec.d.mts} +1 -1
- package/dist/cli/cli-e2e.respec.d.mts.map +1 -0
- package/dist/cli/{cli-e2e.respec.node.mjs → cli-e2e.respec.mjs} +2 -2
- package/dist/cli/cli-e2e.respec.mjs.map +1 -0
- package/dist/cli/commands/add-cmd.d.mts.map +1 -1
- package/dist/cli/commands/add-cmd.mjs +35 -30
- package/dist/cli/commands/add-cmd.mjs.map +1 -1
- package/dist/cli/commands/{branch-checkout-cmd.respec.node.d.mts → branch-checkout-cmd.respec.d.mts} +1 -1
- package/dist/cli/commands/branch-checkout-cmd.respec.d.mts.map +1 -0
- package/dist/cli/commands/{branch-checkout-cmd.respec.node.mjs → branch-checkout-cmd.respec.mjs} +172 -8
- package/dist/cli/commands/branch-checkout-cmd.respec.mjs.map +1 -0
- package/dist/cli/commands/branch-cmd.d.mts +2 -1
- package/dist/cli/commands/branch-cmd.d.mts.map +1 -1
- package/dist/cli/commands/branch-cmd.mjs +59 -8
- package/dist/cli/commands/branch-cmd.mjs.map +1 -1
- package/dist/cli/commands/checkout-cmd.d.mts.map +1 -1
- package/dist/cli/commands/checkout-cmd.mjs +38 -18
- package/dist/cli/commands/checkout-cmd.mjs.map +1 -1
- package/dist/cli/commands/commit-cmd.d.mts.map +1 -1
- package/dist/cli/commands/commit-cmd.mjs +26 -23
- package/dist/cli/commands/commit-cmd.mjs.map +1 -1
- package/dist/cli/commands/{commit-log-cmd.respec.node.d.mts → commit-log-cmd.respec.d.mts} +1 -1
- package/dist/cli/commands/commit-log-cmd.respec.d.mts.map +1 -0
- package/dist/cli/commands/{commit-log-cmd.respec.node.mjs → commit-log-cmd.respec.mjs} +1 -1
- package/dist/cli/commands/commit-log-cmd.respec.mjs.map +1 -0
- package/dist/cli/commands/{init-cmd.respec.node.d.mts → init-cmd.respec.d.mts} +1 -1
- package/dist/cli/commands/init-cmd.respec.d.mts.map +1 -0
- package/dist/cli/commands/{init-cmd.respec.node.mjs → init-cmd.respec.mjs} +1 -1
- package/dist/cli/commands/init-cmd.respec.mjs.map +1 -0
- package/dist/cli/commands/merge-cmd.d.mts +23 -0
- package/dist/cli/commands/merge-cmd.d.mts.map +1 -0
- package/dist/cli/commands/merge-cmd.mjs +224 -0
- package/dist/cli/commands/merge-cmd.mjs.map +1 -0
- package/dist/cli/commands/reset-cmd.d.mts +21 -0
- package/dist/cli/commands/reset-cmd.d.mts.map +1 -0
- package/dist/cli/commands/reset-cmd.mjs +93 -0
- package/dist/cli/commands/reset-cmd.mjs.map +1 -0
- package/dist/cli/commands/reset-restore-cmd.respec.d.mts +7 -0
- package/dist/cli/commands/reset-restore-cmd.respec.d.mts.map +1 -0
- package/dist/cli/commands/reset-restore-cmd.respec.mjs +185 -0
- package/dist/cli/commands/reset-restore-cmd.respec.mjs.map +1 -0
- package/dist/cli/commands/restore-cmd.d.mts +22 -0
- package/dist/cli/commands/restore-cmd.d.mts.map +1 -0
- package/dist/cli/commands/restore-cmd.mjs +115 -0
- package/dist/cli/commands/restore-cmd.mjs.map +1 -0
- package/dist/cli/commands/{status-add-cmd.respec.node.d.mts → status-add-cmd.respec.d.mts} +1 -1
- package/dist/cli/commands/status-add-cmd.respec.d.mts.map +1 -0
- package/dist/cli/commands/{status-add-cmd.respec.node.mjs → status-add-cmd.respec.mjs} +25 -1
- package/dist/cli/commands/status-add-cmd.respec.mjs.map +1 -0
- package/dist/cli/vcs-cli-main.d.mts.map +1 -1
- package/dist/cli/vcs-cli-main.mjs +36 -3
- package/dist/cli/vcs-cli-main.mjs.map +1 -1
- package/dist/engine/branch/branch-graph-helper.d.mts +12 -3
- package/dist/engine/branch/branch-graph-helper.d.mts.map +1 -1
- package/dist/engine/branch/branch-graph-helper.mjs +50 -18
- package/dist/engine/branch/branch-graph-helper.mjs.map +1 -1
- package/dist/engine/branch/branch-space-helper.d.mts +1 -0
- package/dist/engine/branch/branch-space-helper.d.mts.map +1 -1
- package/dist/engine/branch/branch-space-helper.mjs +1 -0
- package/dist/engine/branch/branch-space-helper.mjs.map +1 -1
- package/dist/engine/branch/{branch-space.respec.node.d.mts → branch-space.respec.d.mts} +1 -1
- package/dist/engine/branch/branch-space.respec.d.mts.map +1 -0
- package/dist/engine/branch/{branch-space.respec.node.mjs → branch-space.respec.mjs} +12 -7
- package/dist/engine/branch/branch-space.respec.mjs.map +1 -0
- package/dist/engine/diff/{line-diff-helper.respec.node.d.mts → line-diff-helper.respec.d.mts} +1 -1
- package/dist/engine/diff/line-diff-helper.respec.d.mts.map +1 -0
- package/dist/engine/diff/{line-diff-helper.respec.node.mjs → line-diff-helper.respec.mjs} +1 -1
- package/dist/engine/diff/line-diff-helper.respec.mjs.map +1 -0
- package/dist/engine/filter/{glob-helper.respec.node.d.mts → glob-helper.respec.d.mts} +1 -1
- package/dist/engine/filter/glob-helper.respec.d.mts.map +1 -0
- package/dist/engine/filter/{glob-helper.respec.node.mjs → glob-helper.respec.mjs} +1 -1
- package/dist/engine/filter/glob-helper.respec.mjs.map +1 -0
- package/dist/engine/index/index-helper.d.mts +35 -0
- package/dist/engine/index/index-helper.d.mts.map +1 -1
- package/dist/engine/index/index-helper.mjs +241 -0
- package/dist/engine/index/index-helper.mjs.map +1 -1
- package/dist/engine/item/item-helper.d.mts +29 -3
- package/dist/engine/item/item-helper.d.mts.map +1 -1
- package/dist/engine/item/item-helper.mjs +234 -56
- package/dist/engine/item/item-helper.mjs.map +1 -1
- package/dist/engine/item/item.respec.d.mts +7 -0
- package/dist/engine/item/item.respec.d.mts.map +1 -0
- package/dist/engine/item/item.respec.mjs +75 -0
- package/dist/engine/item/item.respec.mjs.map +1 -0
- package/dist/engine/merge/b2tfs-3way-merge-strategy.d.mts +38 -0
- package/dist/engine/merge/b2tfs-3way-merge-strategy.d.mts.map +1 -0
- package/dist/engine/merge/b2tfs-3way-merge-strategy.mjs +593 -0
- package/dist/engine/merge/b2tfs-3way-merge-strategy.mjs.map +1 -0
- package/dist/engine/merge/b2tfs-merge-strategy.respec.d.mts +7 -0
- package/dist/engine/merge/b2tfs-merge-strategy.respec.d.mts.map +1 -0
- package/dist/engine/merge/b2tfs-merge-strategy.respec.mjs +335 -0
- package/dist/engine/merge/b2tfs-merge-strategy.respec.mjs.map +1 -0
- package/dist/respec-gib.node.mjs +1 -1
- package/dist/respec-gib.node.mjs.map +1 -1
- package/dist/{vcs-gib.respec.node.d.mts → vcs-gib.respec.d.mts} +1 -1
- package/dist/vcs-gib.respec.d.mts.map +1 -0
- package/dist/{vcs-gib.respec.node.mjs → vcs-gib.respec.mjs} +1 -1
- package/dist/vcs-gib.respec.mjs.map +1 -0
- package/package.json +3 -3
- package/src/AUTO-GENERATED-version.mts +1 -1
- package/src/bootstrap/node-bootstrap.mts +6 -0
- package/src/cli/cli-arg-parser.mts +15 -0
- package/src/cli/cli-constants.mts +27 -0
- package/src/cli/{cli-e2e.respec.node.mts → cli-e2e.respec.mts} +2 -2
- package/src/cli/commands/add-cmd.mts +41 -29
- package/src/cli/commands/{branch-checkout-cmd.respec.node.mts → branch-checkout-cmd.respec.mts} +190 -8
- package/src/cli/commands/branch-cmd.mts +78 -8
- package/src/cli/commands/checkout-cmd.mts +48 -23
- package/src/cli/commands/commit-cmd.mts +35 -26
- package/src/cli/commands/merge-cmd.mts +289 -0
- package/src/cli/commands/reset-cmd.mts +128 -0
- package/src/cli/commands/reset-restore-cmd.respec.mts +222 -0
- package/src/cli/commands/restore-cmd.mts +155 -0
- package/src/cli/commands/{status-add-cmd.respec.node.mts → status-add-cmd.respec.mts} +27 -0
- package/src/cli/vcs-cli-main.mts +36 -3
- package/src/engine/branch/branch-graph-helper.mts +66 -18
- package/src/engine/branch/branch-space-helper.mts +6 -0
- package/src/engine/branch/{branch-space.respec.node.mts → branch-space.respec.mts} +12 -6
- package/src/engine/index/index-helper.mts +324 -0
- package/src/engine/item/item-helper.mts +284 -58
- package/src/engine/item/item.respec.mts +92 -0
- package/src/engine/merge/b2tfs-3way-merge-strategy.mts +725 -0
- package/src/engine/merge/b2tfs-merge-strategy.respec.mts +438 -0
- package/src/respec-gib.node.mts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/bootstrap/node-bootstrap.respec.node.d.mts.map +0 -1
- package/dist/bootstrap/node-bootstrap.respec.node.mjs.map +0 -1
- package/dist/cli/cli-arg-parser.respec.node.d.mts.map +0 -1
- package/dist/cli/cli-arg-parser.respec.node.mjs.map +0 -1
- package/dist/cli/cli-e2e.respec.node.d.mts.map +0 -1
- package/dist/cli/cli-e2e.respec.node.mjs.map +0 -1
- package/dist/cli/commands/branch-checkout-cmd.respec.node.d.mts.map +0 -1
- package/dist/cli/commands/branch-checkout-cmd.respec.node.mjs.map +0 -1
- package/dist/cli/commands/commit-log-cmd.respec.node.d.mts.map +0 -1
- package/dist/cli/commands/commit-log-cmd.respec.node.mjs.map +0 -1
- package/dist/cli/commands/init-cmd.respec.node.d.mts.map +0 -1
- package/dist/cli/commands/init-cmd.respec.node.mjs.map +0 -1
- package/dist/cli/commands/status-add-cmd.respec.node.d.mts.map +0 -1
- package/dist/cli/commands/status-add-cmd.respec.node.mjs.map +0 -1
- package/dist/engine/branch/branch-space.respec.node.d.mts.map +0 -1
- package/dist/engine/branch/branch-space.respec.node.mjs.map +0 -1
- package/dist/engine/diff/line-diff-helper.respec.node.d.mts.map +0 -1
- package/dist/engine/diff/line-diff-helper.respec.node.mjs.map +0 -1
- package/dist/engine/filter/glob-helper.respec.node.d.mts.map +0 -1
- package/dist/engine/filter/glob-helper.respec.node.mjs.map +0 -1
- package/dist/vcs-gib.respec.node.d.mts.map +0 -1
- package/dist/vcs-gib.respec.node.mjs.map +0 -1
- package/test_runs/001-hello-node/20260728_090100_0001-flow-core-main.md +0 -39
- package/test_runs/001-hello-node/20260728_090200_0003-flow-branching-worktree.md +0 -54
- package/test_runs/001-hello-node/20260728_090300_0002-flow-selective-add.md +0 -45
- package/test_runs/001-hello-node/20260728_142100_0007-flow-edge-cases.md +0 -44
- package/test_runs/001-hello-node/20260728_142400_0005-flow-hardcoded-ignores.md +0 -36
- package/tools/pack-for-test.mjs +0 -73
- /package/src/bootstrap/{node-bootstrap.respec.node.mts → node-bootstrap.respec.mts} +0 -0
- /package/src/cli/{cli-arg-parser.respec.node.mts → cli-arg-parser.respec.mts} +0 -0
- /package/src/cli/commands/{commit-log-cmd.respec.node.mts → commit-log-cmd.respec.mts} +0 -0
- /package/src/cli/commands/{init-cmd.respec.node.mts → init-cmd.respec.mts} +0 -0
- /package/src/engine/diff/{line-diff-helper.respec.node.mts → line-diff-helper.respec.mts} +0 -0
- /package/src/engine/filter/{glob-helper.respec.node.mts → glob-helper.respec.mts} +0 -0
- /package/src/{vcs-gib.respec.node.mts → vcs-gib.respec.mts} +0 -0
|
@@ -18,6 +18,9 @@ import { putInSpace, persistTransformResult } from '@ibgib/core-gib/dist/witness
|
|
|
18
18
|
|
|
19
19
|
import { GLOBAL_LOG_A_LOT } from '../../vcs-gib-constants.mjs';
|
|
20
20
|
import { SpaceQualifiedIbGibAddr, B2tFSIndexIbGib_V1, B2tFSIndexData_V1, B2tFSIndexRel8ns_V1 } from './index-types.mjs';
|
|
21
|
+
import { B2tFSBranchIbGib_V1 } from '../branch/branch-types.mjs';
|
|
22
|
+
import { B2tFSItemIbGib_V1, B2TFS_CHILD_ITEM_REL8N_NAME } from '../item/item-types.mjs';
|
|
23
|
+
import { getIbGibWithMetaspaceFallback, writeB2tFSItemToFS } from '../item/item-helper.mjs';
|
|
21
24
|
|
|
22
25
|
const lcFile = `[index-helper]`;
|
|
23
26
|
const logalot = GLOBAL_LOG_A_LOT;
|
|
@@ -376,3 +379,324 @@ export async function writeVcsIndexProjection({
|
|
|
376
379
|
}
|
|
377
380
|
}
|
|
378
381
|
}
|
|
382
|
+
|
|
383
|
+
export interface UnstagePathsFromIndexOpts {
|
|
384
|
+
indexIbGib: B2tFSIndexIbGib_V1;
|
|
385
|
+
paths?: string[];
|
|
386
|
+
targetDir?: string;
|
|
387
|
+
activeWorktreeDir?: string;
|
|
388
|
+
vcsPath?: string;
|
|
389
|
+
space: IbGibSpaceAny;
|
|
390
|
+
metaspace: MetaspaceService;
|
|
391
|
+
all?: boolean;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
export interface UnstagePathsFromIndexResult {
|
|
395
|
+
updatedIndex: B2tFSIndexIbGib_V1;
|
|
396
|
+
unstagedPaths: string[];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Unstages specified paths (or all paths if `all` or empty `paths`) from `indexIbGib.data.stagedPaths`
|
|
401
|
+
* and `indexIbGib.data.staged_item`.
|
|
402
|
+
*/
|
|
403
|
+
export async function unstagePathsFromIndex({
|
|
404
|
+
indexIbGib,
|
|
405
|
+
paths = [],
|
|
406
|
+
targetDir = process.cwd(),
|
|
407
|
+
activeWorktreeDir,
|
|
408
|
+
vcsPath,
|
|
409
|
+
space,
|
|
410
|
+
metaspace,
|
|
411
|
+
all = false,
|
|
412
|
+
}: UnstagePathsFromIndexOpts): Promise<UnstagePathsFromIndexResult> {
|
|
413
|
+
const lc = `${lcFile}[${unstagePathsFromIndex.name}]`;
|
|
414
|
+
try {
|
|
415
|
+
if (logalot) {
|
|
416
|
+
console.log(`${lc} starting... (I: 6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d)`);
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
const currentStagedPaths = { ...(indexIbGib.data?.stagedPaths || {}) };
|
|
420
|
+
let currentStagedItems = [...(indexIbGib.data?.staged_item || [])];
|
|
421
|
+
const unstagedPaths: string[] = [];
|
|
422
|
+
|
|
423
|
+
const worktreeDir = activeWorktreeDir || targetDir;
|
|
424
|
+
|
|
425
|
+
if (all || paths.length === 0 || (paths.length === 1 && (paths[0] === '.' || paths[0] === ''))) {
|
|
426
|
+
for (const relPath of Object.keys(currentStagedPaths)) {
|
|
427
|
+
unstagedPaths.push(relPath);
|
|
428
|
+
}
|
|
429
|
+
const updatedIndex = await updateB2tFSIndexIbGib({
|
|
430
|
+
space,
|
|
431
|
+
metaspace,
|
|
432
|
+
indexIbGib,
|
|
433
|
+
dataToUpdate: {
|
|
434
|
+
stagedPaths: {},
|
|
435
|
+
staged_item: [],
|
|
436
|
+
},
|
|
437
|
+
vcsPath,
|
|
438
|
+
});
|
|
439
|
+
return { updatedIndex, unstagedPaths };
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
for (const p of paths) {
|
|
443
|
+
let relPath = p.replace(/\\/g, '/');
|
|
444
|
+
if (path.isAbsolute(p)) {
|
|
445
|
+
relPath = path.relative(worktreeDir, p).replace(/\\/g, '/');
|
|
446
|
+
} else if (targetDir !== worktreeDir) {
|
|
447
|
+
const absP = path.resolve(targetDir, p);
|
|
448
|
+
relPath = path.relative(worktreeDir, absP).replace(/\\/g, '/');
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
const targetKeys = Object.keys(currentStagedPaths).filter((k) => {
|
|
452
|
+
return k === relPath || k.startsWith(relPath + '/');
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
for (const key of targetKeys) {
|
|
456
|
+
const record = currentStagedPaths[key];
|
|
457
|
+
if (record && record.itemAddr) {
|
|
458
|
+
currentStagedItems = currentStagedItems.filter((addr) => addr !== record.itemAddr);
|
|
459
|
+
}
|
|
460
|
+
delete currentStagedPaths[key];
|
|
461
|
+
if (!unstagedPaths.includes(key)) {
|
|
462
|
+
unstagedPaths.push(key);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
const updatedIndex = await updateB2tFSIndexIbGib({
|
|
468
|
+
space,
|
|
469
|
+
metaspace,
|
|
470
|
+
indexIbGib,
|
|
471
|
+
dataToUpdate: {
|
|
472
|
+
stagedPaths: currentStagedPaths,
|
|
473
|
+
staged_item: currentStagedItems,
|
|
474
|
+
},
|
|
475
|
+
vcsPath,
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
return { updatedIndex, unstagedPaths };
|
|
479
|
+
} catch (error) {
|
|
480
|
+
console.error(`${lc} ${extractErrorMsg(error)} (E: 7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e)`);
|
|
481
|
+
throw error;
|
|
482
|
+
} finally {
|
|
483
|
+
if (logalot) {
|
|
484
|
+
console.log(`${lc} complete. (I: 8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f)`);
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
export interface RestoreWorktreePathsOpts {
|
|
490
|
+
paths?: string[];
|
|
491
|
+
targetDir?: string;
|
|
492
|
+
activeWorktreeDir: string;
|
|
493
|
+
activeBranchSpace: IbGibSpaceAny;
|
|
494
|
+
metaspace: MetaspaceService;
|
|
495
|
+
indexIbGib?: B2tFSIndexIbGib_V1;
|
|
496
|
+
vcsPath?: string;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
export interface RestoreWorktreePathsResult {
|
|
500
|
+
restoredPaths: string[];
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* Restores working tree physical files from committed branch item snapshot.
|
|
505
|
+
*/
|
|
506
|
+
export async function restoreWorktreePathsFromSnapshot({
|
|
507
|
+
paths = [],
|
|
508
|
+
targetDir = process.cwd(),
|
|
509
|
+
activeWorktreeDir,
|
|
510
|
+
activeBranchSpace,
|
|
511
|
+
metaspace,
|
|
512
|
+
indexIbGib,
|
|
513
|
+
vcsPath,
|
|
514
|
+
}: RestoreWorktreePathsOpts): Promise<RestoreWorktreePathsResult> {
|
|
515
|
+
const lc = `${lcFile}[${restoreWorktreePathsFromSnapshot.name}]`;
|
|
516
|
+
try {
|
|
517
|
+
if (logalot) {
|
|
518
|
+
console.log(`${lc} starting... (I: 9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a)`);
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
let currIndex = indexIbGib;
|
|
522
|
+
if (!currIndex) {
|
|
523
|
+
currIndex = await getB2tFSIndexIbGib({ space: activeBranchSpace, vcsPath });
|
|
524
|
+
}
|
|
525
|
+
if (!currIndex) {
|
|
526
|
+
throw new Error(`Repository index B2tFSIndexIbGib_V1 not found (E: 0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b)`);
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const activeBranch = currIndex.data?.activeBranch || 'main';
|
|
530
|
+
const branchAddrs = [
|
|
531
|
+
...(currIndex.rel8ns?.branch || []),
|
|
532
|
+
...(currIndex.rel8ns?.branch_tjp || []),
|
|
533
|
+
];
|
|
534
|
+
|
|
535
|
+
let branchIbGibs: B2tFSBranchIbGib_V1[] = [];
|
|
536
|
+
if (branchAddrs.length > 0) {
|
|
537
|
+
for (const bAddr of branchAddrs) {
|
|
538
|
+
const bIbGib = await getIbGibWithMetaspaceFallback({
|
|
539
|
+
addr: bAddr,
|
|
540
|
+
space: activeBranchSpace,
|
|
541
|
+
metaspace,
|
|
542
|
+
});
|
|
543
|
+
if (bIbGib) {
|
|
544
|
+
branchIbGibs.push(bIbGib as B2tFSBranchIbGib_V1);
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const activeBranchIbGib = branchIbGibs.find(
|
|
550
|
+
(b) => b?.data?.name === activeBranch,
|
|
551
|
+
) || (branchIbGibs.at(0) as B2tFSBranchIbGib_V1);
|
|
552
|
+
|
|
553
|
+
if (!activeBranchIbGib) {
|
|
554
|
+
throw new Error(`Branch '${activeBranch}' not found (E: 1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c)`);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
const rootItemAddr = activeBranchIbGib.rel8ns?.b2tfs_item?.at(0);
|
|
558
|
+
if (!rootItemAddr) {
|
|
559
|
+
throw new Error(`Branch '${activeBranch}' has no root item (E: 2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d)`);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
const rootItem = await getIbGibWithMetaspaceFallback({
|
|
563
|
+
addr: rootItemAddr,
|
|
564
|
+
space: activeBranchSpace,
|
|
565
|
+
metaspace,
|
|
566
|
+
}) as B2tFSItemIbGib_V1;
|
|
567
|
+
|
|
568
|
+
if (!rootItem) {
|
|
569
|
+
throw new Error(`Root item node '${rootItemAddr}' could not be fetched (E: 3f7e6d5c4b3a2f1e0d9c8b7a6f5e4d3c)`);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const committedItemMap = new Map<string, { relPath: string; parentRelPath: string; item: B2tFSItemIbGib_V1 }>();
|
|
573
|
+
|
|
574
|
+
await restoreCmd_collectCommittedItems({
|
|
575
|
+
item: rootItem,
|
|
576
|
+
parentRelPath: '',
|
|
577
|
+
space: activeBranchSpace,
|
|
578
|
+
metaspace,
|
|
579
|
+
outMap: committedItemMap,
|
|
580
|
+
});
|
|
581
|
+
|
|
582
|
+
const restoredPaths: string[] = [];
|
|
583
|
+
|
|
584
|
+
if (paths.length === 0 || (paths.length === 1 && (paths[0] === '.' || paths[0] === ''))) {
|
|
585
|
+
for (const entry of committedItemMap.values()) {
|
|
586
|
+
const destPath = path.join(activeWorktreeDir, entry.parentRelPath);
|
|
587
|
+
await writeB2tFSItemToFS({
|
|
588
|
+
item: entry.item,
|
|
589
|
+
destPath,
|
|
590
|
+
space: activeBranchSpace,
|
|
591
|
+
metaspace,
|
|
592
|
+
});
|
|
593
|
+
restoredPaths.push(entry.relPath);
|
|
594
|
+
}
|
|
595
|
+
} else {
|
|
596
|
+
for (const p of paths) {
|
|
597
|
+
let relPath = p.replace(/\\/g, '/');
|
|
598
|
+
if (path.isAbsolute(p)) {
|
|
599
|
+
relPath = path.relative(activeWorktreeDir, p).replace(/\\/g, '/');
|
|
600
|
+
} else if (targetDir !== activeWorktreeDir) {
|
|
601
|
+
const absP = path.resolve(targetDir, p);
|
|
602
|
+
relPath = path.relative(activeWorktreeDir, absP).replace(/\\/g, '/');
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
let matchedCount = 0;
|
|
606
|
+
for (const entry of committedItemMap.values()) {
|
|
607
|
+
if (entry.relPath === relPath || entry.relPath.startsWith(relPath + '/')) {
|
|
608
|
+
const destPath = path.join(activeWorktreeDir, entry.parentRelPath);
|
|
609
|
+
await writeB2tFSItemToFS({
|
|
610
|
+
item: entry.item,
|
|
611
|
+
destPath,
|
|
612
|
+
space: activeBranchSpace,
|
|
613
|
+
metaspace,
|
|
614
|
+
});
|
|
615
|
+
if (!restoredPaths.includes(entry.relPath)) {
|
|
616
|
+
restoredPaths.push(entry.relPath);
|
|
617
|
+
}
|
|
618
|
+
matchedCount++;
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
if (matchedCount === 0) {
|
|
623
|
+
throw new Error(`pathspec '${p}' did not match any committed file(s) in snapshot (E: 4f5a6b7c8d9e0f1a2b3c4d5e6f7a8b9c)`);
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
return { restoredPaths };
|
|
629
|
+
} catch (error) {
|
|
630
|
+
console.error(`${lc} ${extractErrorMsg(error)} (E: 5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b)`);
|
|
631
|
+
throw error;
|
|
632
|
+
} finally {
|
|
633
|
+
if (logalot) {
|
|
634
|
+
console.log(`${lc} complete. (I: 6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b)`);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// #region restoreCmd_collectCommittedItems
|
|
640
|
+
async function restoreCmd_collectCommittedItems({
|
|
641
|
+
item,
|
|
642
|
+
parentRelPath,
|
|
643
|
+
space,
|
|
644
|
+
metaspace,
|
|
645
|
+
outMap,
|
|
646
|
+
}: {
|
|
647
|
+
item: B2tFSItemIbGib_V1;
|
|
648
|
+
parentRelPath: string;
|
|
649
|
+
space: IbGibSpaceAny;
|
|
650
|
+
metaspace: MetaspaceService;
|
|
651
|
+
outMap: Map<string, { relPath: string; parentRelPath: string; item: B2tFSItemIbGib_V1 }>;
|
|
652
|
+
}): Promise<void> {
|
|
653
|
+
if (!item || !item.data) { return; }
|
|
654
|
+
|
|
655
|
+
const { fsType, name } = item.data;
|
|
656
|
+
|
|
657
|
+
if (fsType === 'folder' && !parentRelPath) {
|
|
658
|
+
const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
659
|
+
for (const childAddr of childAddrs) {
|
|
660
|
+
const childItem = await getIbGibWithMetaspaceFallback({
|
|
661
|
+
addr: childAddr,
|
|
662
|
+
space,
|
|
663
|
+
metaspace,
|
|
664
|
+
}) as B2tFSItemIbGib_V1;
|
|
665
|
+
|
|
666
|
+
if (childItem) {
|
|
667
|
+
await restoreCmd_collectCommittedItems({
|
|
668
|
+
item: childItem,
|
|
669
|
+
parentRelPath: '',
|
|
670
|
+
space,
|
|
671
|
+
metaspace,
|
|
672
|
+
outMap,
|
|
673
|
+
});
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
} else {
|
|
677
|
+
const relPath = parentRelPath ? `${parentRelPath}/${name}` : name;
|
|
678
|
+
outMap.set(relPath, { relPath, parentRelPath, item });
|
|
679
|
+
|
|
680
|
+
if (fsType === 'folder') {
|
|
681
|
+
const childAddrs = item.rel8ns?.[B2TFS_CHILD_ITEM_REL8N_NAME] || [];
|
|
682
|
+
for (const childAddr of childAddrs) {
|
|
683
|
+
const childItem = await getIbGibWithMetaspaceFallback({
|
|
684
|
+
addr: childAddr,
|
|
685
|
+
space,
|
|
686
|
+
metaspace,
|
|
687
|
+
}) as B2tFSItemIbGib_V1;
|
|
688
|
+
|
|
689
|
+
if (childItem) {
|
|
690
|
+
await restoreCmd_collectCommittedItems({
|
|
691
|
+
item: childItem,
|
|
692
|
+
parentRelPath: relPath,
|
|
693
|
+
space,
|
|
694
|
+
metaspace,
|
|
695
|
+
outMap,
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
// #endregion restoreCmd_collectCommittedItems
|