1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fixes #6750 Check git subcommand for --remote and expose errors

This commit is contained in:
James Tanner 2014-04-03 15:21:54 -04:00
parent b660062801
commit cca028187e

View file

@ -151,6 +151,34 @@ EXAMPLES = '''
import re import re
import tempfile import tempfile
def get_submodule_update_params(module, git_path, cwd):
#or: git submodule [--quiet] update [--init] [-N|--no-fetch]
#[-f|--force] [--rebase] [--reference <repository>] [--merge]
#[--recursive] [--] [<path>...]
params = []
# run a bad submodule command to get valid params
cmd = "%s submodule update -" % (git_path)
rc, stdout, stderr = module.run_command(cmd, cwd=cwd)
lines = stderr.split('\n')
update_line = None
for line in lines:
if 'git submodule [--quiet] update ' in line:
update_line = line
if update_line:
update_line = update_line.replace('[','')
update_line = update_line.replace(']','')
update_line = update_line.replace('|',' ')
parts = shlex.split(update_line)
for part in parts:
if part.startswith('--'):
part = part.replace('--', '')
params.append(part)
return params
def write_ssh_wrapper(): def write_ssh_wrapper():
module_dir = get_module_path() module_dir = get_module_path()
fd, wrapper_path = tempfile.mkstemp(prefix=module_dir + '/') fd, wrapper_path = tempfile.mkstemp(prefix=module_dir + '/')
@ -383,15 +411,22 @@ def fetch(git_path, module, repo, dest, version, remote, bare):
def submodule_update(git_path, module, dest): def submodule_update(git_path, module, dest):
''' init and update any submodules ''' ''' init and update any submodules '''
# get the valid submodule params
params = get_submodule_update_params(module, git_path, dest)
# skip submodule commands if .gitmodules is not present # skip submodule commands if .gitmodules is not present
if not os.path.exists(os.path.join(dest, '.gitmodules')): if not os.path.exists(os.path.join(dest, '.gitmodules')):
return (0, '', '') return (0, '', '')
cmd = [ git_path, 'submodule', 'sync' ] cmd = [ git_path, 'submodule', 'sync' ]
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest) (rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ,'--remote' ] if 'remote' in params:
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ,'--remote' ]
else:
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ]
(rc, out, err) = module.run_command(cmd, cwd=dest) (rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0: if rc != 0:
module.fail_json(msg="Failed to init/update submodules") module.fail_json(msg="Failed to init/update submodules: %s" % out + err)
return (rc, out, err) return (rc, out, err)
def switch_version(git_path, module, dest, remote, version): def switch_version(git_path, module, dest, remote, version):