git¶
This module uses git CLI to get commit info. It also holds some functions
related to parsing diff output into a list of changed files.
-
cpp_linter.git.get_sha(repo: Repository, parent: None | int | str =
None) Object[source]¶ Uses
gitto fetch the full SHA hash of a commit.Note
This function is only used in local development environments, not in a Continuous Integration workflow.
- Parameters:¶
- repo: Repository¶
The object representing the git repository.
- parent: None | int | str =
None¶ This parameter’s default value will fetch the SHA of the last commit. Set this parameter to the number of parent commits from the current tree’s HEAD or a valid git revision to get the desired commit’s SHA hash instead.
- Returns:¶
A
pygit2.Objectrepresenting the resolved commit.
-
cpp_linter.git.get_diff(parents: None | int | str =
None, ignore_index: bool =False) Diff[source]¶ Retrieve the diff info about a specified commit.
- Parameters:¶
- parents: None | int | str =
None¶ The commit or ref to use as the base of the diff. If set to None, and there are staged changes to be used, then it will be HEAD and the diff will consist of just the staged changes. If there are no staged changes or the index is ignored, it will be HEAD~1.
- ignore_index: bool =
False¶ Setting this flag to
truewill ignore any staged files in the index when producing a diff.
- parents: None | int | str =
- Returns:¶
A
pygit2.Diffobject representing the fetched diff.
- cpp_linter.git.parse_diff(diff_obj: Diff | str, file_filter: FileFilter, lines_changed_only: int) list[FileObj][source]¶
Parse a given diff into file objects.
- Parameters:¶
- diff_obj: Diff | str¶
The complete git diff object for an event.
- file_filter: FileFilter¶
A
FileFilterobject.- lines_changed_only: int¶
A value that dictates what file changes to focus on.
- Returns:¶
A
listofFileObjdescribing information about the files changed.Note
Deleted files are omitted because we only want to analyze additions.