|
1 | | -var git = require('../'), |
| 1 | +var nodegit = require('../'), |
2 | 2 | path = require('path'); |
3 | 3 |
|
4 | 4 | // This example opens a certain file, `README.md`, at a particular commit, |
5 | 5 | // and prints the first 10 lines as well as some metadata. |
6 | | - |
7 | | -git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) { |
8 | | - if (error) throw error; |
9 | | - |
10 | | - repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) { |
11 | | - if (error) throw error; |
12 | | - |
13 | | - commit.getEntry('README.md', function(error, entry) { |
14 | | - if (error) throw error; |
15 | | - |
16 | | - entry.getBlob(function(error, blob) { |
17 | | - if (error) throw error; |
18 | | - |
19 | | - console.log(entry.name(), entry.sha(), blob.size() + 'b'); |
20 | | - console.log('========================================================\n\n'); |
21 | | - var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n'); |
22 | | - console.log(firstTenLines); |
23 | | - console.log('...'); |
24 | | - }); |
25 | | - }); |
26 | | - }); |
27 | | -}); |
| 6 | +var _entry; |
| 7 | +nodegit.Repository.open(path.resolve(__dirname, '../.git')).then(function(repo) { |
| 8 | + return repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5'); |
| 9 | +}).then(function(commit) { |
| 10 | + return commit.getEntry('README.md'); |
| 11 | +}).then(function(entry) { |
| 12 | + _entry = entry; |
| 13 | + return _entry.getBlob(); |
| 14 | +}).then(function(blob) { |
| 15 | + console.log(_entry.filename(), _entry.sha(), blob.rawsize() + 'b'); |
| 16 | + console.log('========================================================\n\n'); |
| 17 | + var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n'); |
| 18 | + console.log(firstTenLines); |
| 19 | + console.log('...'); |
| 20 | +}).done(); |
0 commit comments