repo has no method 'branch' #35

Closed
cnzoupeng opened this Issue Dec 19, 2011 · 6 comments

Projects

None yet

6 participants

@cnzoupeng

var git = require( 'nodegit' );

var repoDir = "/work/gitroot/cpptestprj/.git";

git.repo(repoDir, function( err, repo )
{
if( err ) { throw err; }

  repo.branch( 'master', function( err, branch ) 
  {
    if( err ) { throw err; 
  }

branch.tree().walk().on('entry', function( idx, entry ) 
{
  console.log( entry.name, entry.attributes );
});

});
});

//----------------------------

zoupeng@ubuntu:/work/www$ node gittest.js

/work/gitroot/sourcecode/webide/gittest.js:10
repo.branch( 'master', function( err, branch )
^
TypeError: Object # has no method 'branch'
at /work/gitroot/sourcecode/webide/gittest.js:10:9

need for help!

@cnzoupeng

and i have try all the js example that no one could run..

root@ubuntu:/work/dev/nodegit/example# node raw-repo.js
{}
{}

/work/dev/nodegit/example/raw-repo.js:13
repo.lookupRef( master, 'refs/heads/master', function( err, ref ) {
^
TypeError: Object # has no method 'lookupRef'
at /work/dev/nodegit/example/raw-repo.js:13:10

//--------------------------------------------------------------------------------------
root@ubuntu:/work/dev/nodegit/example# node raw-blob.js

/work/dev/nodegit/example/raw-blob.js:16
tree.entryByIndex( entry, 1 );
^
Error: Callback is required and must be a Function.
at /work/dev/nodegit/example/raw-blob.js:16:12

//-----------------------------------------------------------------------

root@ubuntu:/work/dev/nodegit/example# node raw-blob.js

/work/dev/nodegit/example/raw-blob.js:16
tree.entryByIndex( entry, 1 );
^
Error: Callback is required and must be a Function.
at /work/dev/nodegit/example/raw-blob.js:16:12

@sibartlett

'm having this issue too.

@dhm116
dhm116 commented Jan 5, 2012

+1

Same issue

@dhm116
dhm116 commented Jan 5, 2012

Seems like part of the problem is if you print out what is supposed to be the repository instance to the console, you get this:

https://gist.github.com/1565276

@switz
switz commented Jan 9, 2012

+1 me too

@aaberg
aaberg commented Mar 3, 2012

I also had this issue. I have examined the problem, and found out that it is introduced in commit #918f8f58b99533b17326b9aafdb7cb19adb201c5.

In repo.js on line 14, this line of code is what causes the callback:
git.util().asyncComplete.call(this, arguments, async);

the "this" argument, is what we get as the repo parameter in the callback. The problem is, that "this" refers to the global scope, or something, and not to the repo object.

The example works as expected, if you in repo.js replace "this" in the parameter list, with "self" on line 14.

If you don't want to change the code, the repo() method also returns the repo object, so you can get it from there. I have changed the example code posted by cnzoupeng to work.

var git = require( 'nodegit' );

var repoDir = "/work/gitroot/cpptestprj/.git";

var repo = git.repo(repoDir, function( err ) {
    if( err ) { throw err; }
    repo.branch( 'master', function( err, branch ) {
        if( err ) {
            throw err;
        }

        branch.tree().walk().on('entry', function( idx, entry ) {
          console.log( entry.name, entry.attributes );
        });
    });
});
@tbranyen tbranyen pushed a commit that closed this issue May 12, 2012
@cholin cholin fixes #35: repo has no method 'branch'
the example snippet (from readme.md) is not working anymore. It complains
about a missing method 'branch'. According to aaberg this is due a wrong
argument for git.util().asyncComplete(). In repo.js:14 the callback gets called
with this instead of self.
4f34022
@tbranyen tbranyen closed this in 4f34022 May 12, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment