Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

repo has no method 'branch' #35

Closed
cnzoupeng opened this Issue · 6 comments

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

+1

Same issue

@dhm116

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

+1 me too

@aaberg

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 closed this issue from a commit
@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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.