Skip to content

suziwen/python-gitfile

 
 

Repository files navigation

gitfile - Git as a versioned file system and its RESTful interface

gitfile is a wrapper to Git and allows to edit files without checking out a repository. This library is in an alpha state and is dependent on the development branch of libgit2, and the master branch of pygit2.

Features

  • Create/Update/Delete files
  • Create/Delete branches
  • Create/Delete tags
  • RESTful interface

Dependencies

Install

$ ./install_libgit2.sh
$ virtualenv env --no-site-packages
$ export LIBGIT2=$PWD/env
$ env/bin/pip install -r requirements.txt -r requirements-test.txt
# this is weird...
$ ln -s env/lib/libgit2.0.17.0.dylib ./libgit2.0.dylib
$ env/bin/nosetests tests
$ env/bin/python app.wsgi

Example API usage

from gitfile.git import Git

git = Git('/path/to/gitdir')

blob_sha1 = git.create_blob('blah')
commit_sha1 = git.create_entry('master',
                               '/new_file.txt',
                               blob_sha1,
                               author_name='foo',
                               author_email='foo@example.com',
                               comment='adding new_file.txt')

Example RESTful JSON API usage

You can run a simple web server with the attached wsgi file. :

$ env/bin/python app.wsgi

To get a list of branches :

$ curl -is http://localhost:5000/test.git/branches
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 162
Server: Werkzeug/0.8.3 Python/2.7.3
Date: Thu, 03 Jan 2013 07:30:14 GMT

{
    "error": false,
    "message": null,
    "result": {
        "entries": {
            "master": "7769894b4941d8419f24bcead6efbdf11e483b36"
        }
    }
}

To create a new blob object :

$ curl -is -X POST -H 'Content-Type: text/plain' -d "test" http://localhost:5000/test.git/blobs
HTTP/1.0 201 CREATED
Content-Type: application/json
Content-Length: 155
Server: Werkzeug/0.8.3 Python/2.7.3
Date: Thu, 03 Jan 2013 07:32:16 GMT

{
    "error": false,
    "message": "A resource created successfully.",
    "result": {
        "sha1": "30d74d258442c7c65512eafab474568dd706c430"
    }
}

To add a new file in the master branch :

$ curl -is -X POST -H 'Content-Type: application/json' -d '{"sha1":"30d74d258442c7c65512eafab474568dd706c430","author_name":"foo","author_email":"foo@example.com"}' http://localhost:5000/test.git/branches/master/new_file.txt
HTTP/1.0 201 CREATED
Content-Type: application/json
Content-Length: 91
Server: Werkzeug/0.8.3 Python/2.7.3
Date: Thu, 03 Jan 2013 07:37:35 GMT

{
    "error": false,
    "message": "A resource created successfully.",
    "result": {}
}

To get a list of files in the root directory in the master branch :

$ curl -is http://localhost:5000/test.git/branches/master
HTTP/1.0 200 OK
Content-Type: application/json
Content-Length: 672
Server: Werkzeug/0.8.3 Python/2.7.3
Date: Thu, 03 Jan 2013 07:38:05 GMT

{
    "error": false,
    "message": null,
    "result": {
        "entries": [
            {
                "mode": "0100644",
                "name": ".git-placeholder",
                "sha1": "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391",
                "size": 0,
                "type": "blob"
            },
            {
                "mode": "0100644",
                "name": "new_file.txt",
                "sha1": "30d74d258442c7c65512eafab474568dd706c430",
                "size": 4,
                "type": "blob"
            }
        ],
        "name": "master",
        "sha1": "04f2c15b084af23a1120516bf6ea22e58090665a",
        "type": "branch"
    }
}

About

gitfile is a wrapper/REST interface to Git and allows to edit files without checking out a repository.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published