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

Method createBranch

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

Source from the content-addressed store, hash-verified

1266 }
1267
1268 async createBranch(branchName: string, sha: string) {
1269 try {
1270 const result = await this.createRef('heads', branchName, sha);
1271 return result;
1272 } catch (e) {
1273 const message = String(e.message || '');
1274 if (message === 'Reference update failed') {
1275 await throwOnConflictingBranches(branchName, name => this.getBranch(name), API_NAME);
1276 } else if (
1277 message === 'Reference already exists' &&
1278 branchName.startsWith(`${CMS_BRANCH_PREFIX}/`)
1279 ) {
1280 try {
1281 // this can happen if the branch wasn't deleted when the PR was merged
1282 // we backup the existing branch just in case and patch it with the new sha
1283 await this.backupBranch(branchName);
1284 const result = await this.patchBranch(branchName, sha, { force: true });
1285 return result;
1286 } catch (e) {
1287 console.log(e);
1288 }
1289 }
1290 throw e;
1291 }
1292 }
1293
1294 assertCmsBranch(branchName: string) {
1295 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