diff options
author | Toshio Kuratomi <a.badger@gmail.com> | 2017-03-02 14:19:46 -0800 |
---|---|---|
committer | Toshio Kuratomi <a.badger@gmail.com> | 2017-03-02 14:19:46 -0800 |
commit | 9b325be734daf28b194de11c3418136b56ede9ac (patch) | |
tree | 9a3b5891343f7af7e9c9f120069e0fd2a8ae72fd | |
parent | 2f9a2763330c460a4637bc21138fe21e3159aa98 (diff) | |
download | ansible-modules-core-9b325be734daf28b194de11c3418136b56ede9ac.tar.gz |
* Fixes #21316
* 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
(cherry picked from 3afc993f3a5774f61b6a9b6ed4ea1136821f91ef)
-rw-r--r-- | source_control/git.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/source_control/git.py b/source_control/git.py index c3b74057..55bed66e 100644 --- a/source_control/git.py +++ b/source_control/git.py @@ -380,12 +380,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 opject 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 opject 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 ]) |