* 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)
| 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 |
no test coverage detected