Giter Site home page Giter Site logo

gitkit-js's Introduction

GitKit.js

NPM version Linux Build Status Windows Build status

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.

Installation

$ npm install gitkit

Usage

API Basics

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);
Clone a remote repository
// 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
})
List branches

GitKit.BranchUtils.list returns a promise listing branches as a list of strings.

GitKit.BranchUtils.list(repo)
    .then(function(branches) { ... })
Get current branch

GitKit.BranchUtils.getCurrent returns a promise resolved with the name of the current active branch.

GitKit.BranchUtils.getCurrent(repo)
    .then(function(branch) { ... })
List files in repository

GitKit.WorkingIndex provides a set of methods to work with the working index.

GitKit.WorkingIndex.readFromRepo(repo)
    .then(function(workingIndex) {
        var entries = workingIndex.getEntries();
    });
List changes not staged for commit

GitKit.ChangesUtils provides a set of methods to work with pending changes.

GitKit.ChangesUtils.list(repo)
    .then(function(changes) { ... });
Commit changes
var author = GitKit.Person.create('Bob', '[email protected]');
var message = 'My First commit';

GitKit.CommitUtils.createForChanges(repo, author, message, changes)
    .then(function(newRepo) { ... });
More example and documentation coming soon!

I'll publish a better documentation for this library soon.

Thanks

To the people pointing me in the right directions like:

License

GitKit.js is Apache-licensed.

gitkit-js's People

Contributors

samypesse avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.