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

Method createBranch

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

Source from the content-addressed store, hash-verified

1292 }
1293
1294 async createBranch(branchName: string, sha: string) {
1295 try {
1296 const result = await this.createRef('heads', branchName, sha);
1297 return result;
1298 } catch (e) {
1299 const message = String(e.message || '');
1300 if (message === 'Reference update failed') {
1301 await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
1302 } else if (
1303 message === 'Reference already exists' &&
1304 branchName.startsWith(`${CMS_BRANCH_PREFIX}/`)
1305 ) {
1306 try {
1307 // this can happen if the branch wasn't deleted when the PR was merged
1308 // we backup the existing branch just in case and patch it with the new sha
1309 await this.backupBranch(branchName);
1310 const result = await this.patchBranch(branchName, sha, { force: true });
1311 return result;
1312 } catch (e) {
1313 console.log(e);
1314 }
1315 }
1316 throw e;
1317 }
1318 }
1319
1320 assertCmsBranch(branchName: string) {
1321 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