From 2d5b942ffeed15da78f632e63f26617ea790d6ef Mon Sep 17 00:00:00 2001 From: Petr Svoboda Date: Thu, 1 Aug 2013 11:59:06 +0200 Subject: [PATCH 1/2] Fix traceback in git module when version checkout fails "UnboundLocalError: local variable 'branch' referenced before assignment" is raised in git, line 282, in switch_version. Exception is raised when version is not branch and version checkout fails. E.g. when version is nonexistant commit. --- library/source_control/git | 1 + 1 file changed, 1 insertion(+) diff --git a/library/source_control/git b/library/source_control/git index a7417bf693..20e204c6ad 100644 --- a/library/source_control/git +++ b/library/source_control/git @@ -271,6 +271,7 @@ def switch_version(git_path, module, dest, remote, version): cmd = "%s reset --hard %s/%s" % (git_path, remote, version) else: cmd = "%s checkout --force %s" % (git_path, version) + branch = version else: branch = get_head_branch(git_path, module, dest, remote) (rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, branch)) From d9576b3529c117e1e26b99cb496cb17ee1dbc634 Mon Sep 17 00:00:00 2001 From: Petr Svoboda Date: Fri, 2 Aug 2013 12:53:08 +0200 Subject: [PATCH 2/2] Tidy up fix of git module traceback --- library/source_control/git | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/library/source_control/git b/library/source_control/git index 20e204c6ad..3bc3324eec 100644 --- a/library/source_control/git +++ b/library/source_control/git @@ -271,7 +271,6 @@ def switch_version(git_path, module, dest, remote, version): cmd = "%s reset --hard %s/%s" % (git_path, remote, version) else: cmd = "%s checkout --force %s" % (git_path, version) - branch = version else: branch = get_head_branch(git_path, module, dest, remote) (rc, out, err) = module.run_command("%s checkout --force %s" % (git_path, branch)) @@ -280,7 +279,10 @@ def switch_version(git_path, module, dest, remote, version): cmd = "%s reset --hard %s" % (git_path, remote) (rc, out1, err1) = module.run_command(cmd) if rc != 0: - module.fail_json(msg="Failed to checkout branch %s" % (branch)) + if version != 'HEAD': + module.fail_json(msg="Failed to checkout %s" % (version)) + else: + module.fail_json(msg="Failed to checkout branch %s" % (branch)) (rc, out2, err2) = submodule_update(git_path, module, dest) return (rc, out1 + out2, err1 + err2)