mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-05-30 04:49:09 -07:00
git: If force=yes, apply --force to submodule updates to overwrite local changes (#4415)
Fixes #238
This commit is contained in:
parent
76260d3aa8
commit
c60954605b
1 changed files with 4 additions and 2 deletions
|
@ -661,7 +661,7 @@ def submodules_fetch(git_path, module, remote, track_submodules, dest):
|
||||||
break
|
break
|
||||||
return changed
|
return changed
|
||||||
|
|
||||||
def submodule_update(git_path, module, dest, track_submodules):
|
def submodule_update(git_path, module, dest, track_submodules, force=False):
|
||||||
''' init and update any submodules '''
|
''' init and update any submodules '''
|
||||||
|
|
||||||
# get the valid submodule params
|
# get the valid submodule params
|
||||||
|
@ -676,6 +676,8 @@ def submodule_update(git_path, module, dest, track_submodules):
|
||||||
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ,'--remote' ]
|
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ,'--remote' ]
|
||||||
else:
|
else:
|
||||||
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ]
|
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ]
|
||||||
|
if force:
|
||||||
|
cmd.append('--force')
|
||||||
(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: %s" % out + err)
|
module.fail_json(msg="Failed to init/update submodules: %s" % out + err)
|
||||||
|
@ -938,7 +940,7 @@ def main():
|
||||||
|
|
||||||
if submodules_updated:
|
if submodules_updated:
|
||||||
# Switch to version specified
|
# Switch to version specified
|
||||||
submodule_update(git_path, module, dest, track_submodules)
|
submodule_update(git_path, module, dest, track_submodules, force=force)
|
||||||
|
|
||||||
# determine if we changed anything
|
# determine if we changed anything
|
||||||
result['after'] = get_version(module, git_path, dest)
|
result['after'] = get_version(module, git_path, dest)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue