Git commit from python

I want to write a module in python (This is a training project) to improve my git experience. Is there a python module for various git commands? At least the basic ones (commit / diff / log / add)?

I saw GitPython , but I could not find support for (new) commits; it's more of a repo viewer structure than a full git interface. (Or am I missing something?)

Also, if there is a python module for all of this, would it be preferable or executing shell commands from python code?

+6
source share
2 answers

In GitPython, you create a commit from an index object .

In libgit2, you create a commit from a repository object .

You can also look at this question:

+10
source

Git is designed for plumbing and porcelain. Plumbing components form the basis of a low-level system: managing objects, repositories, remotes, etc. Porcelain, on the other hand, means more comfortable high-level tools that use plumbing.

Historically, only the most basic / critical elements (mainly plumbing) were implemented in C, the rest used shell / perl scripts. To be more portable, more and more code was rewritten in C.

Against this background, I would recommend just using the system calls for the git executable for your python packaging. View your code as part of china git. Compared to using a specialized library:

PRO

  • No need to learn the API - use git commands that you are familiar with
  • A complete set of tools - you can use porcelain and not be limited to low-level functionality

CONTRA

  • You need to analyze the command line output from git calls.
  • May be slower
+9
source

Source: https://habr.com/ru/post/895401/


All Articles