Update desctiprion, parameter name, and default value as discussed in #55

pull/18777/head
Toshio Kuratomi 10 years ago committed by Matt Clay
parent 5c06bb6dca
commit 5fc463eee7

@ -129,15 +129,18 @@ options:
- if C(no), repository will be cloned without the --recursive - if C(no), repository will be cloned without the --recursive
option, skipping sub-modules. option, skipping sub-modules.
track_submodule_branches: track_submodules:
required: false required: false
default: "yes" default: "no"
choices: ["yes", "no"] choices: ["yes", "no"]
version_added: "1.7" version_added: "1.8"
description: description:
- if C(no), submodules will be updated without the --remote - if C(yes), submodules will track the latest commit on their
option, allowing submodules to be tracked by commit hash master branch (or other branch specified in .gitmodules). If
instead of branch name. C(no), submodules will be kept at the revision specified by the
main project. This is equivalent to specifying the --remote flag
to git submodule update.
notes: notes:
- "If the task seems to be hanging, first verify remote host is in C(known_hosts). - "If the task seems to be hanging, first verify remote host is in C(known_hosts).
SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt, SSH will prompt user to authorize the first contact with a remote host. To avoid this prompt,
@ -409,7 +412,7 @@ def get_head_branch(git_path, module, dest, remote, bare=False):
f.close() f.close()
return branch return branch
def fetch(git_path, module, repo, dest, version, remote, bare, track_submodule_branches): def fetch(git_path, module, repo, dest, version, remote, bare, track_submodules):
''' updates repo from remote sources ''' ''' updates repo from remote sources '''
(rc, out0, err0) = module.run_command([git_path, 'remote', 'set-url', remote, repo], cwd=dest) (rc, out0, err0) = module.run_command([git_path, 'remote', 'set-url', remote, repo], cwd=dest)
if rc != 0: if rc != 0:
@ -427,10 +430,10 @@ def fetch(git_path, module, repo, dest, version, remote, bare, track_submodule_b
(rc, out2, err2) = module.run_command("%s fetch --tags %s" % (git_path, remote), cwd=dest) (rc, out2, err2) = module.run_command("%s fetch --tags %s" % (git_path, remote), cwd=dest)
if rc != 0: if rc != 0:
module.fail_json(msg="Failed to download remote objects and refs") module.fail_json(msg="Failed to download remote objects and refs")
(rc, out3, err3) = submodule_update(git_path, module, dest, track_submodule_branches ) (rc, out3, err3) = submodule_update(git_path, module, dest, track_submodules )
return (rc, out1 + out2 + out3, err1 + err2 + err3) return (rc, out1 + out2 + out3, err1 + err2 + err3)
def submodule_update(git_path, module, dest, track_submodule_branches): def submodule_update(git_path, module, dest, track_submodules):
''' init and update any submodules ''' ''' init and update any submodules '''
# get the valid submodule params # get the valid submodule params
@ -441,7 +444,7 @@ def submodule_update(git_path, module, dest, track_submodule_branches):
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)
if 'remote' in params and track_submodule_branches: if 'remote' in params and 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' ]
@ -451,7 +454,7 @@ def submodule_update(git_path, module, dest, track_submodule_branches):
return (rc, out, err) return (rc, out, err)
def switch_version(git_path, module, dest, remote, version, recursive, track_submodule_branches): def switch_version(git_path, module, dest, remote, version, recursive, track_submodules):
cmd = '' cmd = ''
if version != 'HEAD': if version != 'HEAD':
if is_remote_branch(git_path, module, dest, remote, version): if is_remote_branch(git_path, module, dest, remote, version):
@ -477,7 +480,7 @@ def switch_version(git_path, module, dest, remote, version, recursive, track_sub
else: else:
module.fail_json(msg="Failed to checkout branch %s" % (branch)) module.fail_json(msg="Failed to checkout branch %s" % (branch))
if recursive: if recursive:
(rc, out2, err2) = submodule_update(git_path, module, dest, track_submodule_branches) (rc, out2, err2) = submodule_update(git_path, module, dest, track_submodules)
out1 += out2 out1 += out2
err1 += err1 err1 += err1
return (rc, out1, err1) return (rc, out1, err1)
@ -501,7 +504,7 @@ def main():
executable=dict(default=None), executable=dict(default=None),
bare=dict(default='no', type='bool'), bare=dict(default='no', type='bool'),
recursive=dict(default='yes', type='bool'), recursive=dict(default='yes', type='bool'),
track_submodule_branches=dict(default='yes', type='bool'), track_submodules=dict(default='no', type='bool'),
), ),
supports_check_mode=True supports_check_mode=True
) )
@ -546,7 +549,7 @@ def main():
add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey']) add_git_host_key(module, repo, accept_hostkey=module.params['accept_hostkey'])
recursive = module.params['recursive'] recursive = module.params['recursive']
track_submodule_branches = module.params['track_submodule_branches'] track_submodules = module.params['track_submodules']
rc, out, err, status = (0, None, None, None) rc, out, err, status = (0, None, None, None)
@ -592,12 +595,12 @@ def main():
module.exit_json(changed=False, before=before, after=remote_head) module.exit_json(changed=False, before=before, after=remote_head)
if module.check_mode: if module.check_mode:
module.exit_json(changed=True, before=before, after=remote_head) module.exit_json(changed=True, before=before, after=remote_head)
fetch(git_path, module, repo, dest, version, remote, bare, track_submodule_branches) fetch(git_path, module, repo, dest, version, remote, bare, track_submodules)
# switch to version specified regardless of whether # switch to version specified regardless of whether
# we cloned or pulled # we cloned or pulled
if not bare: if not bare:
switch_version(git_path, module, dest, remote, version, recursive, track_submodule_branches) switch_version(git_path, module, dest, remote, version, recursive, track_submodules)
# determine if we changed anything # determine if we changed anything
after = get_version(module, git_path, dest) after = get_version(module, git_path, dest)

Loading…
Cancel
Save