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:
Robin Roth 2017-02-21 14:22:29 +01:00 committed by Toshio Kuratomi
parent fc0ae5ee6b
commit 3afc993f3a
2 changed files with 32 additions and 5 deletions

View file

@ -423,12 +423,17 @@ def clone(git_path, module, repo, dest, remote, depth, version, bare,
else:
cmd.extend([ '--origin', remote ])
if depth:
if version == 'HEAD' \
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)
if version == 'HEAD' or refspec:
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:
cmd.extend([ '--reference', str(reference) ])
cmd.extend([ repo, dest ])