@@ -286,7 +286,7 @@ class Repository extends Requestable {
286
286
* Add a commit to the repository
287
287
* @see https://developer.github.com/v3/git/commits/#create-a-commit
288
288
* @param {string } parent - the SHA of the parent commit
289
- * @param {Object } tree - the tree that describes this commit
289
+ * @param {string } tree - the SHA of the tree for this commit
290
290
* @param {string } message - the commit message
291
291
* @param {Function } cb - will receive the commit that is created
292
292
* @return {Promise } - the promise for the http request
@@ -300,7 +300,7 @@ class Repository extends Requestable {
300
300
301
301
return this . _request ( 'POST' , `/repos/${ this . __fullname } /git/commits` , data , cb )
302
302
. then ( ( response ) => {
303
- this . __currentTree . sha = response . sha ; // Update latest commit
303
+ this . __currentTree . sha = response . data . sha ; // Update latest commit
304
304
return response ;
305
305
} ) ;
306
306
}
@@ -310,11 +310,12 @@ class Repository extends Requestable {
310
310
* @see https://developer.github.com/v3/git/refs/#update-a-reference
311
311
* @param {string } ref - the ref to update
312
312
* @param {string } commitSHA - the SHA to point the reference to
313
+ * @param {boolean } force - indicates whether to force or ensure a fast-forward update
313
314
* @param {Function } cb - will receive the updated ref back
314
315
* @return {Promise } - the promise for the http request
315
316
*/
316
- updateHead ( ref , commitSHA , cb ) {
317
- return this . _request ( 'PATCH' , `/repos/${ this . __fullname } /git/refs/${ ref } ` , { sha : commitSHA } , cb ) ;
317
+ updateHead ( ref , commitSHA , force , cb ) {
318
+ return this . _request ( 'PATCH' , `/repos/${ this . __fullname } /git/refs/${ ref } ` , { sha : commitSHA , force : force } , cb ) ;
318
319
}
319
320
320
321
/**
@@ -500,41 +501,38 @@ class Repository extends Requestable {
500
501
} ) ;
501
502
}
502
503
503
- // Move a file to a new location
504
- // -------
505
- move ( branch , path , newPath , cb ) {
506
- return this . _updateTree ( branch , function ( err , latestCommit ) {
507
- this . getTree ( latestCommit + '?recursive=true' , function ( err , tree ) {
508
- // Update Tree
509
- tree . forEach ( function ( ref ) {
510
- if ( ref . path === path ) {
511
- ref . path = newPath ;
512
- }
513
-
514
- if ( ref . type === 'tree' ) {
515
- delete ref . sha ;
516
- }
517
- } ) ;
518
-
519
- this . createTree ( tree , function ( err , rootTree ) {
520
- this . commit ( latestCommit , rootTree , 'Deleted ' + path , function ( err , commit ) {
521
- this . updateHead ( branch , commit , cb ) ;
504
+ /**
505
+ * Change all references in a repo from old_path to new_path
506
+ * @param {string } branch - the branch to carry out the reference change, or the default branch if not specified
507
+ * @param {string } old_path - original path
508
+ * @param {string } new_path - new reference path
509
+ * @param {Function } cb - will receive the commit in which the move occurred
510
+ * @return {Promise } - the promise for the http request
511
+ */
512
+ move ( branch , old_path , new_path , cb ) {
513
+ return this . getRef ( `heads/${ branch } ` )
514
+ . then ( ( response ) => {
515
+ return this . getTree ( `${ response . data . object . sha } ?recursive=true` )
516
+ . then ( ( response ) => {
517
+ var _resp = response ;
518
+ response . data . tree . forEach ( ( ref ) => {
519
+ if ( ref . path === old_path ) {
520
+ ref . path = new_path ;
521
+ }
522
+ if ( ref . type === 'tree' ) {
523
+ delete ref . sha ;
524
+ }
525
+ } ) ;
526
+ return this . createTree ( response . data . tree ) . then (
527
+ ( response ) => {
528
+ return this . commit ( _resp . data . sha , response . data . sha , `Renamed '${ old_path } ' to '${ new_path } '` )
529
+ . then ( ( response ) => {
530
+ return this . updateHead ( `heads/${ branch } ` , response . data . sha , true , cb ) ;
531
+ } ) ;
532
+ }
533
+ ) ;
522
534
} ) ;
523
- } ) ;
524
535
} ) ;
525
- } ) ;
526
- }
527
-
528
- _updateTree ( branch , cb ) {
529
- if ( branch === this . __currentTree . branch && this . __currentTree . sha ) {
530
- return cb ( null , this . __currentTree . sha ) ;
531
- }
532
-
533
- return this . getRef ( `heads/${ branch } ` , function ( err , sha ) {
534
- this . __currentTree . branch = branch ;
535
- this . __currentTree . sha = sha ;
536
- cb ( err , sha ) ;
537
- } ) ;
538
536
}
539
537
540
538
/**
0 commit comments