Grit is a simple and light-weight git repository manager or git-compatible digital asset management system with limited remote object proxying, a http back-end and easy to use command line, python and web user interfaces.
Note
This is early prototype code, is missing many important features and probably won’t work for you
Features
Some noted differences from git
Known issues as of this release
Installing Grit is easily done using setuptools. Assuming it is installed, just run the following from the command-line:
$ easy_install grit
Alternatively, you can install from the distribution using the setup.py script:
$ git clone https://github.com/rsgalloway/grit.git
$ python setup.py install
Python and the following Python packages are required for Grit to work. Currently, git is required for checking in files and some operations like clone.
This is a simple tutorial using the command line interface for grit. The Python API is documented below. Note that grit is git-compatible, so you can also use git for many operations albiet with different syntax.
The new command creates the equivalent of a bare git repository. This “projects” repo will act as a starting point for creating branches later.
$ grit new /tmp/projects
Start the grit server on localhost port 80 and serve the “projects” repository.
$ grit serve /tmp/projects -p 80
Let’s branch some repositories off of the main “projects” repository. You can use either URLs or local paths here.
$ grit new http://localhost/animal
$ grit new http://localhost/animal/mammal
$ grit new http://localhost/animal/mammal/wolf
To override any files inherited from a branch parent, simply check in a file to the branch with the same name. To get thumbnails in the web UI, check in an appropriate png file called “thumb.png”.
Using grit, checkin a file to a remote repo
$ grit ci http://locahost/animal/mammal/wolf thumb.png
... or to a local repo
$ grit ci /tmp/projects/animal/mammal/wolf thumb.png
Using Python
>>> from grit import Repo
>>> r = Repo('/tmp/projects/animal/mammal/wolf')
>>> r.addFile('/path/to/thumb.png', 'Publishing thumbnail')
Adding multiple items to the same version
>>> from grit import Repo, Item
>>> v = r.addVersion()
>>> v.addFile(path='/path/to/fileA')
>>> v.addFile(path='/path/to/fileB')
>>> v.save('Publishing files')
Using git
$ git clone http://localhost/animal/mammal/wolf
$ cd wolf
$ git add thumb.png
$ git commit thumb.png "adding thumb"
$ git push
You can use grit to checkout the latest version of a repo (with revision depth=0), including all of the automatically inherited files from its branch parents.
$ grit co http://localhost/animal/mammal/wolf
Also with grit, you can check out a single file if you wish.
$ grit co http://localhost/animal/mammal/wolf/thumb.png
The following API docs cover the major classes.
Creates a new Repo instance. Most method and attribute calls are passed to the underlying repo object, which is either an instance of repo.Local or repo.Proxy, which is a proxy representation of a Local object served by the wsgi server.
Parameters: | url – HTTP URL or file path. |
---|---|
Returns: | New repo.Repo instance. |
For example:
>>> r = Repo('http://localhost/projects/myrepo')
or
>>> r = Repo('/tmp/myrepo')
Either way, you can make the same method and attribute calls:
>>> r.name
'myrepo'
>>> r.setDescription(desc='my project repository')
>>> r.versions()
>>> r.items()
>>> f = r.items(path='relative/path/to/file')
Creates a new Repo instance.
Parameters: |
|
---|---|
Returns: | grit.Repo instance. |
For example:
>>> r = Repo.new('/tmp/projects')
>>> r
<grit.Repo "/tmp/projects">
Clone the repository to path (requires git).
Parameters: |
|
---|---|
Returns: | grit.Repo instance. |
For example:
>>> r = Repo("http://localhost/projects/a/b/c")
>>> c = r.clone('/tmp')
>>> c
<grit.Repo "/tmp/c">
Local repository class.
add a new file(s)
add a new Item class object
Creates a new Version, to which Items can be added and removed, and committed.
Returns: | New Version instance. |
---|
Create a branch of this repo at ‘name’.
Parameters: |
|
---|---|
Returns: | New Local instance. |
Returns: | datetime object |
---|
Returns: | repository description |
---|
git command object
Returns a list of items.
Parameters: |
|
---|---|
Returns: | List of Item class objects. |
Create a new bare repo.Local instance.
Parameters: |
|
---|---|
Returns: | New repo.Local instance. |
Returns: | Remote origin as Proxy instance |
---|
sets repository description
Checkout a version of the repo.
Parameters: | version – Version number. |
---|
List of Versions of this repository.
Parameters: |
|
---|---|
Returns: | List of Version objects matching params. |
read blob on access only because get_object is slow
Check out file data to path.
Parameters: | path – Filesystem path to check out item to. |
---|---|
Returns: | True if successful. |
Returns: | blob data |
---|
Returns: | File-like StringIO object |
---|
Create a new Item from a file path.
Parameters: |
|
---|---|
Returns: | New Item class instance. |
Create a new Item from a data stream.
Parameters: |
|
---|---|
Returns: | New Item class instance. |
Modify item data and commit to repo. Git objects are immutable, to save means adding a new item
Parameters: | msg – Commit message. |
---|
Returns: | List of Versions for this Item |
---|
Create a new version of a repo.Local object.
Parameters: | repo – Instance of repo.Local. |
---|---|
Returns: | New Version instance. |
Add version to repo object store, set repo head to version sha.
Parameters: | message – Message string. |
---|
Returns: | Version number / index in list of versions |
---|