summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2014-12-17 13:36:19 -0800
committerJames Cammarata <jimi@sngx.net>2015-02-17 14:41:17 -0600
commit2919abf6c03095ddf986227215ff39c57b2c8cdb (patch)
tree32eb8f48023f9d1c2c5264cf894c086c5dfe5fa3
parent2b50d7cf4abb9037de86f7efc40ec7f9b06f76aa (diff)
downloadansible-modules-core-2919abf6c03095ddf986227215ff39c57b2c8cdb.tar.gz
Make git's update parameter revert to its old behaviour and add new clone parameter to take its place.
Fixes #426 Fixes https://github.com/ansible/ansible/issues/8630
-rw-r--r--source_control/git.py32
1 files changed, 21 insertions, 11 deletions
diff --git a/source_control/git.py b/source_control/git.py
index 6b04d09c..f4c4996d 100644
--- a/source_control/git.py
+++ b/source_control/git.py
@@ -36,9 +36,9 @@ options:
required: true
description:
- Absolute path of where the repository should be checked out to.
- This parameter is required, unless C(update) is set to C(no)
- This change was made in version 1.8. Prior to this version, the
- C(dest) parameter was always required.
+ This parameter is required, unless C(clone) is set to C(no)
+ This change was made in version 1.8.3. Prior to this version,
+ the C(dest) parameter was always required.
version:
required: false
default: "HEAD"
@@ -97,6 +97,13 @@ options:
- Create a shallow clone with a history truncated to the specified
number or revisions. The minimum possible value is C(1), otherwise
ignored.
+ clone:
+ required: false
+ default: "yes"
+ choices: [ "yes", "no" ]
+ version_added: "1.8.3"
+ description:
+ - If C(no), do not clone the repository if it does not exist locally
update:
required: false
default: "yes"
@@ -158,7 +165,7 @@ EXAMPLES = '''
- git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello
# Example just ensuring the repo checkout exists
-- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout update=no
+- git: repo=git://foosball.example.org/path/to/repo.git dest=/srv/checkout clone=no update=no
'''
import re
@@ -586,6 +593,7 @@ def main():
reference=dict(default=None),
force=dict(default='yes', type='bool'),
depth=dict(default=None, type='int'),
+ clone=dict(default='yes', type='bool'),
update=dict(default='yes', type='bool'),
accept_hostkey=dict(default='no', type='bool'),
key_file=dict(default=None, required=False),
@@ -605,6 +613,7 @@ def main():
force = module.params['force']
depth = module.params['depth']
update = module.params['update']
+ allow_clone = module.params['clone']
bare = module.params['bare']
reference = module.params['reference']
git_path = module.params['executable'] or module.get_bin_path('git', True)
@@ -612,8 +621,8 @@ def main():
ssh_opts = module.params['ssh_opts']
gitconfig = None
- if not dest and update:
- module.fail_json(msg="the destination directory must be specified unless update=no")
+ if not dest and allow_clone:
+ module.fail_json(msg="the destination directory must be specified unless clone=no")
elif dest:
dest = os.path.abspath(os.path.expanduser(dest))
if bare:
@@ -645,11 +654,12 @@ def main():
before = None
local_mods = False
repo_updated = None
- if gitconfig and not os.path.exists(gitconfig) or not gitconfig and not update:
- # if there is no git configuration, do a clone operation unless the
- # user requested no updates or we're doing a check mode test (in
- # which case we do a ls-remote), otherwise clone the repo
- if module.check_mode or not update:
+ if (dest and not os.path.exists(gitconfig)) or (not dest and not allow_clone):
+ # if there is no git configuration, do a clone operation unless:
+ # * the user requested no clone (they just want info)
+ # * we're doing a check mode test
+ # In those cases we do an ls-remote
+ if module.check_mode or not allow_clone:
remote_head = get_remote_head(git_path, module, dest, version, repo, bare)
module.exit_json(changed=True, before=before, after=remote_head)
# there's no git config, so clone