Skip to content

Commit 4d7d4ff

Browse files
committed
Re-arrange the README examples so they can be run in order.
1 parent 638d592 commit 4d7d4ff

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

README.md

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,52 @@ sudo apt-get install cmake libzip-dev build-essential
6262

6363
## API examples. ##
6464

65+
### Cloning a repository and reading a file: ###
66+
67+
``` javascript
68+
var clone = require("nodegit").Repo.clone;
69+
70+
// Clone a given repository into a specific folder.
71+
clone("https://github.com/nodegit/nodegit", "tmp", null, function(err, repo) {
72+
if (err) {
73+
throw err;
74+
}
75+
76+
// Use a known commit sha from this repository.
77+
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
78+
79+
// Look up this known commit.
80+
repo.getCommit(sha, function(err, commit) {
81+
if (err) {
82+
throw error;
83+
}
84+
85+
// Look up a specific file within that commit.
86+
commit.getEntry("README.md", function(err, entry) {
87+
if (err) {
88+
throw error;
89+
}
90+
91+
// Get the blob contents from the file.
92+
entry.getBlob(function(err, blob) {
93+
if (err) {
94+
throw err;
95+
}
96+
97+
// Show the name, sha, and filesize in byes.
98+
console.log(entry.name() + entry.sha() + blob.size() + "b");
99+
100+
// Show a spacer.
101+
console.log(Array(72).join("=") + "\n\n");
102+
103+
// Show the entire file.
104+
console.log(String(blob));
105+
});
106+
});
107+
});
108+
});
109+
```
110+
65111
### Emulating git log: ###
66112

67113
``` javascript
@@ -114,52 +160,6 @@ open("tmp", function(err, repo) {
114160
});
115161
```
116162

117-
### Cloning a repository and reading a file: ###
118-
119-
``` javascript
120-
var clone = require("nodegit").Repo.clone;
121-
122-
// Clone a given repository into a specific folder.
123-
clone("https://github.com/nodegit/nodegit", "tmp", null, function(err, repo) {
124-
if (err) {
125-
throw err;
126-
}
127-
128-
// Use a known commit sha from this repository.
129-
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
130-
131-
// Look up this known commit.
132-
repo.getCommit(sha, function(err, commit) {
133-
if (err) {
134-
throw error;
135-
}
136-
137-
// Look up a specific file within that commit.
138-
commit.getEntry("README.md", function(err, entry) {
139-
if (err) {
140-
throw error;
141-
}
142-
143-
// Get the blob contents from the file.
144-
entry.getBlob(function(err, blob) {
145-
if (err) {
146-
throw err;
147-
}
148-
149-
// Show the name, sha, and filesize in byes.
150-
console.log(entry.name() + entry.sha() + blob.size() + "b");
151-
152-
// Show a spacer.
153-
console.log(Array(72).join("=") + "\n\n");
154-
155-
// Show the entire file.
156-
console.log(String(blob));
157-
});
158-
});
159-
});
160-
});
161-
```
162-
163163
## Unit tests. ##
164164

165165
You will need to build locally before running the tests. See above.

0 commit comments

Comments
 (0)