Skip to main content

Intuitive Git for Python

Project description

ci python3.8 pypi codecov.io mit black

Intuitive Git for Python

Install

Dependencies: git ^2.0.0 (tested)

pip install gitspy

Development

poetry install

Example Usage

Get branch

>>> import gitspy
>>> git = gitspy.Git()
>>> # capture will store stdout, which can then be consumed by
>>> # calling `git.stdout()`
>>> # default is to print stdout, and stderr, to console
>>> returncode = git.symbolic_ref("--short", "HEAD", capture=True)
>>> print(returncode)  # printing returncode
0
>>> # consume stdout, a list containing a `str` of the checked out
>>> # branch
>>> stdout = git.stdout()  # -> ['checked-out-branch']
>>> items = len(stdout)  # printing length of `stdout()` outputs
>>> print(items)
1
>>> # no commands have been called yet since last call to `stdout`,
>>> # so stdout is empty
>>> stdout = git.stdout()  # -> []
>>> items = len(stdout)  # printing length of ``stdout()`` outputs
>>> print(items)
0
>>> # stdout can be accrued
>>> # ['checked-out-branch', 'checked-out-branch']
>>> git.symbolic_ref("--short", "HEAD", capture=True)
>>> git.symbolic_ref("--short", "HEAD", capture=True)
>>> print(len(git.stdout()))
2
>>> # stdout is consumed
>>> print(len(git.stdout()))
0
>>> git.symbolic_ref("--short", "HEAD", capture=True)
>>> git.stdout()  # [...] -> void; clear stdout, if it exists
>>> print(len(git.stdout()))
0

Get commit hash

>>> import gitspy
>>> git = gitspy.Git()
>>> git.rev_parse("HEAD", capture=True)
>>> stored = git.stdout()[0]
>>> print(len(stored))  # print the length of the unique hash
40

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitspy-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

gitspy-0.1.1-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page