craft_parts.sources.git_source module

Implement the git source handler.

class craft_parts.sources.git_source.GitSource(source, part_src_dir, *, cache_dir, project_dirs, source_tag=None, source_commit=None, source_depth=None, source_branch=None, source_checksum=None, source_submodules=None, ignore_patterns=None)[source]

Bases: SourceHandler

The git source handler.

Retrieve part sources from a git repository. Branch, depth, commit and tag can be specified using part properties source-branch, source-depth, source-commit`, source-tag, and source-submodules.

  • source (str) –

  • part_src_dir (Path) –

  • cache_dir (Path) –

  • project_dirs (ProjectDirs) –

  • source_tag (Optional[str]) –

  • source_commit (Optional[str]) –

  • source_depth (Optional[int]) –

  • source_branch (Optional[str]) –

  • source_checksum (Optional[str]) –

  • source_submodules (Optional[List[str]]) –

  • ignore_patterns (Optional[List[str]]) –

classmethod check_command_installed()[source]

Check if git is installed.

Return type:


classmethod generate_version(*, part_src_dir=None)[source]

Return the latest git tag from PWD or defined part_src_dir.

The output depends on the use of annotated tags and will return something like: ‘2.28+git.10.abcdef’ where ‘2.28 is the tag, ‘+git’ indicates there are commits ahead of the tag, in this case it is ‘10’ and the latest commit hash begins with ‘abcdef’. If there are no tags or the revision cannot be determined, this will return 0 as the tag and only the commit hash of the latest commit.


part_src_dir (Optional[Path]) –

Return type:



Verify whether the git repository is on the local filesystem.

Return type:



Retrieve the local or remote source files.

Return type:


classmethod version()[source]

Get git version information.

Return type: