MCPcopy Index your code
hub / github.com/github-tools/github / move

Method move

lib/Repository.js:733–752  ·  view source on GitHub ↗

* Change all references in a repo from oldPath to new_path * @param {string} branch - the branch to carry out the reference change, or the default branch if not specified * @param {string} oldPath - original path * @param {string} newPath - new reference path * @param {Requestable.ca

(branch, oldPath, newPath, cb)

Source from the content-addressed store, hash-verified

731 * @return {Promise} - the promise for the http request
732 */
733 move(branch, oldPath, newPath, cb) {
734 let oldSha;
735 return this.getRef(`heads/${branch}`)
736 .then(({data: {object}}) => this.getTree(`${object.sha}?recursive=true`))
737 .then(({data: {tree, sha}}) => {
738 oldSha = sha;
739 let newTree = tree.map((ref) => {
740 if (ref.path === oldPath) {
741 ref.path = newPath;
742 }
743 if (ref.type === 'tree') {
744 delete ref.sha;
745 }
746 return ref;
747 });
748 return this.createTree(newTree);
749 })
750 .then(({data: tree}) => this.commit(oldSha, tree.sha, `Renamed '${oldPath}' to '${newPath}'`))
751 .then(({data: commit}) => this.updateHead(`heads/${branch}`, commit.sha, true, cb));
752 }
753
754 /**
755 * Write a file to the repository

Callers 1

repository.spec.jsFile · 0.80

Calls 5

getRefMethod · 0.95
getTreeMethod · 0.95
createTreeMethod · 0.95
commitMethod · 0.95
updateHeadMethod · 0.95

Tested by

no test coverage detected