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

Method rebaseSingleCommit

packages/decap-cms-backend-github/src/API.ts:1121–1148  ·  view source on GitHub ↗
(baseCommit: GitHubCompareCommit, commit: GitHubCompareCommit)

Source from the content-addressed store, hash-verified

1119 }
1120
1121 async rebaseSingleCommit(baseCommit: GitHubCompareCommit, commit: GitHubCompareCommit) {
1122 // first get the diff between the commits
1123 const result = await this.getDifferences(commit.parents[0].sha, commit.sha);
1124 const files = getTreeFiles(result.files as GitHubCompareFiles);
1125
1126 // only update the tree if changes were detected
1127 if (files.length > 0) {
1128 // create a tree with baseCommit as the base with the diff applied
1129 const tree = await this.updateTree(baseCommit.sha, files);
1130 const { message, author, committer } = commit.commit;
1131
1132 // create a new commit from the updated tree
1133 const newCommit = await this.createCommit(
1134 message,
1135 tree.sha,
1136 [baseCommit.sha],
1137 author
1138 ? { name: author.name || '', email: author.email || '', date: author.date }
1139 : undefined,
1140 committer
1141 ? { name: committer.name || '', email: committer.email || '', date: committer.date }
1142 : undefined,
1143 );
1144 return newCommit as unknown as GitHubCompareCommit;
1145 } else {
1146 return commit;
1147 }
1148 }
1149
1150 /**
1151 * Rebase an array of commits one-by-one, starting from a given base SHA

Callers 2

rebaseCommitsMethod · 0.95
API.spec.jsFile · 0.80

Calls 4

getDifferencesMethod · 0.95
updateTreeMethod · 0.95
createCommitMethod · 0.95
getTreeFilesFunction · 0.85

Tested by

no test coverage detected