git: If force=yes, apply --force to submodule updates to overwrite local changes (#4415)

Fixes #238
This commit is contained in:
jctanner 2016-08-12 18:06:02 -04:00 committed by Matt Clay
parent 76260d3aa8
commit c60954605b

View file

@ -661,7 +661,7 @@ def submodules_fetch(git_path, module, remote, track_submodules, dest):
break
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 '''
# 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' ]
else:
cmd = [ git_path, 'submodule', 'update', '--init', '--recursive' ]
if force:
cmd.append('--force')
(rc, out, err) = module.run_command(cmd, cwd=dest)
if rc != 0:
module.fail_json(msg="Failed to init/update submodules: %s" % out + err)
@ -938,7 +940,7 @@ def main():
if submodules_updated:
# 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
result['after'] = get_version(module, git_path, dest)