git: Check if version is populated or not (#82173)

Before usage check if the git version is populated or not.

Fixes: #72321

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
pull/83199/head
Abhijeet Kasurde 7 months ago committed by GitHub
parent 2816922cd6
commit f4bbd75a3c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,3 @@
---
bugfixes:
- git - check if git version is available or not before using it for comparison (https://github.com/ansible/ansible/issues/72321).

@ -500,7 +500,7 @@ def set_git_ssh_env(key_file, ssh_opts, git_version, module):
# older than 2.3 does not know how to use git_ssh_command, # older than 2.3 does not know how to use git_ssh_command,
# so we force it into get_ssh var # so we force it into get_ssh var
# https://github.com/gitster/git/commit/09d60d785c68c8fa65094ecbe46fbc2a38d0fc1f # https://github.com/gitster/git/commit/09d60d785c68c8fa65094ecbe46fbc2a38d0fc1f
if git_version < LooseVersion('2.3.0'): if git_version is not None and git_version < LooseVersion('2.3.0'):
# for use in wrapper # for use in wrapper
os.environ["GIT_SSH_OPTS"] = ssh_opts os.environ["GIT_SSH_OPTS"] = ssh_opts
@ -913,7 +913,7 @@ def fetch(git_path, module, repo, dest, version, remote, depth, bare, refspec, g
refspecs = ['+refs/heads/*:refs/heads/*', '+refs/tags/*:refs/tags/*'] refspecs = ['+refs/heads/*:refs/heads/*', '+refs/tags/*:refs/tags/*']
else: else:
# ensure all tags are fetched # ensure all tags are fetched
if git_version_used >= LooseVersion('1.9'): if git_version_used is not None and git_version_used >= LooseVersion('1.9'):
fetch_cmd.append('--tags') fetch_cmd.append('--tags')
else: else:
# old git versions have a bug in --tags that prevents updating existing tags # old git versions have a bug in --tags that prevents updating existing tags
@ -1308,7 +1308,7 @@ def main():
# GIT_SSH=<path> as an environment variable, might create sh wrapper script for older versions. # GIT_SSH=<path> as an environment variable, might create sh wrapper script for older versions.
set_git_ssh_env(key_file, ssh_opts, git_version_used, module) set_git_ssh_env(key_file, ssh_opts, git_version_used, module)
if depth is not None and git_version_used < LooseVersion('1.9.1'): if depth is not None and git_version_used is not None and git_version_used < LooseVersion('1.9.1'):
module.warn("git version is too old to fully support the depth argument. Falling back to full checkouts.") module.warn("git version is too old to fully support the depth argument. Falling back to full checkouts.")
depth = None depth = None

Loading…
Cancel
Save