From 5446e6639fb350555a418c661d13fb1fa35917a2 Mon Sep 17 00:00:00 2001 From: Robin Roth Date: Fri, 21 Oct 2016 16:48:21 +0200 Subject: [PATCH] Fix git failure for use of depth with version (#5135) * Fixes #5108 * before module fails with "fatal: A branch named 'STABLE' already exists." when depth is used on a fresh clone with a non-HEAD branch --- lib/ansible/modules/source_control/git.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/source_control/git.py b/lib/ansible/modules/source_control/git.py index 41c29a4ca4c..42ee9393a60 100644 --- a/lib/ansible/modules/source_control/git.py +++ b/lib/ansible/modules/source_control/git.py @@ -756,11 +756,12 @@ def switch_version(git_path, module, dest, remote, version, verify_commit, depth else: # FIXME check for local_branch first, should have been fetched already if is_remote_branch(git_path, module, dest, remote, version): + if depth and not is_local_branch(git_path, module, dest, version): + # git clone --depth implies --single-branch, which makes + # the checkout fail if the version changes + # fetch the remote branch, to be able to check it out next + set_remote_branch(git_path, module, dest, remote, version, depth) if not is_local_branch(git_path, module, dest, version): - if depth: - # git clone --depth implies --single-branch, which makes - # the checkout fail if the version changes - set_remote_branch(git_path, module, dest, remote, version, depth) cmd = "%s checkout --track -b %s %s/%s" % (git_path, version, remote, version) else: (rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, version), cwd=dest)