JS-Git

0.7.8 · abandoned · verified Sun Apr 19

JS-Git is a JavaScript implementation of the Git version control system, designed to enable Git-powered applications within restricted environments like Chromebooks and tablets, and to explore using Git as a data store alternative to SQL or NoSQL databases. The current stable version, 0.7.8, was released at a time when ES6 generators were a cutting-edge feature, indicating a focus on specific control flow patterns. The library differentiates itself by providing a modular architecture where various Git functionalities (like in-memory storage, tree creation, packfile operations, and history walking) are added as "mixins" to a base JavaScript object. This approach offers flexibility in building custom Git-enabled applications but requires manual composition of features. It supports both generator-based asynchronous operations and traditional Node.js-style callbacks. The project is effectively abandoned, with no significant updates or maintenance since around 2015.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates initializing an in-memory Git repository with various mixins and executing a basic tree creation operation using generator-based async control flow.

var modes = require('js-git/lib/modes');
var run = require('gen-run');

// Create a repo by creating a plain object.
var repo = {};

// Mix in various functionalities to the repo object
require('js-git/mixins/mem-db')(repo); // Provides in-memory storage
require('js-git/mixins/create-tree')(repo); // Adds high-level tree creation API
require('js-git/mixins/pack-ops')(repo); // Methods for packfile streams
require('js-git/mixins/walkers')(repo); // Algorithms for walking history/trees
require('js-git/mixins/read-combiner')(repo); // Combines parallel requests
require('js-git/mixins/formats')(repo); // Makes object interface less strict

run(function*() {
  try {
    // Example: Creating a simple tree object
    const treeHash = yield repo.createTree([
      { mode: modes.blob, path: "README.md", content: "Hello, js-git!" },
      { mode: modes.tree, path: "src", entries: [] } // An empty tree folder
    ]);
    console.log("Created tree with hash:", treeHash);

    // You could now save this tree as part of a commit, fetch blobs, etc.
    // For instance, loading the content of README.md (requires other mixins and setup)
    // const readmeBlob = yield repo.loadAs('blob', 'hash_of_readme_blob');
    // console.log("README content:", readmeBlob.toString());
    
    console.log("Repo initialized and a basic tree created.");
  } catch (err) {
    console.error("An error occurred:", err);
  }
});

view raw JSON →