Giter VIP home page Giter VIP logo

es-git's Introduction

ES-Git

Git implemented in EcmaScript, a fork of JS-Git

Example

DEMOS (source: packages/example)

This basic example shows how to do low-level manipulation of an in-memory repository

import { Mode, mix } from '@es-git/core';
import MemoryRepo from '@es-git/memory-repo';
import objectMixin from '@es-git/object-mixin';
import saveAsMixin from '@es-git/save-as-mixin';
import loadAsMixin from '@es-git/load-as-mixin';

async function test(){
  // Create the repository in memory and
  // enhance it using three mixins
  class Repo extends mix(MemoryRepo)
                    .with(objectMixin)
                    .with(saveAsMixin)
                    .with(loadAsMixin) {}

  // Create an instance of the repository
  const repo = new Repo();

  // Save a text file in the repo with the contents `hello`
  const hash = await repo.saveText('hello');

  // Save a folder with one file, the one we created above
  const tree = await repo.saveTree({
    'file.txt': {
      mode: Mode.file,
      hash
    }
  });

  // Commit the file and folder to the repo
  const commitHash = await repo.saveCommit({
    author: {
      name: 'Tim Caswell',
      email: '[email protected]',
      date: new Date()
    },
    committer: {
      name: 'Marius Gundersen',
      email: '[email protected]',
      date: new Date()
    },
    message: 'initial commit',
    tree,
    parents: []
  });

  // Point the master branch to the commit
  await repo.setRef('refs/heads/master', commitHash);

  // Get the hash that the master branch points to
  const refHash = await repo.getRef('refs/heads/master');
  if(!refHash) throw new Error('branch does not exist');

  // Get the commit (the hash of the tree and the message) using the hash
  const {tree: treeHash, message} = await repo.loadCommit(refHash);
  console.log(message); // `initial commit`

  // Get the hash to the `file.txt' file in the tree
  const {'file.txt': {hash: fileHash}} = await repo.loadTree(treeHash);

  // Get the content of the file as a string
  const content = await repo.loadText(fileHash);
  console.log(content) // `hello`
};

test();

Repositories

These are the core storage packages. They all implement IRawRepo. Pick one that fits your project, and enhance it with the mixins.

Mixins

These mixins add features to the repo. Some of them depend on other mixins, so the order in which the mixins are applied is significant.

Other packages

Relationship to JS-Git

This project is a fork of JS-Git, refactored and rewritten in TypeScript. See #132 for more information.

es-git's People

Contributors

aaronhammond avatar aaronpowell avatar alexbirkett avatar aredridel avatar creationix avatar dfries avatar doublelift avatar dregin avatar dscho avatar funroll avatar gijswijs avatar gitter-badger avatar kmalakoff avatar kriskowal avatar mariusgundersen avatar mintbridge avatar mrscreationix avatar scottgonzalez avatar seriema avatar spiralp avatar tombyrer avatar tracker1 avatar vsivsi avatar wkonkel avatar

Watchers

 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.