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

Method updateTree

packages/decap-cms-backend-github/src/API.ts:1462–1530  ·  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

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