Skip to content

Instantly share code, notes, and snippets.

@tylergaw
Created November 22, 2014 19:55
Show Gist options
  • Select an option

  • Save tylergaw/90a31a15d36730c7d8ce to your computer and use it in GitHub Desktop.

Select an option

Save tylergaw/90a31a15d36730c7d8ce to your computer and use it in GitHub Desktop.
Using nodegit

I was trying to use nodegit and was running into trouble. I followed the install instructions on the README and then tried the examples there, but was getting errors for anything beyond requiring the package.

For now it seems you can't use the version of nodegit that is published to npm.

npm install nodegit

That will install version 0.1.4. Which seems to not work. Here's an example of what would happen.

// test.js
var open = require('nodegit').Repository.open;
node test.js

which would give the following:

/Users/tyler/Desktop/wut/test.js:1
odule, __filename, __dirname) { var open = require('nodegit').Repository.open;
                                                                        ^
TypeError: Cannot read property 'open' of undefined
    at Object.<anonymous> (/Users/tyler/Desktop/wut/test.js:1:103)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:906:3

What you need is nodegit version 0.2.0. To get that, you can install the package from the master branch on Github. You'll need a package.json. Here's what I'm doing.

// package.json
...
"devDependencies": {
    "nodegit": "git+ssh://[email protected]:nodegit/nodegit#master"
  }
...

Once that's in place, run npm install again. Wait quite a while and then the nodegit example above–and the others–should work.

@tylergaw
Copy link
Author

Oh cool, didn't know you could install it like that in package.json. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment