Skip to content

Commit 1a44769

Browse files
committed
Add ability to set extra git options in config file
This adds the ability to define git_extra_options which are git options to be passed through to the actual git command, with the specific intention of allowing http ssl verification disabling but there's no reason not to allow other options should they be warranted Signed-off-by: John 'Warthog9' Hawley <[email protected]>
1 parent d181306 commit 1a44769

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

build_node/build_node_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ class BuildNodeConfig(BaseConfig):
6363
Git repositories cache locks directory.
6464
git_repos_cache_dir : str
6565
Git repositories cache directory.
66+
git_extra_options : list of str
67+
Git options to be passed to underlying git commands
6668
sentry_dsn : str
6769
Client key to send build data to Sentry.
6870
pulp_host : str
@@ -99,6 +101,7 @@ def __init__(self, config_file=None, **cmd_args):
99101
# compatibility
100102
'git_cache_locks_dir': '/srv/alternatives/git_repos_cache/locks/',
101103
'git_repos_cache_dir': '/srv/alternatives/git_repos_cache/',
104+
'git_extra_options': None,
102105
'native_support': DEFAULT_NATIVE_BUILDING,
103106
'arm64_support': DEFAULT_ARM64_BUILDING,
104107
'arm32_support': DEFAULT_ARM32_BUILDING,
@@ -132,6 +135,7 @@ def __init__(self, config_file=None, **cmd_args):
132135
'working_dir': {'type': 'string', 'required': True},
133136
'git_cache_locks_dir': {'type': 'string', 'required': True},
134137
'git_repos_cache_dir': {'type': 'string', 'required': True},
138+
'git_extra_options': {'type': 'list', 'required': False, 'nullable': True},
135139
'native_support': {'type': 'boolean', 'default': True},
136140
'arm64_support': {'type': 'boolean', 'default': False},
137141
'arm32_support': {'type': 'boolean', 'default': False},

build_node/builders/base_builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def checkout_git_sources(self, git_sources_dir, ref):
112112
with MirroredGitRepo(
113113
ref.url, self.config.git_repos_cache_dir,
114114
self.config.git_cache_locks_dir,
115-
timeout=600) as cached_repo:
115+
timeout=600, git_command_extras=self.config.git_extra_options) as cached_repo:
116116
repo = cached_repo.clone_to(git_sources_dir)
117117
repo.checkout(ref.git_ref)
118118
self.__log_commit_id(git_sources_dir)

build_node/utils/git_utils.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ class GitCacheError(Exception):
739739
class MirroredGitRepo(object):
740740

741741
def __init__(self, repo_url, repos_dir, locks_dir, timeout=60,
742-
logger=None):
742+
git_command_extras=None, logger=None):
743743
"""
744744
@type repo_url: str or unicode
745745
@param repo_url: Git repository URL.
@@ -750,6 +750,8 @@ def __init__(self, repo_url, repos_dir, locks_dir, timeout=60,
750750
need the timeout.
751751
@type logger: logging.Logger
752752
@param logger: Logger instance to use (optional).
753+
@type git_command_extras: list of str
754+
@param git_command_extras: List of extra command line options to be passed to git (optional)
753755
"""
754756
if not isinstance(repo_url, str):
755757
raise ValueError("repo_url must be instance of str or unicode")
@@ -782,6 +784,8 @@ def __init__(self, repo_url, repos_dir, locks_dir, timeout=60,
782784
"{0}.lock".format(self.__repo_hash))
783785
self.__fd = None
784786

787+
self.__git_command_extras = git_command_extras
788+
785789
def clone_to(self, target_dir, branch=None):
786790
"""
787791
Clones cached git repository to the specified directory.
@@ -839,7 +843,7 @@ def __enter__(self):
839843
raise e
840844
return self
841845

842-
def __clone_repo(self, repo_url, target_dir, mirror=False, branch=None):
846+
def __clone_repo(self, repo_url, target_dir, mirror=False, branch=None, git_opts=None):
843847
"""
844848
Clones git repository to the specified directory.
845849
@@ -849,10 +853,16 @@ def __clone_repo(self, repo_url, target_dir, mirror=False, branch=None):
849853
@param target_dir: The name of a new directory to clone into.
850854
@type mirror: bool
851855
@param mirror: Set up a mirror of the source repository if True.
856+
@type git_opts: list of str
857+
@param git_opts: list of explicit options to append to git command (optional)
852858
853859
@raise GitCacheError: If git-clone execution failed.
854860
"""
855861
cmd = ["git", "clone"]
862+
if self.__git_command_extras is not None:
863+
cmd.extend( self.__git_command_extras )
864+
if git_opts is not None:
865+
cmd.extend( git_opts )
856866
if mirror:
857867
cmd.append("--mirror")
858868
cmd.extend((repo_url, target_dir))

0 commit comments

Comments
 (0)