Christoffer
Christoffer

Reputation: 26835

Git library for Ruby or Python?

I'm looking for a Ruby or Python implementation of the Git client that can be used to update and commit changes in a local repository.

I prefer if the library does not use shell commands at all but keeps everything in "pure code".

Are there any?

Thank you in advance.

Upvotes: 7

Views: 3768

Answers (6)

hobs
hobs

Reputation: 19259

GitPython has an object-oriented API similar to Grit:

>>> #$ pip install GitPython
>>> import git
>>> repo = git.Repo('.')
>>> repo.git_dir
'/home/hobs/src/twip/.git'
>>> repo.bare
False
>>> repo.untracked_files
[u'twip/scripts.bak/__init__.py',
 u'twip/scripts.bak/cat_tweets.py',
 u'twip/scripts.bak/clean.py',
 u'twip/scripts.bak/explore.py',
 u'twip/scripts.bak/generate.py',
 u'twip/scripts.bak/plot_globe.py',
 u'twip/scripts.bak/skeleton.py']
>>> repo.head.ref
<git.Head "refs/heads/master">
>>> repo.tags
[<git.TagReference "refs/tags/0.0.1">,
 <git.TagReference "refs/tags/0.0.2">,
 <git.TagReference "refs/tags/0.0.3">]

Upvotes: 0

Micha&#235;l Witrant
Micha&#235;l Witrant

Reputation: 7714

There is now libgit2: a C library sponsored by Github with many bindings including Ruby and Python.

Upvotes: 3

J&#246;rg W Mittag
J&#246;rg W Mittag

Reputation: 369468

For Python, there is the Dulwich library which @RyanWilcox already mentioned.

For Ruby, there unfortunately is no Git library. There is Grit, which implements a subset of Git in Ruby and wraps the command line tools for some additional features, but only supports the subset of Git that GitHub needs. And you could use either JGit or Git# via JRuby or IronRuby.

Upvotes: 3

RyanWilcox
RyanWilcox

Reputation: 13972

There's also Dulwich, a Python implementation of the Git file formats and protocols.

Upvotes: 9

Eimantas
Eimantas

Reputation: 49354

You can check out ruby-git gem.

Upvotes: 3

miku
miku

Reputation: 188064

Grit gives you object oriented read/write access to Git repositories via Ruby.

require 'grit'
include Grit
repo = Repo.new("/Users/tom/dev/grit")

repo.commits
# => [#<Grit::Commit "e80bbd2ce67651aa18e57fb0b43618ad4baf7750">,
      #<Grit::Commit "91169e1f5fa4de2eaea3f176461f5dc784796769">,
      #<Grit::Commit "038af8c329ef7c1bae4568b98bd5c58510465493">,
      #<Grit::Commit "40d3057d09a7a4d61059bca9dca5ae698de58cbe">,
      #<Grit::Commit "4ea50f4754937bf19461af58ce3b3d24c77311d9">]

...

Upvotes: 6

Related Questions