Skip to content

Instantly share code, notes, and snippets.

@gnarf gnarf/err.js
Last active Aug 29, 2015

Embed
What would you like to do?
var clone = require("./").Clone.clone;
function errorLog(err) {
console.error(err);
}
// Look up this known commit.
function getCommit(repo) {
// Use a known commit sha from this repository.
return repo.getCommit("59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5");
}
// Look up a specific file within that commit.
function getReadme(commit) {
return commit.getEntry("README.md");
}
// Get the blob contents from the file.
function getBlob(entry) {
// Patch the blob to contain a reference to the entry.
return entry.getBlob()
.then(function attachEntry(blob) {
blob.entry = entry;
return blob;
});
}
// Display information about the blob.
function showBlob(blob) {
// Show the name, sha, and filesize in byes.
console.log(blob.entry.name() + blob.entry.sha() + blob.size() + "b");
// Show a spacer.
console.log(Array(72).join("=") + "\n\n");
// Show the entire file.
console.log(String(blob));
}
// Clone a given repository into a specific folder.
clone("https://github.com/nodegit/nodegit", "tmp", null)
.then(getCommit)
.then(getReadme)
.then(getBlob)
.then(showBlob)
.catch(errorLog);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.