|
|
|
|
@ -163,6 +163,12 @@ options:
|
|
|
|
|
all git servers support git archive.
|
|
|
|
|
version_added: "2.4"
|
|
|
|
|
|
|
|
|
|
archive_prefix:
|
|
|
|
|
description:
|
|
|
|
|
- Specify a prefix to add to each file path in archive. Requires C(archive) to be specified.
|
|
|
|
|
version_added: "2.10"
|
|
|
|
|
type: str
|
|
|
|
|
|
|
|
|
|
separate_git_dir:
|
|
|
|
|
description:
|
|
|
|
|
- The path to place the cloned repository. If specified, Git repository
|
|
|
|
|
@ -972,10 +978,12 @@ def git_version(git_path, module):
|
|
|
|
|
return LooseVersion(rematch.groups()[0])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def git_archive(git_path, module, dest, archive, archive_fmt, version):
|
|
|
|
|
def git_archive(git_path, module, dest, archive, archive_fmt, archive_prefix, version):
|
|
|
|
|
""" Create git archive in given source directory """
|
|
|
|
|
cmd = "%s archive --format=%s --output=%s %s" \
|
|
|
|
|
% (git_path, archive_fmt, archive, version)
|
|
|
|
|
cmd = [git_path, 'archive', '--format', archive_fmt, '--output', archive, version]
|
|
|
|
|
if archive_prefix is not None:
|
|
|
|
|
cmd.insert(-1, '--prefix')
|
|
|
|
|
cmd.insert(-1, archive_prefix)
|
|
|
|
|
(rc, out, err) = module.run_command(cmd, cwd=dest)
|
|
|
|
|
if rc != 0:
|
|
|
|
|
module.fail_json(msg="Failed to perform archive operation",
|
|
|
|
|
@ -985,7 +993,7 @@ def git_archive(git_path, module, dest, archive, archive_fmt, version):
|
|
|
|
|
return rc, out, err
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_archive(git_path, module, dest, archive, version, repo, result):
|
|
|
|
|
def create_archive(git_path, module, dest, archive, archive_prefix, version, repo, result):
|
|
|
|
|
""" Helper function for creating archive using git_archive """
|
|
|
|
|
all_archive_fmt = {'.zip': 'zip', '.gz': 'tar.gz', '.tar': 'tar',
|
|
|
|
|
'.tgz': 'tgz'}
|
|
|
|
|
@ -1007,7 +1015,7 @@ def create_archive(git_path, module, dest, archive, version, repo, result):
|
|
|
|
|
tempdir = tempfile.mkdtemp()
|
|
|
|
|
new_archive_dest = os.path.join(tempdir, repo_name)
|
|
|
|
|
new_archive = new_archive_dest + '.' + archive_fmt
|
|
|
|
|
git_archive(git_path, module, dest, new_archive, archive_fmt, version)
|
|
|
|
|
git_archive(git_path, module, dest, new_archive, archive_fmt, archive_prefix, version)
|
|
|
|
|
|
|
|
|
|
# filecmp is supposed to be efficient than md5sum checksum
|
|
|
|
|
if filecmp.cmp(new_archive, archive):
|
|
|
|
|
@ -1029,7 +1037,7 @@ def create_archive(git_path, module, dest, archive, version, repo, result):
|
|
|
|
|
% to_text(e))
|
|
|
|
|
else:
|
|
|
|
|
# Perform archive from local directory
|
|
|
|
|
git_archive(git_path, module, dest, archive, archive_fmt, version)
|
|
|
|
|
git_archive(git_path, module, dest, archive, archive_fmt, archive_prefix, version)
|
|
|
|
|
result.update(changed=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -1059,9 +1067,11 @@ def main():
|
|
|
|
|
track_submodules=dict(default='no', type='bool'),
|
|
|
|
|
umask=dict(default=None, type='raw'),
|
|
|
|
|
archive=dict(type='path'),
|
|
|
|
|
archive_prefix=dict(),
|
|
|
|
|
separate_git_dir=dict(type='path'),
|
|
|
|
|
),
|
|
|
|
|
mutually_exclusive=[('separate_git_dir', 'bare')],
|
|
|
|
|
required_by={'archive_prefix': ['archive']},
|
|
|
|
|
supports_check_mode=True
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
@ -1083,6 +1093,7 @@ def main():
|
|
|
|
|
ssh_opts = module.params['ssh_opts']
|
|
|
|
|
umask = module.params['umask']
|
|
|
|
|
archive = module.params['archive']
|
|
|
|
|
archive_prefix = module.params['archive_prefix']
|
|
|
|
|
separate_git_dir = module.params['separate_git_dir']
|
|
|
|
|
|
|
|
|
|
result = dict(changed=False, warnings=list())
|
|
|
|
|
@ -1186,7 +1197,7 @@ def main():
|
|
|
|
|
result.update(changed=True)
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
create_archive(git_path, module, dest, archive, version, repo, result)
|
|
|
|
|
create_archive(git_path, module, dest, archive, archive_prefix, version, repo, result)
|
|
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
else:
|
|
|
|
|
@ -1260,7 +1271,7 @@ def main():
|
|
|
|
|
result.update(changed=True)
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
create_archive(git_path, module, dest, archive, version, repo, result)
|
|
|
|
|
create_archive(git_path, module, dest, archive, archive_prefix, version, repo, result)
|
|
|
|
|
|
|
|
|
|
module.exit_json(**result)
|
|
|
|
|
|
|
|
|
|
|