|
| 1 | +Version **0.0.79** Node.js libgit2 asynchronous native bindings |
| 2 | + |
| 3 | +A collection of non-blocking Node.js libgit2 bindings, raw api, convenience api, unit tests, documentation and accomodations to make contributing easier. |
| 4 | + |
| 5 | +#### require |
| 6 | + |
| 7 | +* [Node.js >=0.8](http://nodejs.org/) |
| 8 | +* [npm](http://npmjs.org/) *(if you want the premiere install experience)* |
| 9 | +* [Git](http://git-scm.com/) *(if you want to unit test )* |
| 10 | + |
| 11 | +#### install |
| 12 | + |
| 13 | + npm install nodegit |
| 14 | + |
| 15 | + |
| 16 | +#### use |
| 17 | + |
| 18 | +*emulate `git log`* |
| 19 | + |
| 20 | + // Load in the module. |
| 21 | + var git = require('nodegit'), |
| 22 | + async = require('async'); |
| 23 | + |
| 24 | + // Open the repository in the current directory. |
| 25 | + git.repo('.git', function(error, repository) { |
| 26 | + if (error) throw error; |
| 27 | + |
| 28 | + // Use the master branch. |
| 29 | + repository.branch('master', function(error, branch) { |
| 30 | + if (error) throw error; |
| 31 | + |
| 32 | + // Iterate over the revision history. |
| 33 | + branch.history().on('commit', function(error, commit) { |
| 34 | + |
| 35 | + // Print out `git log` emulation. |
| 36 | + async.series([ |
| 37 | + function(callback) { |
| 38 | + commit.sha(callback); |
| 39 | + }, |
| 40 | + function(callback) { |
| 41 | + commit.time(callback); |
| 42 | + }, |
| 43 | + function(callback) { |
| 44 | + commit.author(function(error, author) { |
| 45 | + author.name(callback); |
| 46 | + }); |
| 47 | + }, |
| 48 | + function(callback) { |
| 49 | + commit.author(function(error, author) { |
| 50 | + author.email(callback); |
| 51 | + }); |
| 52 | + }, |
| 53 | + function(callback) { |
| 54 | + commit.message(callback); |
| 55 | + } |
| 56 | + ], function printCommit(error, results) { |
| 57 | + if (error) throw error; |
| 58 | + console.log('SHA ' + results[0]); |
| 59 | + console.log(new Date(results[1] * 1000)); |
| 60 | + console.log(results[2] + ' <' + results[3] + '>'); |
| 61 | + console.log(results[4]); |
| 62 | + }); |
| 63 | + }); |
| 64 | + }); |
| 65 | + }); |
| 66 | + |
| 67 | +*view commit tree and blob information* |
| 68 | + |
| 69 | + // Load in the module. |
| 70 | + var git = require('nodegit'); |
| 71 | + |
| 72 | + // Open the repository in the current directory. |
| 73 | + git.repo('.git', function(error, repository) { |
| 74 | + if (error) throw error; |
| 75 | + |
| 76 | + // Use the master branch. |
| 77 | + repository.branch('master', function(error, branch) { |
| 78 | + if (error) throw error; |
| 79 | + |
| 80 | + // Iterate over the revision history. |
| 81 | + branch.tree(function(error, tree) { |
| 82 | + console.log(tree); |
| 83 | + if (error) throw error; |
| 84 | + tree.walk().on('entry', function(error, entry) { |
| 85 | + entry.name(function(error, name) { |
| 86 | + console.log(name); |
| 87 | + }); |
| 88 | + }); |
| 89 | + }); |
| 90 | + }); |
| 91 | + }); |
| 92 | + |
| 93 | +#### download |
| 94 | + |
| 95 | +You can download this project in either [zip](http://github.com/tbranyen/nodegit/zipball/master) or [tar](http://github.com/tbranyen/nodegit/tarball/master) formats. |
| 96 | + |
| 97 | +You can also clone and build the project with [Git](http://git-scm.com) by running: |
| 98 | + |
| 99 | + $ git clone git://github.com/tbranyen/nodegit |
| 100 | + |
| 101 | + $ cd nodegit |
| 102 | + |
| 103 | + $ node install |
0 commit comments