Skip to content

Commit

Permalink
Merge pull request #5910 from nasastry/git_submodule
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Richter <jarichte@redhat.com>
  • Loading branch information
richtja committed Apr 18, 2024
2 parents a6b2555 + feeb389 commit 1be8815
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions avocado/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(
commit=None,
destination_dir=None,
base_uri=None,
submodule=False,
):
"""
Instantiates a new GitRepoHelper
Expand All @@ -56,11 +57,14 @@ def __init__(
:type base_uri: string
:param base_uri: a closer, usually local, git repository url from where
to fetch content first from
:type submodule: Boolean
:param submodule: to download submodules recursively
"""
self.uri = uri
self.base_uri = base_uri
self.branch = branch
self.commit = commit
self.submodule = submodule

if destination_dir is None:
uri_basename = uri.split("/")[-1]
Expand Down Expand Up @@ -179,6 +183,13 @@ def checkout(self, branch=None, commit=None):
top_tag_desc = f"tag {top_tag}"
LOG.info("git commit ID is %s (%s)", top_commit, top_tag_desc)

def submodule_checkout(self):
"""
Performs a git checkout of submodules recursively
"""
LOG.debug("Checking out submodules")
self.git_cmd("submodule update --init --recursive")

def execute(self):
"""
Performs all steps necessary to initialize and download a git repo.
Expand All @@ -191,10 +202,18 @@ def execute(self):
self.fetch(self.base_uri)
self.fetch(self.uri)
self.checkout()
if self.submodule:
self.submodule_checkout()


def get_repo(
uri, branch="master", lbranch=None, commit=None, destination_dir=None, base_uri=None
uri,
branch="master",
lbranch=None,
commit=None,
destination_dir=None,
base_uri=None,
submodule=False,
):
"""
Utility function that retrieves a given git code repository.
Expand All @@ -212,7 +231,11 @@ def get_repo(
:type base_uri: string
:param base_uri: a closer, usually local, git repository url from where to
fetch content first from
:type submodule: Boolean
:param submodule: to download submodules recursively
"""
repo = GitRepoHelper(uri, branch, lbranch, commit, destination_dir, base_uri)
repo = GitRepoHelper(
uri, branch, lbranch, commit, destination_dir, base_uri, submodule
)
repo.execute()
return repo.destination_dir

0 comments on commit 1be8815

Please sign in to comment.