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
Return actual names of blobs and trees.
Get local/remote branches (while excluding remote HEADs).
Return unreachable commits not in the reflog.
Return name of branch pointed to by HEAD.
Return SHA of the commit pointed to by local HEAD.
Return the root node of the DAG for git notes.
Return the SHA and type of all git objects (in one string).
Return heads of pull-requests.
Return symbolic references of remote heads.
Return list of remotes.
Return stash IDs and their associated SHAs.
Return parsed info for all annotated and lightweight tags.
Detect if a local branch is tracking a remote one.
Return children of a tree object.
Read the file associated with an object.
Return output of
git-rev-list
.Return set of commit SHA in the range defined by
range_expr
.Return a set of SHA corresponding to a list of descriptors.
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_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_remote_heads_sym_ref(remotes: list[str]) dict[str, str] [source]¶
Return symbolic references of remote heads.
- 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 (seeCMD_TAGS_INFO
) used in this function doesn’t return deleted annotated tags. They are handled separately inGitInspector._get_objects_info_parsed()
(note that their SHA is included in the output ofGitCommand.get_objects_sha_kind()
).Note¶
The
--python
flag (seeCMD_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 asgit 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 bemain..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.