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: int | None =
None
) Object [source]¶ Uses
git
to fetch the full SHA hash of the current 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: int | None =
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 to get the desired commit’s SHA hash instead.
- Returns:¶
A
str
representing the commit’s SHA hash.
-
cpp_linter.git.get_diff(parents: int =
1
) Diff [source]¶ Retrieve the diff info about a specified commit.
- 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
FileFilter
object.- lines_changed_only: int¶
A value that dictates what file changes to focus on.
- Returns:¶
A
list
ofFileObj
describing information about the files changed.Note
Deleted files are omitted because we only want to analyze updates.