git_dag.git_commands.GitCommand

class git_dag.git_commands.GitCommand(path: str | Path = '.')[source]

Bases: GitCommandBase

Git commands that query the repository to process (without modifications).

Methods

get_blobs_and_trees_names

Return actual names of blobs and trees.

get_branches

Get local/remote branches (while excluding remote HEADs).

get_fsck_unreachable_commits

Return unreachable commits not in the reflog.

get_local_head_branch

Return name of branch pointed to by HEAD.

get_local_head_commit_sha

Return SHA of the commit pointed to by local HEAD.

get_notes_dag_root

Return the root node of the DAG for git notes.

get_objects_sha_kind

Return the SHA and type of all git objects (in one string).

get_prs_heads

Return heads of pull-requests.

get_remote_heads_sym_ref

Return symbolic references of remote heads.

get_remotes

Return list of remotes.

get_stash_info

Return stash IDs and their associated SHAs.

get_tags_info_parsed

Return parsed info for all annotated and lightweight tags.

local_branch_is_tracking

Detect if a local branch is tracking a remote one.

ls_tree

Return children of a tree object.

read_object_file

Read the file associated with an object.

rev_list

Return output of git-rev-list.

rev_list_range

Return set of commit SHA in the range defined by range_expr.

rev_parse_descriptors

Return a set of SHA corresponding to a list of descriptors.

run_general

Run a general command.

get_blobs_and_trees_names(trees_info: dict[str, list[str]]) dict[str, str][source]

Return actual names of blobs and trees.

Note

Based on https://stackoverflow.com/a/25954360.

Note

A tree object might have no name – this happens when a repository has no directories (note that a commit always has an associated tree object) or when a tree object is created manually (without a commit). Sometimes a blob has no name, e.g., when it are created manually (git hash-object -w) or it is not referenced by a tree object.

get_branches(remotes: list[str]) dict[str, dict[str, str]][source]

Get local/remote branches (while excluding remote HEADs).

get_fsck_unreachable_commits() list[str][source]

Return unreachable commits not in the reflog.

get_local_head_branch() str | None[source]

Return name of branch pointed to by HEAD.

get_local_head_commit_sha() str[source]

Return SHA of the commit pointed to by local HEAD.

get_notes_dag_root() dict[str, str] | None[source]

Return the root node of the DAG for git notes.

get_objects_sha_kind() list[str][source]

Return the SHA and type of all git objects (in one string).

Note

Unreachable commits (and deleted annotated tags) are included as well.

Note

The --unordered flag is used because ordering by SHA is not necessary.

get_prs_heads() dict[str, str][source]

Return heads of pull-requests.

get_remote_heads_sym_ref(remotes: list[str]) dict[str, str][source]

Return symbolic references of remote heads.

get_remotes() list[str][source]

Return list of remotes.

get_stash_info() list[str] | None[source]

Return stash IDs and their associated SHAs.

get_tags_info_parsed() dict[str, dict[str, dict[str, str]]][source]

Return parsed info for all annotated and lightweight tags.

Note

The git for-each-ref ... command (see CMD_TAGS_INFO) used in this function doesn’t return deleted annotated tags. They are handled separately in GitInspector._get_objects_info_parsed() (note that their SHA is included in the output of GitCommand.get_objects_sha_kind()).

Note

The --python flag (see CMD_TAGS_INFO) forms groups delimited by '...' which makes them easy to split and parse. On the flip-side, we have to decode escapes of escapes while preserving unicode characters. Note that if the message contains \n-s (i.e., one backlash), they would appear as \\\\n (four backlashes).

local_branch_is_tracking(local_branch_sha: str) str | None[source]

Detect if a local branch is tracking a remote one.

ls_tree(sha: str) list[str][source]

Return children of a tree object.

Note

The default output of git ls-tree SHA is the same as git cat-file -p SHA. Maybe I should use the --object-only flag.

read_object_file(sha: str) list[str][source]

Read the file associated with an object.

Note

It is quite slow if all objects are to be read like this (-p stands for pretty-print).

rev_list(args: str) str[source]

Return output of git-rev-list.

Note

The --all flag doesn’t imply all commits but all commits reachable from any reference.

rev_list_range(range_expr: str | None) list[str] | None[source]

Return set of commit SHA in the range defined by range_expr.

Note

For example range_expr could be main..feature.

rev_parse_descriptors(descriptors: list[str] | None) list[str] | None[source]

Return a set of SHA corresponding to a list of descriptors.

Note

A descriptor can be e.g., HEAD, main, a truncated SHA, etc.

static run_general(command: str, env: dict[str, str] | None = None, encoding: str = 'utf-8', expected_stderr: str | None = None) str

Run a general command.