| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -14,7 +14,9 @@ To run `nodegit` you need `Node.js` and to run unit tests you will need to have | |||
| 14 | 14 | ### Easy install (Recommended) ### | |
| 15 | 15 | This will install and configure everything you need to use `nodegit`. | |
| 16 | 16 | ||
| 17 | - $ sudo npm install nodegit | ||
| 17 | + ```` bash | ||
| 18 | + $ sudo npm install nodegit | ||
| 19 | + ```` | ||
| 18 | 20 | ||
| 19 | 21 | To update an existing installation, run | |
| 20 | 22 | ||
@@ -54,121 +56,125 @@ API Example Usage | |||
| 54 | 56 | ||
| 55 | 57 | #### Convenience API #### | |
| 56 | 58 | ||
| 57 | - var git = require( 'nodegit' ); | ||
| 58 | - | ||
| 59 | - // Read a repository | ||
| 60 | - git.repo( '.git', function( err, repo ) { | ||
| 61 | - // Success is always 0, failure is always an error string | ||
| 59 | + ```` javascript | ||
| 60 | + var git = require( 'nodegit' ); | ||
| 61 | + | ||
| 62 | + // Read a repository | ||
| 63 | + git.repo( '.git', function( err, repo ) { | ||
| 64 | + // Success is always 0, failure is always an error string | ||
| 65 | + if( err ) { throw err; } | ||
| 66 | + | ||
| 67 | + // Use the master branch | ||
| 68 | + repo.branch( 'master', function( err, branch ) { | ||
| 62 | 69 | if( err ) { throw err; } | |
| 63 | 70 | ||
| 64 | - // Use the master branch | ||
| 65 | - repo.branch( 'master', function( err, branch ) { | ||
| 66 | - if( err ) { throw err; } | ||
| 67 | - | ||
| 68 | - // Iterate over the revision history | ||
| 69 | - var history = branch.history(); | ||
| 70 | - | ||
| 71 | - // Commit event is emitted with index 0,n... and commit object | ||
| 72 | - history.on( 'commit', function( idx, commit ) { | ||
| 73 | - // Print out `git log` emulation | ||
| 74 | - console.log( 'commit ' + commit.sha ); | ||
| 75 | - console.log( commit.author.name + '<' + commit.author.email + '>' ); | ||
| 76 | - console.log( commit.time ); | ||
| 77 | - console.log( '\n' ); | ||
| 78 | - console.log( commit.message ); | ||
| 79 | - console.log( '\n' ); | ||
| 80 | - }); | ||
| 71 | + // Iterate over the revision history | ||
| 72 | + var history = branch.history(); | ||
| 73 | + | ||
| 74 | + // Commit event is emitted with index 0,n... and commit object | ||
| 75 | + history.on( 'commit', function( idx, commit ) { | ||
| 76 | + // Print out `git log` emulation | ||
| 77 | + console.log( 'commit ' + commit.sha ); | ||
| 78 | + console.log( commit.author.name + '<' + commit.author.email + '>' ); | ||
| 79 | + console.log( commit.time ); | ||
| 80 | + console.log( '\n' ); | ||
| 81 | + console.log( commit.message ); | ||
| 82 | + console.log( '\n' ); | ||
| 81 | 83 | }); | |
| 82 | 84 | }); | |
| 85 | + }); | ||
| 86 | + ```` | ||
| 83 | 87 | ||
| 84 | 88 | #### Raw API #### | |
| 85 | 89 | ||
| 86 | - var git = require( 'nodegit' ).raw; | ||
| 87 | - | ||
| 88 | - // Create instance of Repo constructor | ||
| 89 | - var repo = new git.Repo(); | ||
| 90 | + ```` javascript | ||
| 91 | + var git = require( 'nodegit' ).raw; | ||
| 92 | + | ||
| 93 | + // Create instance of Repo constructor | ||
| 94 | + var repo = new git.Repo(); | ||
| 90 | 95 | ||
| 91 | - // Read a repository | ||
| 92 | - repo.open( '.git', function( err ) { | ||
| 93 | - // Err is an integer, success is 0, use strError for string representation | ||
| 96 | + // Read a repository | ||
| 97 | + repo.open( '.git', function( err ) { | ||
| 98 | + // Err is an integer, success is 0, use strError for string representation | ||
| 99 | + if( err ) { | ||
| 100 | + var error = new git.Error(); | ||
| 101 | + throw error.strError( err ); | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + // Create instance of Ref constructor with this repository | ||
| 105 | + var ref = new git.Ref( repo ); | ||
| 106 | + | ||
| 107 | + // Find the master branch | ||
| 108 | + repo.lookupRef( ref, '/refs/heads/master', function( err ) { | ||
| 94 | 109 | if( err ) { | |
| 95 | - var error = new git.Error(); | ||
| 96 | - throw error.strError( err ); | ||
| 110 | + var error = new git.Error(); | ||
| 111 | + throw error.strError( err ); | ||
| 97 | 112 | } | |
| 98 | 113 | ||
| 99 | - // Create instance of Ref constructor with this repository | ||
| 100 | - var ref = new git.Ref( repo ); | ||
| 101 | - | ||
| 102 | - // Find the master branch | ||
| 103 | - repo.lookupRef( ref, '/refs/heads/master', function( err ) { | ||
| 114 | + // Create instance of Commit constructor with this repository | ||
| 115 | + var commit = new git.Commit( repo ), | ||
| 116 | + // Create instance of Oid constructor | ||
| 117 | + oid = new git.Oid(); | ||
| 118 | + | ||
| 119 | + // Set the oid constructor internal reference to this branch reference | ||
| 120 | + ref.oid( oid ); | ||
| 121 | + | ||
| 122 | + // Lookup the commit for this oid | ||
| 123 | + commit.lookup( oid, function() { | ||
| 104 | 124 | if( err ) { | |
| 105 | 125 | var error = new git.Error(); | |
| 106 | 126 | throw error.strError( err ); | |
| 107 | 127 | } | |
| 108 | 128 | ||
| 109 | - // Create instance of Commit constructor with this repository | ||
| 110 | - var commit = new git.Commit( repo ), | ||
| 111 | - // Create instance of Oid constructor | ||
| 112 | - oid = new git.Oid(); | ||
| 113 | - | ||
| 114 | - // Set the oid constructor internal reference to this branch reference | ||
| 115 | - ref.oid( oid ); | ||
| 129 | + // Create instance of RevWalk constructor with this repository | ||
| 130 | + var revwalk = new git.RevWalk( repo ); | ||
| 116 | 131 | ||
| 117 | - // Lookup the commit for this oid | ||
| 118 | - commit.lookup( oid, function() { | ||
| 119 | - if( err ) { | ||
| 120 | - var error = new git.Error(); | ||
| 121 | - throw error.strError( err ); | ||
| 122 | - } | ||
| 132 | + // Push the commit as the start to walk | ||
| 133 | + revwalk.push( commit ); | ||
| 123 | 134 | ||
| 124 | - // Create instance of RevWalk constructor with this repository | ||
| 125 | - var revwalk = new git.RevWalk( repo ); | ||
| 135 | + // Recursive walk | ||
| 136 | + function walk() { | ||
| 137 | + // Each revision walk iteration yields a commit | ||
| 138 | + var revisionCommit = new git.Commit( repo ); | ||
| 126 | 139 | ||
| 127 | - // Push the commit as the start to walk | ||
| 128 | - revwalk.push( commit ); | ||
| 140 | + revwalk.next( revisionCommit, function( err ) { | ||
| 141 | + // Finish recursion once no more revision commits are left | ||
| 142 | + if( err ) { return; } | ||
| 129 | 143 | ||
| 130 | - // Recursive walk | ||
| 131 | - function walk() { | ||
| 132 | - // Each revision walk iteration yields a commit | ||
| 133 | - var revisionCommit = new git.Commit( repo ); | ||
| 144 | + // Create instance of Oid for sha | ||
| 145 | + var oid = new git.Oid(); | ||
| 134 | 146 | ||
| 135 | - revwalk.next( revisionCommit, function( err ) { | ||
| 136 | - // Finish recursion once no more revision commits are left | ||
| 137 | - if( err ) { return; } | ||
| 147 | + // Set oid to the revision commit | ||
| 148 | + revisionCommit.id( oid ); | ||
| 138 | 149 | ||
| 139 | - // Create instance of Oid for sha | ||
| 140 | - var oid = new git.Oid(); | ||
| 150 | + // Create instance of Sig for author | ||
| 151 | + var author = new git.Sig(); | ||
| 141 | 152 | ||
| 142 | - // Set oid to the revision commit | ||
| 143 | - revisionCommit.id( oid ); | ||
| 153 | + // Set the author to the revision commit author | ||
| 154 | + revisionCommit.author( author ); | ||
| 144 | 155 | ||
| 145 | - // Create instance of Sig for author | ||
| 146 | - var author = new git.Sig(); | ||
| 156 | + // Convert timestamp to milliseconds and set new Date object | ||
| 157 | + var time = new Date( revisionCommit.time() * 1000 ); | ||
| 147 | 158 | ||
| 148 | - // Set the author to the revision commit author | ||
| 149 | - revisionCommit.author( author ); | ||
| 159 | + // Print out `git log` emulation | ||
| 160 | + console.log( oid.toString( 40 ) ); | ||
| 161 | + console.log( author.name() + '<' + author.email() + '>' ); | ||
| 162 | + console.log( time ); | ||
| 163 | + console.log( '\n' ); | ||
| 164 | + console.log( revisionCommit.message() ); | ||
| 165 | + console.log( '\n' ); | ||
| 150 | 166 | ||
| 151 | - // Convert timestamp to milliseconds and set new Date object | ||
| 152 | - var time = new Date( revisionCommit.time() * 1000 ); | ||
| 153 | - | ||
| 154 | - // Print out `git log` emulation | ||
| 155 | - console.log( oid.toString( 40 ) ); | ||
| 156 | - console.log( author.name() + '<' + author.email() + '>' ); | ||
| 157 | - console.log( time ); | ||
| 158 | - console.log( '\n' ); | ||
| 159 | - console.log( revisionCommit.message() ); | ||
| 160 | - console.log( '\n' ); | ||
| 161 | - | ||
| 162 | - // Recurse! | ||
| 163 | - walk(); | ||
| 164 | - }); | ||
| 165 | - } | ||
| 167 | + // Recurse! | ||
| 168 | + walk(); | ||
| 169 | + }); | ||
| 170 | + } | ||
| 166 | 171 | ||
| 167 | - // Initiate recursion | ||
| 168 | - walk(): | ||
| 169 | - }); | ||
| 172 | + // Initiate recursion | ||
| 173 | + walk(): | ||
| 170 | 174 | }); | |
| 171 | 175 | }); | |
| 176 | + }); | ||
| 177 | + ```` | ||
| 172 | 178 | ||
| 173 | 179 | Running tests | |
| 174 | 180 | ------------- | |
| Back | FazBrowse Home | New Git URL |
0 commit comments