Fix git clone tag with depth=1
* Fixes #21316, add testcase based on this * Add option `--branch NAME` to git clone command in case of branch or tag in combination with depth=1 * This option should work back to at least git 1.8 and thus on all supported distributions * Provide better warning if depth is dropped
This commit is contained in:
parent
fc0ae5ee6b
commit
3afc993f3a
2 changed files with 32 additions and 5 deletions
|
@ -423,12 +423,17 @@ def clone(git_path, module, repo, dest, remote, depth, version, bare,
|
||||||
else:
|
else:
|
||||||
cmd.extend([ '--origin', remote ])
|
cmd.extend([ '--origin', remote ])
|
||||||
if depth:
|
if depth:
|
||||||
if version == 'HEAD' \
|
if version == 'HEAD' or refspec:
|
||||||
or refspec \
|
|
||||||
or is_remote_branch(git_path, module, dest, repo, version) \
|
|
||||||
or is_remote_tag(git_path, module, dest, repo, version):
|
|
||||||
# only use depth if the remote object is branch or tag (i.e. fetchable)
|
|
||||||
cmd.extend([ '--depth', str(depth) ])
|
cmd.extend([ '--depth', str(depth) ])
|
||||||
|
elif is_remote_branch(git_path, module, dest, repo, version) \
|
||||||
|
or is_remote_tag(git_path, module, dest, repo, version):
|
||||||
|
cmd.extend([ '--depth', str(depth) ])
|
||||||
|
cmd.extend(['--branch', version])
|
||||||
|
else:
|
||||||
|
# only use depth if the remote object is branch or tag (i.e. fetchable)
|
||||||
|
module.warn("Ignoring depth argument. "
|
||||||
|
"Shallow clones are only available for "
|
||||||
|
"HEAD, branches, tags or in combination with refspec.")
|
||||||
if reference:
|
if reference:
|
||||||
cmd.extend([ '--reference', str(reference) ])
|
cmd.extend([ '--reference', str(reference) ])
|
||||||
cmd.extend([ repo, dest ])
|
cmd.extend([ repo, dest ])
|
||||||
|
|
|
@ -64,6 +64,28 @@
|
||||||
args:
|
args:
|
||||||
chdir: '{{ checkout_dir }}'
|
chdir: '{{ checkout_dir }}'
|
||||||
|
|
||||||
|
- name: clear checkout_dir
|
||||||
|
file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ checkout_dir }}"
|
||||||
|
|
||||||
|
# Test for https://github.com/ansible/ansible/issues/21316
|
||||||
|
- name: Shallow clone with tag
|
||||||
|
git:
|
||||||
|
repo: 'file://{{ repo_dir|expanduser }}/shallow'
|
||||||
|
dest: '{{ checkout_dir }}'
|
||||||
|
depth: 1
|
||||||
|
version: earlytag
|
||||||
|
register: cloneold
|
||||||
|
|
||||||
|
- assert:
|
||||||
|
that: "cloneold|success"
|
||||||
|
|
||||||
|
- name: clear checkout_dir
|
||||||
|
file:
|
||||||
|
state: absent
|
||||||
|
path: "{{ checkout_dir }}"
|
||||||
|
|
||||||
|
|
||||||
# Test for https://github.com/ansible/ansible-modules-core/issues/3456
|
# Test for https://github.com/ansible/ansible-modules-core/issues/3456
|
||||||
# clone a repo with depth and version specified
|
# clone a repo with depth and version specified
|
||||||
|
|
Loading…
Reference in a new issue