Skip to content

Instantly share code, notes, and snippets.

@gnarf
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnarf/b7b6bdc5498322271dd7 to your computer and use it in GitHub Desktop.
Save gnarf/b7b6bdc5498322271dd7 to your computer and use it in GitHub Desktop.
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