1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

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
This commit is contained in:
Robin Roth 2016-10-21 16:48:21 +02:00 committed by Matt Clay
parent 3dda38a90f
commit 5446e6639f

View file

@ -756,11 +756,12 @@ def switch_version(git_path, module, dest, remote, version, verify_commit, depth
else: else:
# FIXME check for local_branch first, should have been fetched already # FIXME check for local_branch first, should have been fetched already
if is_remote_branch(git_path, module, dest, remote, version): if is_remote_branch(git_path, module, dest, remote, version):
if not is_local_branch(git_path, module, dest, version): if depth and not is_local_branch(git_path, module, dest, version):
if depth:
# git clone --depth implies --single-branch, which makes # git clone --depth implies --single-branch, which makes
# the checkout fail if the version changes # 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) set_remote_branch(git_path, module, dest, remote, version, depth)
if not is_local_branch(git_path, module, dest, version):
cmd = "%s checkout --track -b %s %s/%s" % (git_path, version, remote, version) cmd = "%s checkout --track -b %s %s/%s" % (git_path, version, remote, version)
else: else:
(rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, version), cwd=dest) (rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, version), cwd=dest)