{"id":14646,"library":"js-git","title":"JS-Git","description":"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.","status":"abandoned","version":"0.7.8","language":"javascript","source_language":"en","source_url":"git://github.com/creationix/js-git","tags":["javascript","git","js-git"],"install":[{"cmd":"npm install js-git","lang":"bash","label":"npm"},{"cmd":"yarn add js-git","lang":"bash","label":"yarn"},{"cmd":"pnpm add js-git","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required to execute generator-based asynchronous functions, which is a primary control flow style for js-git.","package":"gen-run","optional":false}],"imports":[{"note":"JS-Git uses CommonJS `require()` exclusively. There is no ES Module export.","wrong":"import { modes } from 'js-git/lib/modes';","symbol":"modes","correct":"var modes = require('js-git/lib/modes');"},{"note":"Mixins are functions that directly modify the `repo` object when called with it, not modules to be imported and assigned.","wrong":"import memDbMixin from 'js-git/mixins/mem-db';","symbol":"memDbMixin","correct":"require('js-git/mixins/mem-db')(repo);"},{"note":"Like other mixins, `create-tree` is a CommonJS module that exports a function to augment the `repo` object.","wrong":"import { createTree } from 'js-git/mixins/create-tree';","symbol":"createTreeMixin","correct":"require('js-git/mixins/create-tree')(repo);"},{"note":"The `gen-run` dependency also uses CommonJS `require()`.","wrong":"import run from 'gen-run';","symbol":"run","correct":"var run = require('gen-run');"}],"quickstart":{"code":"var modes = require('js-git/lib/modes');\nvar run = require('gen-run');\n\n// Create a repo by creating a plain object.\nvar repo = {};\n\n// Mix in various functionalities to the repo object\nrequire('js-git/mixins/mem-db')(repo); // Provides in-memory storage\nrequire('js-git/mixins/create-tree')(repo); // Adds high-level tree creation API\nrequire('js-git/mixins/pack-ops')(repo); // Methods for packfile streams\nrequire('js-git/mixins/walkers')(repo); // Algorithms for walking history/trees\nrequire('js-git/mixins/read-combiner')(repo); // Combines parallel requests\nrequire('js-git/mixins/formats')(repo); // Makes object interface less strict\n\nrun(function*() {\n  try {\n    // Example: Creating a simple tree object\n    const treeHash = yield repo.createTree([\n      { mode: modes.blob, path: \"README.md\", content: \"Hello, js-git!\" },\n      { mode: modes.tree, path: \"src\", entries: [] } // An empty tree folder\n    ]);\n    console.log(\"Created tree with hash:\", treeHash);\n\n    // You could now save this tree as part of a commit, fetch blobs, etc.\n    // For instance, loading the content of README.md (requires other mixins and setup)\n    // const readmeBlob = yield repo.loadAs('blob', 'hash_of_readme_blob');\n    // console.log(\"README content:\", readmeBlob.toString());\n    \n    console.log(\"Repo initialized and a basic tree created.\");\n  } catch (err) {\n    console.error(\"An error occurred:\", err);\n  }\n});","lang":"javascript","description":"Demonstrates initializing an in-memory Git repository with various mixins and executing a basic tree creation operation using generator-based async control flow."},"warnings":[{"fix":"Use a generator runner like `gen-run` or transpile with tools like `regenerator`. Do not attempt to use `async/await` directly with `yield` statements.","message":"Reliance on ES6 Generators and `yield` for async operations. This library's primary asynchronous control flow pattern uses ES6 generators with `yield`, often orchestrated by external runners like `gen-run`. This is not compatible with modern `async/await` syntax directly without transpilation or wrapping.","severity":"breaking","affected_versions":"*"},{"fix":"Ensure your project is configured to use CommonJS modules or use dynamic `import()` if absolutely necessary, though direct `require()` is the intended usage.","message":"CommonJS Module System Only. `js-git` exclusively uses CommonJS `require()` for module loading and is not directly compatible with ES Modules `import` syntax.","severity":"gotcha","affected_versions":"*"},{"fix":"Review the documentation for required mixins and ensure all necessary functionalities are explicitly applied to your repository object using `require('js-git/mixins/...')(...)(repo)`.","message":"Manual Mixin Composition Required. Unlike many modern libraries, `js-git` requires developers to manually apply each desired functionality (e.g., storage, tree operations, walkers) as 'mixins' to a base repository object. Forgetting a mixin will result in missing methods.","severity":"gotcha","affected_versions":"*"},{"fix":"Consider alternative, actively maintained Git-related libraries for JavaScript, or be prepared to fork and maintain `js-git` yourself if specific features are indispensable.","message":"Project Abandoned: `js-git` has not been actively maintained for several years (since approximately 2015). This means no new features, bug fixes, or security patches will be released, and it may not be compatible with newer Node.js versions or browser environments without significant effort.","severity":"breaking","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Wrap generator functions with a generator runner (e.g., `gen-run`) or ensure `yield` is used only within a generator context, not directly with `async/await`. For modern async/await, you'd need a compatibility layer or a different library.","cause":"Attempting to use `yield` within an `async function` or `await` with a generator-based function without proper wrapping, or trying to use `await` with `js-git`'s generator-style APIs directly.","error":"SyntaxError: await is only valid in async functions and the top level bodies of modules"},{"fix":"Ensure `require('js-git/mixins/create-tree')(repo);` (and all other necessary mixins for the methods you intend to use) has been called to augment the `repo` object with the desired functionalities.","cause":"The `create-tree` mixin (or any other required mixin) was not applied to the `repo` object, meaning the method was never added.","error":"TypeError: repo.createTree is not a function"},{"fix":"Verify the module path is correct relative to the `node_modules` directory. Ensure your environment supports CommonJS `require()` statements, as `js-git` does not ship with ES Module exports.","cause":"Incorrect module path or attempting to use `import` syntax in an environment that only supports CommonJS `require()` for this package, or vice-versa.","error":"Error: Cannot find module 'js-git/lib/modes'"},{"fix":"When using the callback style, ensure the callback function is provided as the last argument to the `js-git` API call: `someAction(args, function (err, value) { ... });`. If you intended to curry, make sure to invoke the curried function: `someAction(args)(function (err, value) { ... });`.","cause":"When using `js-git`'s callback-style APIs, if a callback is not provided, the function returns a partially applied function. This error occurs if that returned function is not subsequently invoked with the callback.","error":"TypeError: someAction(...) is not a function (when trying to use callback style)"}],"ecosystem":"npm"}