|
|
|
@ -151,6 +151,34 @@ EXAMPLES = '''
|
|
|
|
|
import re
|
|
|
|
|
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():
|
|
|
|
|
module_dir = get_module_path()
|
|
|
|
|
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):
|
|
|
|
|
''' 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
|
|
|
|
|
if not os.path.exists(os.path.join(dest, '.gitmodules')):
|
|
|
|
|
return (0, '', '')
|
|
|
|
|
cmd = [ git_path, 'submodule', 'sync' ]
|
|
|
|
|
(rc, out, err) = module.run_command(cmd, check_rc=True, cwd=dest)
|
|
|
|
|
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)
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
|
def switch_version(git_path, module, dest, remote, version):
|
|
|
|
|