Skip to content

Refactor to ES6 + Flow #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 57 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
ae71585
Start new
SamyPesse Jun 18, 2017
f38b202
Start model GitObject and jest tests
SamyPesse Jun 18, 2017
bbe781d
Add path for git objects
SamyPesse Jun 18, 2017
580e73d
Add unit tests for Author
SamyPesse Jun 18, 2017
5b5243f
Continue
SamyPesse Jun 18, 2017
7304062
Ignore lib folder
SamyPesse Jun 18, 2017
b0bb345
Implement node fs
SamyPesse Jun 18, 2017
b5a0327
Start new cli
SamyPesse Jun 18, 2017
bb58b1d
Fix iterating over a tree
SamyPesse Jun 19, 2017
826f48e
Add unit tests for tree parsing
SamyPesse Jun 19, 2017
f2fcafd
Improve cli command ls-tree
SamyPesse Jun 19, 2017
813cb09
Add parsing for commits
SamyPesse Jun 19, 2017
f2eba19
Add method Repository.walkCommits and log command
SamyPesse Jun 19, 2017
4b74d83
Add head / ref parsing
SamyPesse Jun 19, 2017
47aeeff
Add MemoryFS
SamyPesse Jun 19, 2017
60b03d4
Ensure file exists before write
SamyPesse Jun 19, 2017
d3e14d6
Add method readTree on fs to list all files
SamyPesse Jun 19, 2017
931e905
Fix Head.isDetached
SamyPesse Jun 19, 2017
3b980db
Add command to list refs
SamyPesse Jun 19, 2017
2cc48ed
Add model RefsIndex to list refs
SamyPesse Jun 20, 2017
3eac9f7
Complete listing of branches
SamyPesse Jun 20, 2017
13b92ac
Start parsing of pack files
SamyPesse Jun 20, 2017
7882d34
Complete parsing of packfiles
SamyPesse Jun 20, 2017
bd90ea2
Start indexing of object files
SamyPesse Jun 21, 2017
c124c68
Cleanup code with prettier and airbnb config
SamyPesse Jun 21, 2017
4c101d5
Add parsing WorkingIndex
SamyPesse Jun 21, 2017
9ff8ace
Add command ls-files
SamyPesse Jun 21, 2017
00eb452
Add tag command
SamyPesse Jun 21, 2017
4fec2eb
Add base document about support
SamyPesse Jun 21, 2017
c8f0562
Show current branch in listing with "gitkit branch"
SamyPesse Jun 21, 2017
edc3380
Start transforms and doc
SamyPesse Jun 22, 2017
d13d101
Add Head, start testing Transform
SamyPesse Jun 22, 2017
8902757
Start logic to read object from packfiles
SamyPesse Jun 24, 2017
56930bb
Parse version of packfile index
SamyPesse Jun 25, 2017
99088ca
Parse shas and crcs from packfile index
SamyPesse Jun 25, 2017
12b94d4
Complete parsing of offsets
SamyPesse Jun 25, 2017
62241b1
Fix indexation of objects
SamyPesse Jun 25, 2017
9e0a321
Add method readAt for fs
SamyPesse Jun 25, 2017
98e8296
Add unit test for readAt
SamyPesse Jun 25, 2017
2f5033d
Add pretty printing in cat-file
SamyPesse Jun 25, 2017
d6fff81
Fix command show-refs
SamyPesse Jun 25, 2017
587a3a1
Add first step for fetch: discovery
SamyPesse Jun 26, 2017
1143959
Strat implementing fetch transform/command
SamyPesse Jun 26, 2017
86d8c69
Start parser for config
SamyPesse Jun 27, 2017
4806438
Add method to write the config
SamyPesse Jun 27, 2017
7347ba7
Add transform to add a remote
SamyPesse Jun 27, 2017
65a106a
Adapt parsing of discovery
SamyPesse Jun 28, 2017
c325553
Add global GitKit class
SamyPesse Jun 29, 2017
42773a8
Adapt all commands
SamyPesse Jun 29, 2017
8e3c4fb
Fix unit tests for HEAD/Ref
SamyPesse Jun 29, 2017
816c808
Fix listing of refs
SamyPesse Jun 29, 2017
cdb2892
Fix command log
SamyPesse Jun 29, 2017
093491d
Implement init command
SamyPesse Jun 29, 2017
d328706
Update readme example
SamyPesse Jun 29, 2017
c08bc63
Remove doc
SamyPesse Jun 29, 2017
b31061c
Improve command init
SamyPesse Jun 29, 2017
15bf92a
Start command add
SamyPesse Jun 29, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015", "stage-0"],
"plugins": ["transform-flow-strip-types"]
}
53 changes: 31 additions & 22 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
{
"rules": {
"indent": [ 2, 4 ],
"quotes": [ 2, "single" ],
"linebreak-style": [ 2, "unix" ],
"semi": [ 2, "always" ],
"no-unused-vars": [ 2, {
"vars": "all",
"args": "none"
} ],
"spaced-comment": [ 2, "always" ]
},
"env": {
"node": true,
"mocha": true,
"browser": true,
"jasmine": true
},
"globals": {
"fixtures": true
},
"extends": "eslint:recommended"
}
"extends": [
"airbnb-base",
"plugin:flowtype/recommended",
"prettier",
"prettier/flowtype"
],
"plugins": [
"flowtype",
"prettier"
],
"env": {
"jest": true
},
"rules": {
"eqeqeq": ["off"],
"no-bitwise": ["off"],
"class-methods-use-this": ["off"],
"import/prefer-default-export": ["off"],
"arrow-body-style": ["error", "as-needed"],
"no-use-before-define": ["error", { "functions": false }],
"no-param-reassign": ["error", { "props": false }],
"no-unused-vars": ["error", {
"args": "none"
}],
"prettier/prettier": ["error", {
"singleQuote": true,
"parser": "flow",
"tabWidth": 4
}]
}
}
10 changes: 10 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ignore]
./lib

