Commit 79f3c56d by Tom Berger

Add a `recursive` option to the git command.

Make it possible to clone without submodules by setting
recursive to no. Default is yes, so no change is needed
in existing plays.
parent 56e3d312
......@@ -95,6 +95,15 @@ options:
description:
- if C(yes), repository will be created as a bare repo, otherwise
it will be a standard repo with a workspace.
recursive:
required: false
default: "yes"
choices: [ "yes", "no" ]
version_added: "1.5"
description:
- if C(no), repository will be cloned without the --recursive
option, skipping sub-modules.
notes:
- "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,
......@@ -125,7 +134,8 @@ def get_version(git_path, dest, ref="HEAD"):
sha = os.popen(cmd).read().rstrip("\n")
return sha
def clone(git_path, module, repo, dest, remote, depth, version, bare, reference):
def clone(git_path, module, repo, dest, remote, depth, version, bare,
reference, recursive):
''' makes a new git repo if it does not already exist '''
dest_dirname = os.path.dirname(dest)
try:
......@@ -137,7 +147,9 @@ def clone(git_path, module, repo, dest, remote, depth, version, bare, reference)
if bare:
cmd.append('--bare')
else:
cmd.extend([ '--origin', remote, '--recursive' ])
cmd.extend([ '--origin', remote ])
if recursive:
cmd.extend([ '--recursive' ])
if is_remote_branch(git_path, module, dest, repo, version) \
or is_remote_tag(git_path, module, dest, repo, version):
cmd.extend([ '--branch', version ])
......@@ -354,6 +366,7 @@ def main():
update=dict(default='yes', type='bool'),
executable=dict(default=None),
bare=dict(default='no', type='bool'),
recursive=dict(default='yes', type='bool'),
),
supports_check_mode=True
)
......@@ -368,6 +381,7 @@ def main():
bare = module.params['bare']
reference = module.params['reference']
git_path = module.params['executable'] or module.get_bin_path('git', True)
recursive = module.params['recursive']
if bare:
gitconfig = os.path.join(dest, 'config')
......@@ -384,7 +398,8 @@ def main():
if module.check_mode:
remote_head = get_remote_head(git_path, module, dest, version, repo)
module.exit_json(changed=True, before=before, after=remote_head)
clone(git_path, module, repo, dest, remote, depth, version, bare, reference)
clone(git_path, module, repo, dest, remote, depth, version, bare,
reference, recursive)
elif not update:
# Just return having found a repo already in the dest path
# this does no checking that the repo is the actual repo
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment