I've gone with taking a string and converting it because the depth of the namespacing in the libgit2 name is rather large and we don't care about the global namespace that C has; and this also lets us pass the same as the '-X' option to git-merge.
pygit2 - libgit2 bindings in Python
Pygit2 is a set of Python bindings to the libgit2 shared library, libgit2 implements the core of Git. Pygit2 works with Python 2.7, 3.2, 3.3, 3.4 and pypy.
Links:
- http://github.com/libgit2/pygit2 -- Source code and issue tracker
 - http://www.pygit2.org/ -- Documentation
 - http://pypi.python.org/pypi/pygit2 -- Download
 
How to install
Changelog
0.21.3 (2014-09-15)
Breaking changes:
- Now 
Repository.blame(...)returnsOidinstead of string #413 - New 
Reference.set_target(...)replaces theReference.targetsetter andReference.log_append(...)#414 - New 
Repository.set_head(...)replaces theRepository.headsetter #414 Repository.merge(...)now uses theSAFE_CREATEstrategy by default #417
Other changes:
- New 
Remote.delete()#418 #420 - New 
Repository.write_archive(...)#421 - Now 
Repository.checkout(...)accepts branch objects #408 - Fix refcount leak in remotes #403 #404 #419
 - Various fixes to 
clone_repository(...)#399 #411 #425 #426 - Fix build error in Python 3 #401
 - Now 
pip install pygit2installs cffi first #380 #407 - Add support for pypy3 #422
 - Documentation improvements #398 #409
 
0.21.2 (2014-08-09)
- Fix regression with Python 2, 
IndexEntry.pathreturns str (bytes in Python 2 and unicode in Python 3) - Get back 
IndexEntry.oidfor backwards compatibility - Config, iterate over the keys (instead of the key/value pairs) #395
 Diff.find_similarsupports new threshold arguments #396- Optimization, do not load the object when expanding an oid prefix #397
 
0.21.1 (2014-07-22)
- Install fix #382
 - Documentation improved, including #383 #385 #388
 - Documentation, use the read-the-docs theme #387
 - Coding style improvements #392
 - New 
Repository.state_cleanup()#386 - New 
Index.conflicts#345 #389 - New checkout option to define the target directory #390
 
Backward incompatible changes:
Now the checkout strategy must be a keyword argument.
Change
Repository.checkout(refname, strategy)toRepository.checkout(refname, strategy=strategy)Idem for
checkout_head,checkout_indexandcheckout_tree
0.21.0 (2014-06-27)
Highlights:
- Drop official support for Python 2.6, and add support for Python 3.4 #376
 - Upgrade to libgit2 v0.21.0 #374
 - Start using cffi #360 #361
 
Backward incompatible changes:
- Replace 
oidbyidthrough the API to follow libgit2 conventions. - Merge API overhaul following changes in libgit2.
 - New 
Remote.rename(...)replacesRemote.name = ... - Now 
Remote.fetch()returns aTransferProgressobject. - Now 
Config.get_multivar(...)returns an iterator instead of a list. 
New features:
- New 
Config.snapshot()andRepository.config_snapshot() - New 
Configmethods:get_bool(...),get_int(...),parse_bool(...)andparse_int(...)#357 - Blob: implement the memory buffer interface #362
 - New 
clone_into(...)function #368 - Now 
Indexcan be used alone, without a repository #372 - Add more options to 
init_repository#347 - Support 
Repository.workdir = ...and support setting detached headsRepository.head = <Oid>#377 
Other:
- Fix again build with VS2008 #364
 - Fix 
Blob.diff(...)andBlob.diff_to_buffer(...)arguments passing #366 - Fail gracefully when compiling against the wrong version of libgit2 #365
 - Several documentation improvements and updates #359 #375 #378
 
0.20.3 (2014-04-02)
- A number of memory issues fixed #328 #348 #353 #355 #356
 - Compatibility fixes for PyPy (#338), Visual Studio 2008 (#343) and Python 3.3 (#351)
 - Make the sort mode parameter in 
Repository.walk(...)optional #337 - New 
Object.peel(...)#342 - New 
Index.add_all(...)#344 - Introduce support for libgit2 options #350
 - More informative repr for 
Repositoryobjects #352 - Introduce support for credentials #354
 - Several documentation fixes #302 #336
 - Tests, remove temporary files #341
 
0.20.2 (2014-02-04)
Repository:
- New 
Repository.default_signature#310 
Oid:
- New 
str(Oid)deprecatesOid.hex#322 
Object:
- New 
Object.iddeprecatesObject.oid#322 - New 
TreeEntry.iddeprecatesTreeEntry.oid#322 - New 
Blob.diff(...)andBlob.diff_to_buffer(...)#307 - New 
Commit.tree_idandCommit.parent_ids#73 #311 - New rich comparison between tree entries #305 #313
 - Now 
Tree.__contains__(key)supports paths #306 #316 
Index:
- Now possible to create 
IndexEntry(...)#325 - Now 
IndexEntry.path,IndexEntry.oidandIndexEntry.modeare writable #325 - Now 
Index.add(...)accepts anIndexEntrytoo #325 - Now 
Index.write_tree(...)is able to write to a different repository #325 - Fix memory leak in 
IndexEntry.pathsetter #335 
Config:
Remote:
- New type 
Refspec#314 - New 
Remote.push_url#315 - New 
Remote.add_pushandRemote.add_fetch#255 #318 - New 
Remote.fetch_refspecsreplacesRemote.get_fetch_refspecs()andRemote.set_fetch_refspecs(...)#319 - New 
Remote.push_refspecsreplacesRemote.get_push_refspecs()andRemote.set_push_refspecs(...)#319 - New 
Remote.progress,Remote.transfer_progressandRemote.update_tips#274 #324 - New type 
TransferProgress#274 #324 - Fix refcount leak in 
Repository.remotes#321 #332 
Other: #331
0.20.1 (2013-12-24)
- New remote ref-specs API: #290
 - New 
Repository.reset(...): #292, #294 - Export 
GIT_DIFF_MINIMAL: #293 - New 
Repository.merge(...): #295 - Fix 
Repository.blameargument handling: #297 - Fix build error on Windows: #298
 - Fix typo in the README file, Blog → Blob: #301
 - Now 
Diff.patchreturnsNoneif no patch: #232, #303 - New 
Walker.simplify_first_parent(): #304 
0.20.0 (2013-11-24)
- Upgrade to libgit2 v0.20.0: #288
 - New 
Repository.head_is_unbornreplacesRepository.head_is_orphaned - Changed 
pygit2.clone_repository(...). Droppush_url,fetch_specandpush_specparameters. Addignore_cert_errors. - New 
Patch.additionsandPatch.deletions: #275 - New 
Patch.is_binary: #276 - New 
Reference.log_append(...): #277 - New 
Blob.is_binary: #278 - New 
len(Diff)shows the number of patches: #281 - Rewrite 
Repository.status(): #283 - New 
Reference.shorthand: #284 - New 
Repository.blame(...): #285 - Now 
Repository.listall_references()andRepository.listall_branches()return a list, not a tuple: #289 
Authors
73 developers have contributed at least 1 commit to pygit2:
J. David Ibáñez            Rémi Duraffort             Alexander Bayandin
Carlos Martín Nieto        Sebastian Thiel            Andrew Chin
Nico von Geyso             Fraser Tweedale            András Veres-Szentkirályi
W. Trevor King             Han-Wen Nienhuys           Benjamin Kircher
Dave Borowitz              Leonardo Rhodes            Benjamin Pollack
Daniel Rodríguez Troitiño  Petr Viktorin              Bryan O'Sullivan
Richo Healey               Ron Cohen                  Daniel Bruce
Christian Boos             Thomas Kluyver             David Fischer
Julien Miotte              Alex Chamberlain           David Sanders
Xu Tao                     Amit Bakshi                Devaev Maxim
Jose Plana                 Andrey Devyatkin           Eric Davis
Matthew Gamble             Arno van Lumig             Erik Meusel
Martin Lenders             Ben Davis                  Erik van Zijst
Petr Hosek                 Eric Schrijver             Ferengee
Victor Garcia              Hervé Cauwelier            Gustavo Di Pietro
Xavier Delannoy            Huang Huang                Hugh Cole-Baker
Yonggang Luo               Ian P. McCullough          Jasper Lievisse Adriaanse
Valentin Haenel            Jack O'Connor              Josh Bleecher Snyder
Michael Jones              Jared Flatow               Mathieu Bridon
Bernardo Heynemann         Jiunn Haur Lim             Óscar San José
John Szakmeister           Jun Omae                   Ridge Kennedy
Matthew Duggan             Sarath Lakshman            Rui Abreu Ferreira
Brodie Rao                 Vicent Marti               earl
Vlad Temian                Zoran Zaric
David Versmisse            Adam Spiers
License
GPLv2 with linking exception.
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.
In addition to the permissions in the GNU General Public License, the authors give you unlimited permission to link the compiled version of this file into combinations with other programs, and to distribute those combinations without any restriction coming from the use of this file. (The General Public License restrictions do apply in other respects; for example, they cover modification of the file, and distribution when not linked into a combined executable.)
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