[include]

[libs]

[options]
emoji=true
unsafe.enable_getters_and_setters=true
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ build/Release
node_modules

.tmp
lib/
7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
sudo: false
language: node_js
node_js:
- "stable"
- "stable"
script:
- npm run test
- npm run lint
after_script:
- npm run flow
140 changes: 66 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,100 +4,92 @@
[![Linux Build Status](https://travis-ci.org/SamyPesse/gitkit-js.svg?branch=master)](https://travis-ci.org/SamyPesse/gitkit-js)
[![Windows Build status](https://ci.appveyor.com/api/projects/status/63nlflxcwmb2pue6?svg=true)](https://ci.appveyor.com/project/SamyPesse/gitkit-js)

Pure JavaScript implementation of Git backed by immutable models and promises.
GitKit is a 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.
The goal of this project is not to be used in real-world projects, but instead to provides a readable (the code is typed using flow) JS implementation of the Git-backend with a high-level API for manipulating repositories: read files, commit changes, clone, push, etc. See [Support](#support) for details about supported operations.

This library can work both in the browser and Node.js.

## Installation

```
$ npm install gitkit
$ yarn add 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).

```js
var GitKit = require('gitkit');
var NativeFS = require('gitkit/lib/fs/native');

// Prepare the filesystem
var fs = NativeFS(process.cwd());
## CLI

// Create a repository instance
var repo = GitKit.Repository.createWithFS(fs, isBare);
```
GitKit implements a CLI with the goal of being compatible with the official Git command.

##### Clone a remote repository
⚠️ **Do not use it:** GitKit is for testing-only.

```js
// 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
})
$ npm install gitkit --global
$ gitkit clone https://github.com/GitbookIO/gitkit.git ./repo
```

##### List branches

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

```js
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.

```js
GitKit.BranchUtils.getCurrent(repo)
.then(function(branch) { ... })
```

##### List files in repository

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

```js
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.

```js
GitKit.ChangesUtils.list(repo)
.then(function(changes) { ... });
```
## Usage

##### Commit changes
State of the Git repository is represented as a single immutable `Repository` instance. Read and write access to the repository is done using a `FS` driver, the implementation of the fs depends on the platform (`NativeFS` for Node.js, `LocalStorageFS` or `MemoryFS` for the browser).

```js
var author = GitKit.Person.create('Bob', '[email protected]');
var message = 'My First commit';

GitKit.CommitUtils.createForChanges(repo, author, message, changes)
.then(function(newRepo) { ... });
import GitKit, { Repository } from 'gitkit';

import NativeFS from 'gitkit/lib/fs/native';

// Create a filesystem to access the repository on the disk:
const fs = new NativeFS(process.cwd());

// Create a repository:
const repo = new Repository({ fs });
const gitkit = new GitKit(repo);

// Commit some changes
gitkit
.writeFile('README.md', 'Hello world')
.then(() => gitkit.addFile('README.md'))
.then(() => gitkit.commit({
message: 'Update README',
author: Author.createFromPerson(
Person.create({
name: 'John Doe',
email: '[email protected]'
})
)
}));
```

##### More example and documentation coming soon!

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

| Description | Status |
| --------- |:-----------:|
| Initialize a new repository | ✅ |
| **References** | |
| Listing refs (branches, tags), both from packed-refs or refs folder | ✅ |
| Create a new reference | ❌ |
| **Branches** | |
| Read current HEAD | ✅ |
| Checkout a branch (update HEAD and working files) | ❌ |
| **Index** | |
| Listing files in the `.git/index` | ✅ |
| Add new file in the index | ❌ |
| Update the index from the file in the repository | ❌ |
| **Trees** | |
| List all entries in a tree | ✅ |
| Create a new tree | ❌ |
| **Blobs** | |
| Read a blob by its sha | ✅ |
| Create a new blob | ❌ |
| **Commits** | |
| Read a commit by its sha | ✅ |
| Walk the commits history | ✅ |
| Create a new commit | ❌ |
| **Clone / Fetch** | |
| Discovery with the remote repository | ✅ |
| Fetch a reference | ❌ |
| Clone a new repository | ❌ |
| **Transports** | |
| HTTP / HTTPS | ✅ |
| SSH | ❌ |

## Thanks

Expand Down
8 changes: 0 additions & 8 deletions bin/add.js

This file was deleted.

17 changes: 0 additions & 17 deletions bin/branch.js

This file was deleted.

51 changes: 0 additions & 51 deletions bin/cat-file.js

This file was deleted.

17 changes: 0 additions & 17 deletions bin/command.js

This file was deleted.

28 changes: 0 additions & 28 deletions bin/commit.js

This file was deleted.

Loading