Skip to content

Latest commit

 

History

History
58 lines (46 loc) · 2.84 KB

README.md

File metadata and controls

58 lines (46 loc) · 2.84 KB

Gitcovery

Build Status

A Python module that allows you to explore git repositories. It abstracts over the git system, hiding the command-line arguments behind simple function calls and objects. This makes the module useful when you want to run analyses on git repositories.
As an example of its simplicity, only 6 lines of Python code are needed to create a graph that shows evolution of the number of lines in this README-file over time. This includes the two lines that are always needed to draw any graph at all. Try running python examples/filesizePlot/filesizePlot.py from the root of this repository to check it out, or take a look at the other examples in the exmples folder.

Usage

This module wraps the git repository in the following ways, making it simple to get data from it without parsing the commandline output.

git = Git.set_root('path/to/repo')                                      # Select local dir
git = Git.clone('/tmp', 'https://github.com/ChielBruin/Gitcovery.git')  # Clone and select remote dir
git = Git.checkout('<branch>')
commit = Commit.get_commit('<commitHash>')

# Get the files in the tests folder
folder = git.get_folder('src/tests').children()
folder = git.src.tests.children()               # Functionally equivalent

# Get the author of the latest commit
print(git.history()[0].author)

# Get changes made to a file in the last commit
print(git.get_file('README.md').history()[0].changes(file='README.md'))
print(git.get_file('README.md').history()[0].changes().get_file('README.md'))
print(git.get_file('README.md').changes()[0])

# Compare the length of the full history with the length of that of the 'README.md' file
print(len(git.history()), len(git.get('README.md').history()))

# Get the status of a file
print(folder.get_file('a/file.txt').status())

# Print the name of all the files
git.for_each_file(lambda x: print(x.path))

To get a more in depth understanding of the module, take a look at the following sources:

  • exmples/
    A folder containing examples on how this module can be used. These examples include:
    • A basic example showing a little bit of everything
    • Plotting the file size of README.md over the evolution of a repository
  • REFERENCE.md
    A reference document with all the available classes and their functions and fields

Installation

To install the module simply run pip install . in the root of this repository.
Now, the module can simply be imported with

from gitcovery import Git

To run the tests for the module run: python setup.py test

Future work

  • Improve the implementation for diffs
    It now only records the metadata, making it impossible to reconstruct a file using all the Diffs in his history (except for its size).
  • Add more tests
  • More examples