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
pull/18777/head
Toshio Kuratomi 10 years ago committed by Matt Clay
parent 7c8f0b99af
commit a7ff6c4cba

@ -36,9 +36,9 @@ options:
required: true required: true
description: description:
- Absolute path of where the repository should be checked out to. - Absolute path of where the repository should be checked out to.
This parameter is required, unless C(update) is set to C(no) This parameter is required, unless C(clone) is set to C(no)
This change was made in version 1.8. Prior to this version, the This change was made in version 1.8.3. Prior to this version,
C(dest) parameter was always required. the C(dest) parameter was always required.
version: version:
required: false required: false
default: "HEAD" default: "HEAD"
@ -97,6 +97,13 @@ options:
- Create a shallow clone with a history truncated to the specified - Create a shallow clone with a history truncated to the specified
number or revisions. The minimum possible value is C(1), otherwise number or revisions. The minimum possible value is C(1), otherwise
ignored. 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: update:
required: false required: false
default: "yes" default: "yes"
@ -158,7 +165,7 @@ EXAMPLES = '''
- git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello - git: repo=ssh://git@github.com/mylogin/hello.git dest=/home/mylogin/hello
# Example just ensuring the repo checkout exists # 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 import re
@ -588,6 +595,7 @@ def main():
reference=dict(default=None), reference=dict(default=None),
force=dict(default='yes', type='bool'), force=dict(default='yes', type='bool'),
depth=dict(default=None, type='int'), depth=dict(default=None, type='int'),
clone=dict(default='yes', type='bool'),
update=dict(default='yes', type='bool'), update=dict(default='yes', type='bool'),
accept_hostkey=dict(default='no', type='bool'), accept_hostkey=dict(default='no', type='bool'),
key_file=dict(default=None, required=False), key_file=dict(default=None, required=False),
@ -607,6 +615,7 @@ def main():
force = module.params['force'] force = module.params['force']
depth = module.params['depth'] depth = module.params['depth']
update = module.params['update'] update = module.params['update']
allow_clone = module.params['clone']
bare = module.params['bare'] bare = module.params['bare']
reference = module.params['reference'] reference = module.params['reference']
git_path = module.params['executable'] or module.get_bin_path('git', True) git_path = module.params['executable'] or module.get_bin_path('git', True)
@ -614,8 +623,8 @@ def main():
ssh_opts = module.params['ssh_opts'] ssh_opts = module.params['ssh_opts']
gitconfig = None gitconfig = None
if not dest and update: if not dest and allow_clone:
module.fail_json(msg="the destination directory must be specified unless update=no") module.fail_json(msg="the destination directory must be specified unless clone=no")
elif dest: elif dest:
dest = os.path.abspath(os.path.expanduser(dest)) dest = os.path.abspath(os.path.expanduser(dest))
if bare: if bare:
@ -651,11 +660,12 @@ def main():
before = None before = None
local_mods = False local_mods = False
repo_updated = None repo_updated = None
if gitconfig and not os.path.exists(gitconfig) or not gitconfig and 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 # if there is no git configuration, do a clone operation unless:
# user requested no updates or we're doing a check mode test (in # * the user requested no clone (they just want info)
# which case we do a ls-remote), otherwise clone the repo # * we're doing a check mode test
if module.check_mode or not update: # 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) remote_head = get_remote_head(git_path, module, dest, version, repo, bare)
module.exit_json(changed=True, before=before, after=remote_head) module.exit_json(changed=True, before=before, after=remote_head)
# there's no git config, so clone # there's no git config, so clone

Loading…
Cancel
Save