Pure JavaScript implementation of Git backed by immutable models and promises.
The goal is to provide both a low and high level API for manipulating Git repositories: read files, commit changes, edit working index, clone, push, fetch, etc.
This library can work both in the browser and Node.js.
$ npm install gitkit
State of the Git repository is represented as a single immutable Repository
object. Read and write access to the repository is done using a FS
driver, the implementation of the fs depends on the plaftrom ( NativeFS
for Node.js/Native, LocalStorageFS
or MemoryFS
for the browser).
var GitKit = require('gitkit'); var NativeFS = require('gitkit/lib/fs/native'); // Prepare the filesystem var fs = NativeFS(process.cwd()); // Create a repository instance var repo = GitKit.Repository.createWithFS(fs, isBare);
// Create a transport instance for the GitHub repository var transport = new GitKit.HTTPTransport('https://github.com/GitbookIO/gitbook.git'); GitKit.TransferUtils.clone(repo, transport) .then(function(newRepo) { // Clone succeed! }, function(err) { // Clone failed })
GitKit.BranchUtils.list
returns a promise listing branches as a list of strings.
GitKit.BranchUtils.list(repo) .then(function(branches) { ... })
GitKit.BranchUtils.getCurrent
returns a promise resolved with the name of the current active branch.
GitKit.BranchUtils.getCurrent(repo) .then(function(branch) { ... })
GitKit.WorkingIndex
provides a set of methods to work with the working index.
GitKit.WorkingIndex.readFromRepo(repo) .then(function(workingIndex) { var entries = workingIndex.getEntries(); });
GitKit.ChangesUtils
provides a set of methods to work with pending changes.
GitKit.ChangesUtils.list(repo) .then(function(changes) { ... });
var author = GitKit.Person.create('Bob', 'bob@gmail.com'); var message = 'My First commit'; GitKit.CommitUtils.createForChanges(repo, author, message, changes) .then(function(newRepo) { ... });
I'll publish a better documentation for this library soon.
To the people pointing me in the right directions like:
GitKit.js
isApache-licensed.