Git
This module provides basic functionality to interact with git. It comes in handy when writing deployment scripts.
Interacting with a repository
All repository interactions are done through the Repo
class
and its methods. If an interaction fails, a GitException
is raised.
Commit and status objects
Some of Repo
commands return parsed descriptions of git objects:
- class yuio.git.Commit(hash: str, author: str, author_email: str, author_date: datetime, committer: str, committer_email: str, committer_date: datetime, title: str, body: str, orig_ref: Optional[str] = None)[source]
Commit description.
- author_date: datetime.datetime
Author time.
- committer_date: datetime.datetime
Committer time.
- class yuio.git.Status(commit: str, branch: ~typing.Optional[str] = None, upstream: ~typing.Optional[str] = None, ahead: ~typing.Optional[int] = None, behind: ~typing.Optional[int] = None, has_tracked_changes: bool = False, has_untracked_changes: bool = False, changes: ~typing.List[~yuio.git.FileStatus] = <factory>)[source]
Status of a working copy.
- changes: List[yuio.git.FileStatus]
List of changed files, both tracked and untracked.
- class yuio.git.FileStatus(path: Path, path_from: Optional[Path] = None, staged: Modification = Modification.UNMODIFIED, tree: Modification = Modification.UNMODIFIED)[source]
Status of a changed file.
- path: pathlib.Path
Path of the file.
- path_from: Optional[pathlib.Path] = None
If file was moved, contains path where it was moved from.
- staged: yuio.git.Modification = '.'
File modification in the index (staged).
- tree: yuio.git.Modification = '.'
File modification in the tree (unstaged).
- class yuio.git.Modification(value)[source]
For changed file, what modification was applied to it.
- UNMODIFIED = '.'
File wasn’t changed.
- MODIFIED = 'M'
File was changed.
- ADDED = 'A'
File was created.
- DELETED = 'D'
File was deleted.
- RENAMED = 'R'
File was renamed (and possibly changed).
- COPIED = 'C'
File was copied (and possibly changed).
- UPDATED = 'U'
File with conflicts is unmerged.
- IGNORED = '?'
File is in
.gitignore
.
- UNTRACKED = '!'
File was created but not yet added to git, i.e. not staged.
Parsing git refs
When you need to query a git ref from a user, RefParser
will ensure
that the ref points to a valid git object: