Tutorial

Importing Maggit

This is pretty simple

import maggit

You can use the star import if you want

from maggit import *

For the rest of the tutorial, we’ll assume that you import maggit and do not use the star import.

Get a repository

A Repo is one the central objects when interactig with maggit:

# Create a repository
repo = maggit.Repo()

By default, Maggit will look for a git repository in your current directory. If you want to explore a repository elsewhere, specify it:

repo = maggit.Repo("a/git/repository")

You don’t have to specify a the root directory of the repository. If the directory you specify is not a git repository, maggit will look up in the parents directories.

References

Once we’ve got a repository, the first thing we may want to do is list it’s references (branches, tags):

branches = repo.branches
print(repo.branches.keys())

repo.branches is a dictionnary mapping all branches of the repository

If we want manipulate the master branch, lets get it:

master = branches['master']

In the same way repo.tags is a dictionnary mapping all tags of the repository

All the references we get, whatever they are branches, lightweigh tag or real tag objects share a common api. The most interesting here, is to get the commit object pointed to by the ref:

commit = master.commit

The commit object

Other important object in Maggit is naturally the git objects. A git object firstly allow us to access to the content of the object itself.

The commit object is one of them. Naturally it allows us to access the commit attributes:

commit.message
commit.first_line #The first line of the message
commit.author
commit.committer
commit.parents # The parents of the commit
commit.tree # The tree object