MCPcopy Create free account
hub / github.com/decaporg/decap-cms / updateTree

Method updateTree

packages/decap-cms-backend-github/src/API.ts:1449–1517  ·  view source on GitHub ↗
(
    baseSha: string,
    files: { path: string; sha: string | null; newPath?: string }[],
    branch = this.branch,
    hasSubfolders = true,
  )

Source from the content-addressed store, hash-verified

1447 }
1448
1449 async updateTree(
1450 baseSha: string,
1451 files: { path: string; sha: string | null; newPath?: string }[],
1452 branch = this.branch,
1453 hasSubfolders = true,
1454 ) {
1455 const toMove: { from: string; to: string; sha: string }[] = [];
1456 const tree = files.reduce((acc, file) => {
1457 const entry = {
1458 path: trimStart(file.path, '/'),
1459 mode: '100644',
1460 type: 'blob',
1461 sha: file.sha,
1462 } as TreeEntry;
1463
1464 if (file.newPath) {
1465 toMove.push({ from: file.path, to: file.newPath, sha: file.sha as string });
1466 } else {
1467 acc.push(entry);
1468 }
1469
1470 return acc;
1471 }, [] as TreeEntry[]);
1472
1473 for (const { from, to, sha } of toMove) {
1474 if (!hasSubfolders) {
1475 // New behavior (subfolders: false): Only move the specific file
1476 // Delete the file at the old path
1477 tree.push({
1478 path: trimStart(from, '/'),
1479 mode: '100644',
1480 type: 'blob',
1481 sha: null,
1482 });
1483 // Create the file at the new path
1484 tree.push({
1485 path: trimStart(to, '/'),
1486 mode: '100644',
1487 type: 'blob',
1488 sha,
1489 });
1490 } else {
1491 // Legacy behavior (subfolders: true, default): Move all files in the directory
1492 // This is for collections where all files in a folder represent a single entry
1493 const sourceDir = dirname(from);
1494 const destDir = dirname(to);
1495 const files = await this.listFiles(sourceDir, { branch, depth: 100 });
1496 for (const file of files) {
1497 // delete current path
1498 tree.push({
1499 path: file.path,
1500 mode: '100644',
1501 type: 'blob',
1502 sha: null,
1503 });
1504 // create in new path
1505 tree.push({
1506 path: file.path.replace(sourceDir, destDir),

Callers 8

storeMetadataMethod · 0.95
deleteMetadataMethod · 0.95
persistFilesMethod · 0.95
deleteFilesMethod · 0.95
editorialWorkflowGitMethod · 0.95
rebaseSingleCommitMethod · 0.95
forceMergePRMethod · 0.95
API.spec.jsFile · 0.80

Calls 3

listFilesMethod · 0.95
createTreeMethod · 0.95
replaceMethod · 0.80

Tested by

no test coverage detected