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

Method createBranch

packages/decap-cms-backend-github/src/API.ts:1307–1331  ·  view source on GitHub ↗
(branchName: string, sha: string)

Source from the content-addressed store, hash-verified

1305 }
1306
1307 async createBranch(branchName: string, sha: string) {
1308 try {
1309 const result = await this.createRef('heads', branchName, sha);
1310 return result;
1311 } catch (e) {
1312 const message = String(e.message || '');
1313 if (message === 'Reference update failed') {
1314 await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
1315 } else if (
1316 message === 'Reference already exists' &&
1317 branchName.startsWith(`${CMS_BRANCH_PREFIX}/`)
1318 ) {
1319 try {
1320 // this can happen if the branch wasn't deleted when the PR was merged
1321 // we backup the existing branch just in case and patch it with the new sha
1322 await this.backupBranch(branchName);
1323 const result = await this.patchBranch(branchName, sha, { force: true });
1324 return result;
1325 } catch (e) {
1326 console.log(e);
1327 }
1328 }
1329 throw e;
1330 }
1331 }
1332
1333 assertCmsBranch(branchName: string) {
1334 return branchName.startsWith(`${CMS_BRANCH_PREFIX}/`);

Callers 4

migrateToVersion1Method · 0.95
editorialWorkflowGitMethod · 0.95
backupBranchMethod · 0.95

Calls 5

createRefMethod · 0.95
getBranchMethod · 0.95
backupBranchMethod · 0.95
patchBranchMethod · 0.95

Tested by

no test coverage detected