1- /*global require: true, jQuery: false */
21var git = require ( 'nodegit2' ) ;
32
43var Repo = function ( path , callback ) {
54 // Public namespace
65 var self = { } ;
76
87 // Private internal use variables
9- var _commits = [ ] ;
8+ var _commits = [ ] ,
9+ _error = git . error ( ) ;
10+
11+ function error ( err ) {
12+ if ( err !== 0 ) {
13+ return _error . error . strError ( err ) ;
14+ }
15+
16+ return 0 ;
17+ }
18+
1019
1120 // Internal reference to a Git repository
1221 self . repo = new git . git2 . Repo ( ) ;
@@ -32,6 +41,8 @@ var Repo = function( path, callback ) {
3241
3342 commit . lookup ( self . repo , oid , function ( ) {
3443 var args = Array . prototype . slice . call ( arguments ) ;
44+ args [ 0 ] = error ( args [ 0 ] ) ;
45+
3546 callback && callback . apply ( commit , ( args . push ( commit ) , args ) ) ;
3647 } ) ;
3748 } ;
@@ -40,13 +51,17 @@ var Repo = function( path, callback ) {
4051 var ref = new git . git2 . Ref ( ) ;
4152 self . repo . lookupRef ( ref , name , function ( ) {
4253 var args = Array . prototype . slice . call ( arguments ) ;
54+ args [ 0 ] = error ( args [ 0 ] ) ;
55+
4356 callback && callback . apply ( ref , ( args . push ( git . ref ( ref ) ) , args ) ) ;
4457 } ) ;
4558 } ;
4659
4760 self . init = function ( path , is_bare , callback ) {
4861 self . repo . init ( path , is_bare , function ( ) {
4962 var args = Array . prototype . slice . call ( arguments ) ;
63+ args [ 0 ] = error ( args [ 0 ] ) ;
64+
5065 callback && callback . apply ( self , ( args . push ( self ) , args ) ) ;
5166 } ) ;
5267
@@ -62,6 +77,8 @@ var Repo = function( path, callback ) {
6277 if ( path && callback ) {
6378 self . repo . open ( path , function ( ) {
6479 var args = Array . prototype . slice . call ( arguments ) ;
80+ args [ 0 ] = error ( args [ 0 ] ) ;
81+
6582 callback && callback . apply ( self , ( args . push ( self ) , args ) ) ;
6683 } ) ;
6784 }
0 commit comments