@@ -531,29 +531,24 @@ class Repository extends Requestable {
531531 * @return {Promise } - the promise for the http request
532532 */
533533 move ( branch , oldPath , newPath , cb ) {
534+ let oldSha ;
534535 return this . getRef ( `heads/${ branch } ` )
535- . then ( ( response ) => {
536- return this . getTree ( `${ response . data . object . sha } ?recursive=true` )
537- . then ( ( response ) => {
538- let _resp = response ;
539- response . data . tree . forEach ( ( ref ) => {
540- if ( ref . path === oldPath ) {
541- ref . path = newPath ;
542- }
543- if ( ref . type === 'tree' ) {
544- delete ref . sha ;
545- }
546- } ) ;
547- return this . createTree ( response . data . tree ) . then (
548- ( response ) => {
549- return this . commit ( _resp . data . sha , response . data . sha , `Renamed '${ oldPath } ' to '${ newPath } '` )
550- . then ( ( response ) => {
551- return this . updateHead ( `heads/${ branch } ` , response . data . sha , true , cb ) ;
552- } ) ;
553- }
554- ) ;
555- } ) ;
556- } ) ;
536+ . then ( ( { data : { object} } ) => this . getTree ( `${ object . sha } ?recursive=true` ) )
537+ . then ( ( { data : { tree, sha} } ) => {
538+ oldSha = sha ;
539+ let newTree = tree . map ( ( ref ) => {
540+ if ( ref . path === oldPath ) {
541+ ref . path = newPath ;
542+ }
543+ if ( ref . type === 'tree' ) {
544+ delete ref . sha ;
545+ }
546+ return ref ;
547+ } ) ;
548+ return this . createTree ( newTree ) ;
549+ } )
550+ . then ( ( { data : tree } ) => this . commit ( oldSha , tree . sha , `Renamed '${ oldPath } ' to '${ newPath } '` ) )
551+ . then ( ( { data : commit } ) => this . updateHead ( `heads/${ branch } ` , commit . sha , true , cb ) ) ;
557552 }
558553
559554 /**
0 commit comments