AsyncGit

(Fully qualified class: privex.helpers.extras.git._AsyncGit)

class privex.helpers.extras.git._AsyncGit(repo: str = None, default_version: str = 'HEAD', **kwargs)[source]

Git CLI wrapper class - methods can be used both synchronously and async via AsyncGit / Git (aliases, both are the same)

This class uses the awaitable_class() decorator to make the class work both synchronously and asynchronously, without needing to duplicate code.

The awaitable_class() decorator detects whether the methods are being called from a synchronous, or an asynchronous function/method.

  • If they’re being called from an async function, then a coroutine will be returned, and must be await’ed.

  • If they’re being called from a synchronous function, then it will spin up an event loop, run the method in the event loop, then return the result transparently.

Synchronous usage:

>>> from privex.helpers import Git
>>> g = Git()   # Git is an alias for AsyncGit, there is no difference between them
>>>
>>> def some_func():
...     current_commit = g.get_current_commit()
...     print(current_commit)
'ac52b28f551825160785f9ea7e96f86ccc869cc1'

Asynchronous usage:

>>> from privex.helpers import Git
>>> g = Git()    # Git is an alias for AsyncGit, there is no difference between them
>>>
>>> async def some_func():
...     current_commit = await g.get_current_commit()
...     print(current_commit)
'ac52b28f551825160785f9ea7e96f86ccc869cc1'
__init__(repo: str = None, default_version: str = 'HEAD', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__([repo, default_version])

Initialize self.

__getattr__(item)

If an attribute doesn’t exist, this method will return a awaitable() function that simply calls git() with the attribute name as the first argument, followed by any additional positional/keyword arguments.

_repo([repo])

add(*args[, repo])

Use like git add

branch(*args[, repo])

checkout(branch, *args[, repo, new])

commit(message, *args[, repo])

Calls git commit with the arguments -m "message" [args], where each positional argument passed after the message is passed as a command line argument.

get_current_branch([repo])

Get current active branch/tag.

get_current_commit([version, repo])

Get current commit hash.

get_current_tag([version, repo])

Get the latest tag on this branch - useful for detecting current version of your python application.

git(*args[, repo, strip, stderr])

Wrapper async method for calling git executable command against a repo - casts args to str.

init(*args[, repo])

Use like git init

log(*args[, repo, concise])

status(*args[, repo, concise])

tag(*args[, repo])