From 016c5aee944227e07f244839d3d518a3b33a82c8 Mon Sep 17 00:00:00 2001 From: SerenaFeng Date: Fri, 23 Dec 2016 14:32:52 +0800 Subject: bugfix: get git branch failed when only 'git fetch' is provided File "/usr/local/lib/python2.7/dist-packages/functest/cli/commands/cli_env.py", line 58, in show branch = repo.head.reference File "/usr/local/lib/python2.7/dist-packages/git/refs/symbolic.py", line 258, in _get_reference raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha)) TypeError: HEAD is a detached symbolic reference as it points to '2632ba86dd920267455ee10154b9e2ce4695a889' JIRA: FUNCTEST-673 Change-Id: I2306dde254710d7d0e8a3529a19e3d8fdb6e5b02 Signed-off-by: SerenaFeng --- functest/cli/commands/cli_env.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'functest/cli') diff --git a/functest/cli/commands/cli_env.py b/functest/cli/commands/cli_env.py index 5228c3e80..9423631bf 100644 --- a/functest/cli/commands/cli_env.py +++ b/functest/cli/commands/cli_env.py @@ -48,10 +48,14 @@ class CliEnv: installer_info = ("%s, %s" % (install_type, installer_ip)) scenario = _get_value(CONST.DEPLOY_SCENARIO) node = _get_value(CONST.NODE_NAME) - repo = git.Repo(CONST.dir_repo_functest) - branch = repo.head.reference - git_branch = branch.name - git_hash = branch.commit.hexsha + repo_h = git.Repo(CONST.dir_repo_functest).head + if repo_h.is_detached: + git_branch = 'detached from FETCH_HEAD' + git_hash = repo_h.commit.hexsha + else: + branch = repo_h.reference + git_branch = branch.name + git_hash = branch.commit.hexsha is_debug = _get_value(CONST.CI_DEBUG, 'false') build_tag = CONST.BUILD_TAG if build_tag is not None: -- cgit 1.2.3-korg