Giter Club home page Giter Club logo

isomorphic-git's Introduction

isomorphic-git

A pure JavaScript implementation of git for node and browsers!

Latest release:

current npm version required node version written in ECMAScript 2017+ license gzip size install size

Master branch status:

semantic-release Build Status codecov dependencies Known Vulnerabilities FOSSA Status

Social:

Gitter chat Backers on Open Collective Sponsors on Open Collective

Browser Support:

Sauce Labs Test Status (for master branch)

Most recent build:

Build Status Build Status

isomorphic-git is a pure JavaScript implementation of git that works in node and browser environments (including WebWorkers and ServiceWorkers). This means it can be used to read and write to git repositories, as well as fetch from and push to git remotes like Github.

Isomorphic-git aims for 100% interoperability with the canonical git implementation. This means it does all its operations by modifying files in a ".git" directory just like the git you are used to. The included isogit CLI can operate on git repositories on your desktop or server.

isomorphic-git aims to be a complete solution with no assembly required. I've tried carefully to design the API so it is easy to use all the features, without paying a penalty in bundle size. By providing functionality as separate functions instead of an object oriented API, code bundlers like Webpack will only include the functionality your application actually uses. (Or at least that's the goal.)

I am working on adding type definitions so you can enjoy static type-checking and intelligent code completion in editors like CodeSandbox.

Getting Started

The "isomorphic" in isomorphic-git means it works equally well on the server or the browser. That's tricky to do since git uses the file system, and browsers don't have an fs module. So rather than relying on the fs module, isomorphic-git is BYOFS (Bring Your Own File System). When creating a new Git object, you pass it the fs module to use.

If you're only using isomorphic-git in Node, you can just use the native fs module.

const git = require('isomorphic-git');
const fs = require('fs');
git.listFiles({fs, dir: __dirname});

If you're writing code for the browser though, you'll need something that emulates the fs API. At the time of writing, the most complete option is BrowserFS. It has a few more steps involved to set up than in Node, as seen below:

<script src="https://unpkg.com/browserfs"></script>
<script src="https://unpkg.com/isomorphic-git"></script>
<script>
BrowserFS.configure({ fs: "IndexedDB", options: {} }, function (err) {
  if (err) return console.log(err);
  window.fs = BrowserFS.BFSRequire("fs");
  git.listFiles({fs: window.fs, dir: '/'});
});
</script>

Besides IndexedDB, BrowserFS supports many different backends with different performance characteristics, as well as advanced configurations such as: multiple mounting points, and overlaying a writeable filesystems on top of a read-only filesystem. You don't need to know about all these features, but familiarizing yourself with the different options may be necessary if you hit a storage limit or performance bottleneck in the IndexedDB backend I suggested above.

View the full Getting Started guide here.

CORS support

Unfortunately, due to the same-origin policy by default isomorphic-git can only clone from the same origin as the webpage it is running on. This is terribly inconvenient, as it means for all practical purposes cloning and pushing repos must be done through a proxy.

I have created cors-buster which you can clone or npm install cors-buster or deploy to Now.sh. I used to have an instance up, but it got abused so be careful.

It is literally just two lines of code to add the CORS headers!! Easy stuff. Surely it will happen.

Using as an npm module

You can install it from npm.

npm install --save isomorphic-git

In the package.json you'll see there are actually 4 different versions:

  "main": "dist/for-node/",
  "browser": "dist/for-browserify/",
  "module": "dist/for-future/",
  "unpkg": "dist/bundle.umd.min.js",

This probably deserves a brief explanation.

  • the "main" version is for node.
  • the "browser" version is for browserify.
  • the "module" version is for native ES6 module loaders when they arrive.
  • the "unpkg" version is the UMD build.

For more details about each build see ./dist/README.md

isogit CLI

Isomorphic-git comes with a simple CLI tool, named isogit because isomorphic-git is a lot to type. It is really just a thin shell that translates command line arguments into the equivalent JS API commands. So you should be able to run any current or future isomorphic-git commands using the CLI.

It always starts with an the assumption that the current working directory is a git root. E.g. repo = new Git({fs, dir: '.'}).

It uses minimisted to parse command line options.

TODO: Document this more. Also write some tests? IDK the CLI is more of a lark for testing really.

Supported Git commands

I may continue to make changes to the API until the 1.0 release, after which I promise not to make any breaking changes.

commands

utils

Internal code architecture

I have written this library as a series of layers that build upon one another and should tree-shake very well:

Commands

Each command is available as its own file, so you are able to import individual commands if you only need a few in order to optimize your bundle size.

Managers

Managers are a level above models. They take care of implementation performance details like

  • batching reads to and from the file system
  • in-process concurrency locks
  • lockfiles
  • caching files and invalidating cached results
  • reusing objects
  • object memory pools

Models and Utils

Models and utils are the lowest level building blocks. Models generally have very few or no dependencies except for 'buffer'. This makes them portable to many different environments so they can be a useful lowest common denominator.

Utils are basically miscellaneous functions. Some are convenience wrappers for common filesystem operations.

Who is using isomorphic-git?

  • nde - a futuristic next-generation web IDE
  • git-app-manager - install "unhosted" websites locally by git cloning them

Similar projects

Acknowledgments

Isomorphic-git would not have been possible without the pioneering work by @creationix and @chrisdickinson. Git is a tricky binary mess, and without their examples (and their modules!) I would not have been able to come even close to finishing this. They are geniuses ahead of their time.

Contributors

Thanks goes to these wonderful people (emoji key):


William Hilton

πŸ“ πŸ› πŸ’» 🎨 πŸ“– πŸ’‘ ⚠️ βœ…

wDhTIG

πŸ›

Marc MacLeod

πŸ€” πŸ”

Brett Zamir

πŸ€”

Dan Allen

πŸ› πŸ€”

TomΓ‘Ε‘ HΓΌbelbauer

πŸ› πŸ’»

Juan Campa

πŸ›

Ira Miller

πŸ›

Rhys Arkins

πŸ’»

Sean Larkin

πŸ’»

Daniel Ruf

πŸ’»

bokuweb

πŸ’» πŸ“– ⚠️

Hiroki Osame

πŸ’» πŸ“–

Jakub Jankiewicz

πŸ’¬ πŸ› πŸ’» πŸ’‘ ⚠️

howardgod

πŸ› πŸ’»

burningTyger

πŸ›

Melvin Carvalho

πŸ“–

This project follows the all-contributors specification. Contributions of any kind welcome!

Backers

Thank you to all our backers! πŸ™ [Become a backer]

Sponsors

Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [Become a sponsor]

License

This work is released under The MIT License

FOSSA Status

isomorphic-git's People

Contributors

billiegoose avatar renovate[bot] avatar greenkeeper[bot] avatar tomashubelbauer avatar danielruf avatar akajes avatar bokuweb avatar erdahuja avatar privatenumber avatar jcubic avatar jdanford avatar melvincarvalho avatar renovate-bot avatar rarkins avatar thelarkinn avatar styfle avatar stickler-ci avatar alexandercbooth avatar fossabot avatar howardgod avatar monkeywithacupcake avatar

Watchers

James Drew 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.