geit
v0.0.7
Published
Simply get source code trees from a git repository via Smart HTTP
Downloads
174
Readme
geit 🐐
Simply get source code trees from a git repository via Smart HTTP.
- No git command-line tool required
- Caching git objects with levelup (Using memdown as a backend by default)
- Supporting HTTP Authentication, proxies, etc. with request
Installation
$ npm install --save geit
Examples
Get 'README.md' on HEAD
const geit = require('geit');
const repo = geit('https://github.com/h2so5/geit.git');
repo.tree('HEAD', function(tree, err) {
const blobID = tree['README.md'].object;
repo.blob(blobID, function(data, err) {
console.log(data.toString());
});
});
Get 'README.md' on HEAD (Promise)
const geit = require('geit');
const repo = geit('https://github.com/h2so5/geit.git');
repo.tree('HEAD').then((tree) => {
const blobID = tree['README.md'].object;
return repo.blob(blobID);
}).then((data) => {
console.log(data.toString());
});
Extract all files in a tree
(Same as git clone --depth 1
without .git directory)
const geit = require('geit');
const path = require('path');
const fs = require('fs');
const repo = geit('https://github.com/h2so5/geit.git');
repo.tree('HEAD', function(tree, err) {
extractTree(repo, tree, './geit');
});
function extractTree(repo, tree, dir) {
fs.mkdirSync(dir);
for (let name in tree) {
const item = tree[name];
const pathname = path.join(dir, name);
switch (item.mode) {
case '040000': // directory
extractTree(repo, item.children, pathname);
break;
case '120000': // symbolic link
repo.blob(item.object, function(blob, err) {
fs.linkSync(pathname, blob.toString());
});
break;
case '160000': // submodule
fs.mkdirSync(pathname);
break;
default:
const mode = parseInt(item.mode.slice(-4), 8); // permissions
repo.blob(item.object, function(blob, err) {
fs.writeFileSync(pathname, blob, { mode: mode });
});
}
}
}
HTTP Authentication
const repo = geit('https://github.com/h2so5/geit.git', {
request: {
auth: { user: 'username', pass: 'password' },
},
});
Use leveldown instead of memdown
$ npm install --save leveldown
const levelup = require('levelup');
const repo = geit('https://github.com/h2so5/geit.git', {
db: levelup('./geit.db'),
});
API
geit(url[, options]) -> [Repository]
url
String - Repository URLoptions
Object
repo.refs([callback]) -> [Promise]
callback
Functionrefs
Object - Git referenceserr
Object - Error
repo.tree(id[, callback]) -> [Promise]
id
String - Commit ID | Branch name | Tag name | Ref namecallback
Functiontree
Object - Git treeerr
Object - Error
repo.blob(id[, callback]) -> [Promise]
id
String - Blob IDcallback
Functionblob
Buffer - Blob dataerr
Object - Error