https://github.com/creationix/node-git
Node.JS library to read git repositories.
https://github.com/creationix/node-git
Last synced: 11 months ago
JSON representation
Node.JS library to read git repositories.
- Host: GitHub
- URL: https://github.com/creationix/node-git
- Owner: creationix
- Created: 2010-04-06T14:28:59.000Z (about 16 years ago)
- Default Branch: master
- Last Pushed: 2015-03-17T15:23:28.000Z (over 11 years ago)
- Last Synced: 2025-05-30T01:55:39.878Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 162 KB
- Stars: 205
- Watchers: 10
- Forks: 30
- Open Issues: 9
-
Metadata Files:
- Readme: README.markdown
Awesome Lists containing this project
README
# node-git
This is a thin wrapper around the command-line `git` command for use inside node applications. It's used primarily by the [wheat][] blogging system to enable a running node.JS server to read files out of a git repository as if they were local files.
## Example usage
```js
var sys = require('sys'),
Git = require('git');
// Test it!
Git("/Users/tim/code/howtonode.org");
Git.exists("articles/control-flow-part-ii.markdown", function (err, tags) {
if (err) { throw(err); }
sys.p(tags);
});
Git.getTags(function (err, tags) {
if (err) { throw(err); }
Object.keys(tags).forEach(function (tag) {
Git.readDir("articles", tags[tag], function (err, contents) {
if (err) { throw(err); }
contents.files.forEach(function (file) {
file = Path.join("articles", file);
Git.readFile(file, tags[tag], function (err, text) {
if (err) { throw(err); }
sys.error("tag: " + tag + " sha1: " + tags[tag] + " file: " + file + " length: " + text.length);
});
});
});
});
});
```
More example:
```js
var sys = require('sys');
// Git("/Users/tim/git/howtonode.org.git");
Git("/Users/tim/Code/howtonode.org");
Git.log("articles/what-is-this.markdown", function (err, data) {
if (err) throw err;
sys.p(data);
process.exit();
});
```
[wheat]: http://github.com/creationix/wheat