Skip to content

Commit 677f4d7

Browse files
committed
Merge pull request #248 from naman34/patch-1
Update Readme, to improve example code
2 parents f616833 + f417c18 commit 677f4d7

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

README.md

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,32 @@ npm install nodegit --msvs_version=2013
100100
var clone = require("nodegit").Repository.clone;
101101

102102
// Clone a given repository into a specific folder.
103-
clone("https://github.com/nodegit/nodegit", "tmp", null).then(function(repo) {
104-
// Use a known commit sha from this repository.
105-
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
106-
107-
// Look up this known commit.
108-
repo.getCommit(sha).then(function(commit) {
103+
clone("https://github.com/nodegit/nodegit", "tmp", null)
104+
.then(function(repo) {
105+
// Use a known commit sha from this repository.
106+
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
107+
108+
// Look up this known commit.
109+
return repo.getCommit(sha);
110+
})
111+
.then(function(commit) {
109112
// Look up a specific file within that commit.
110-
commit.getEntry("README.md").then(function(entry) {
111-
// Get the blob contents from the file.
112-
entry.getBlob().then(function(blob) {
113-
// Show the name, sha, and filesize in byes.
114-
console.log(entry.name() + entry.sha() + blob.size() + "b");
115-
116-
// Show a spacer.
117-
console.log(Array(72).join("=") + "\n\n");
118-
119-
// Show the entire file.
120-
console.log(String(blob));
121-
});
122-
});
113+
return commit.getEntry("README.md");
114+
})
115+
.then(function(entry) {
116+
// Get the blob contents from the file.
117+
return entry.getBlob();
118+
})
119+
.then(function(blob) {
120+
// Show the name, sha, and filesize in byes.
121+
console.log(entry.name() + entry.sha() + blob.size() + "b");
122+
123+
// Show a spacer.
124+
console.log(Array(72).join("=") + "\n\n");
125+
126+
// Show the entire file.
127+
console.log(String(blob));
123128
});
124-
});
125129
```
126130

127131
### Emulating git log: ###
@@ -130,9 +134,12 @@ clone("https://github.com/nodegit/nodegit", "tmp", null).then(function(repo) {
130134
var open = require("nodegit").Repository.open;
131135

132136
// Open the repository directory.
133-
open("tmp").then(function(repo) {
134-
// Open the master branch.
135-
repo.getMaster().then(function(branch) {
137+
open("tmp")
138+
.then(function(repo) {
139+
// Open the master branch.
140+
return repo.getMaster();
141+
})
142+
.then(function(branch) {
136143
// Create a new history event emitter.
137144
var history = branch.history();
138145

@@ -165,7 +172,6 @@ open("tmp").then(function(repo) {
165172
// Start emitting events.
166173
history.start();
167174
});
168-
});
169175
```
170176

171177
## Unit tests. ##

0 commit comments

Comments
 (0)