diff --git a/manic/externals_description.py b/manic/externals_description.py index 918d616e37..42755e1a52 100644 --- a/manic/externals_description.py +++ b/manic/externals_description.py @@ -193,6 +193,9 @@ def parse_submodules_desc_section(section_items, file_path): def read_gitmodules_file(root_dir, file_name): # pylint: disable=deprecated-method # Disabling this check because the method is only used for python2 + # pylint: disable=too-many-locals + # pylint: disable=too-many-branches + # pylint: disable=too-many-statements """Read a .gitmodules file and convert it to be compatible with an externals description. """ diff --git a/manic/repository_git.py b/manic/repository_git.py index f986051001..3a6a0f1716 100644 --- a/manic/repository_git.py +++ b/manic/repository_git.py @@ -109,27 +109,21 @@ def _clone_repo(self, base_dir_path, repo_dir_name, verbosity): def _current_ref(self): """Determine the *name* associated with HEAD. - If we're on a branch, then returns the branch name; otherwise, - if we're on a tag, then returns the tag name; otherwise, returns + If we're on a tag, then returns the tag name; otherwise, returns the current hash. Returns an empty string if no reference can be determined (e.g., if we're not actually in a git repository). + + If we're on a branch, then the branch name is also included in + the returned string (in addition to the tag / hash). """ ref_found = False - # If we're on a branch, then use that as the current ref - branch_found, branch_name = self._git_current_branch() - if branch_found: - current_ref = branch_name + # If we're exactly at a tag, use that as the current ref + tag_found, tag_name = self._git_current_tag() + if tag_found: + current_ref = tag_name ref_found = True - if not ref_found: - # Otherwise, if we're exactly at a tag, use that as the - # current ref - tag_found, tag_name = self._git_current_tag() - if tag_found: - current_ref = tag_name - ref_found = True - if not ref_found: # Otherwise, use current hash as the current ref hash_found, hash_name = self._git_current_hash() @@ -137,7 +131,12 @@ def _current_ref(self): current_ref = hash_name ref_found = True - if not ref_found: + if ref_found: + # If we're on a branch, include branch name in current ref + branch_found, branch_name = self._git_current_branch() + if branch_found: + current_ref = "{} (branch {})".format(current_ref, branch_name) + else: # If we still can't find a ref, return empty string. This # can happen if we're not actually in a git repo current_ref = '' diff --git a/test/test_sys_checkout.py b/test/test_sys_checkout.py index 118bee5308..9889feba0c 100644 --- a/test/test_sys_checkout.py +++ b/test/test_sys_checkout.py @@ -38,7 +38,6 @@ import os import os.path import shutil -import sys import unittest from manic.externals_description import ExternalsDescription diff --git a/test/test_unit_repository_git.py b/test/test_unit_repository_git.py index 4a0a334bb1..b153e556a9 100644 --- a/test/test_unit_repository_git.py +++ b/test/test_unit_repository_git.py @@ -101,7 +101,7 @@ def test_ref_branch(self): True, 'feature3') self._repo._git_current_tag = self._git_current_tag(True, 'foo_tag') self._repo._git_current_hash = self._git_current_hash(True, 'abc123') - expected = 'feature3' + expected = 'foo_tag (branch feature3)' result = self._repo._current_ref() self.assertEqual(result, expected)