@@ -92,22 +92,6 @@ Repository.prototype.getBranchCommit = function(name, callback) {
9292 } , callback ) ;
9393} ;
9494
95- /**
96- * Lists out the remotes in the given repository.
97- *
98- * @param {Function } Optional callback
99- * @return {Object } Promise object.
100- */
101- Repository . prototype . getRemotes = function ( callback ) {
102- return Remote . list ( this ) . then ( function ( remotes ) {
103- if ( typeof callback === "function" ) {
104- callback ( null , remotes ) ;
105- }
106-
107- return remotes ;
108- } , callback ) ;
109- } ;
110-
11195/**
11296 * Lookup the reference with the given name.
11397 *
@@ -425,9 +409,10 @@ Repository.prototype.createCommitOnHead = function(
425409 committer ,
426410 message ,
427411 treeOid ,
428- [ parent ] ) ;
412+ [ parent ] ,
413+ callback ) ;
429414 } ) ;
430- } ) ;
415+ } , callback ) ;
431416} ;
432417
433418/**
@@ -455,4 +440,85 @@ Repository.prototype.treeBuilder = function() {
455440 return builder ;
456441} ;
457442
443+ /**
444+ * Gets the default signature for the default user and now timestamp
445+ * @return {Signature }
446+ */
447+ Repository . prototype . defaultSignature = function ( ) {
448+ return NodeGit . Signature . default ( this ) ;
449+ } ;
450+
451+ /**
452+ * Lists out the remotes in the given repository.
453+ *
454+ * @param {Function } Optional callback
455+ * @return {Object } Promise object.
456+ */
457+ Repository . prototype . getRemotes = function ( callback ) {
458+ return Remote . list ( this ) . then ( function ( remotes ) {
459+ if ( typeof callback === "function" ) {
460+ callback ( null , remotes ) ;
461+ }
462+
463+ return remotes ;
464+ } , callback ) ;
465+ } ;
466+
467+ /**
468+ * Gets a remote from the repo
469+ *
470+ * @param {String|Remote } remote
471+ * @param {Function } callback
472+ * @return {Remote } The remote object
473+ */
474+ Repository . prototype . getRemote = function ( remote , callback ) {
475+ if ( remote instanceof NodeGit . Remote ) {
476+ return Promise . resolve ( remote ) . then ( function ( remoteObj ) {
477+ if ( typeof callback === "function" ) {
478+ callback ( null , remoteObj ) ;
479+ }
480+
481+ return remoteObj ;
482+ } , callback ) ;
483+ }
484+
485+ return NodeGit . Remote . load ( this , remote ) . then ( function ( remoteObj ) {
486+ if ( typeof callback === "function" ) {
487+ callback ( null , remoteObj ) ;
488+ }
489+
490+ return remoteObj ;
491+ } , callback ) ;
492+ } ;
493+
494+ /**
495+ * Fetches from a remote
496+ *
497+ * @param {String|Remote } remote
498+ */
499+ Repository . prototype . fetch = function ( remote ) {
500+ var repo = this ;
501+
502+ return repo . getRemote ( remote ) . then ( function ( remote ) {
503+ return remote . fetch ( repo . defaultSignature ( ) ) ;
504+ } ) ;
505+ } ;
506+
507+ /**
508+ * Fetches from all remotes
509+ */
510+ Repository . prototype . fetchAll = function ( ) {
511+ var repo = this ;
512+
513+ return repo . getRemotes ( function ( remotes ) {
514+ var fetchPromises = [ ] ;
515+
516+ remotes . forEach ( function ( remote ) {
517+ fetchPromises . push ( repo . fetch ( remote ) ) ;
518+ } ) ;
519+
520+ return Promise . all ( fetchPromises ) ;
521+ } ) ;
522+ } ;
523+
458524module . exports = Repository ;
0 commit comments