66already in the python path.
77
88"""
9+ # pylint: disable=too-many-lines,protected-access
910
1011from __future__ import absolute_import
1112from __future__ import unicode_literals
2223from manic .externals_description import ExternalsDescriptionDict
2324from manic .global_constants import EMPTY_STR
2425
25- # pylint: disable=W0212
26+ # pylint: disable=C0103
27+ GIT_BRANCH_OUTPUT_DETACHED_BRANCH_v1_8 = '''
28+ * (detached from origin/feature2) 36418b4 Work on feature2
29+ master 9b75494 [origin/master] Initialize repository.
30+ '''
31+ # pylint: enable=C0103
2632
2733
2834GIT_BRANCH_OUTPUT_DETACHED_BRANCH = '''
@@ -126,6 +132,16 @@ def test_ref_detached_branch(self):
126132 git_output )
127133 self .assertEqual (result , expected )
128134
135+ def test_ref_detached_branch_v1_8 (self ):
136+ """Test that we can identify ref is detached from a remote branch
137+
138+ """
139+ git_output = GIT_BRANCH_OUTPUT_DETACHED_BRANCH_v1_8
140+ expected = 'origin/feature2'
141+ result = self ._repo ._current_ref_from_branch_command (
142+ git_output )
143+ self .assertEqual (result , expected )
144+
129145 def test_ref_tracking_branch (self ):
130146 """Test that we correctly identify we are on a tracking branch
131147 """
@@ -604,9 +620,12 @@ class TestGitRegExp(unittest.TestCase):
604620 def setUp (self ):
605621 """Common constans
606622 """
607- self ._detached_tmpl = string .Template (
623+ self ._detached_git_v2_tmpl = string .Template (
608624 '* (HEAD detached at $ref) 36418b4 Work on feature-2' )
609625
626+ self ._detached_git_v1_tmpl = string .Template (
627+ '* (detached from $ref) 36418b4 Work on feature-2' )
628+
610629 self ._tracking_tmpl = string .Template (
611630 '* feature-2 36418b4 [$ref] Work on feature-2' )
612631
@@ -617,7 +636,11 @@ def test_re_detached_alphnum(self):
617636 """Test re correctly matches alphnumeric (basic debugging)
618637 """
619638 value = 'feature2'
620- input_str = self ._detached_tmpl .substitute (ref = value )
639+ input_str = self ._detached_git_v2_tmpl .substitute (ref = value )
640+ match = GitRepository .RE_DETACHED .search (input_str )
641+ self .assertIsNotNone (match )
642+ self .assertEqual (match .group (1 ), value )
643+ input_str = self ._detached_git_v1_tmpl .substitute (ref = value )
621644 match = GitRepository .RE_DETACHED .search (input_str )
622645 self .assertIsNotNone (match )
623646 self .assertEqual (match .group (1 ), value )
@@ -626,7 +649,11 @@ def test_re_detached_underscore(self):
626649 """Test re matches with underscore
627650 """
628651 value = 'feature_2'
629- input_str = self ._detached_tmpl .substitute (ref = value )
652+ input_str = self ._detached_git_v2_tmpl .substitute (ref = value )
653+ match = GitRepository .RE_DETACHED .search (input_str )
654+ self .assertIsNotNone (match )
655+ self .assertEqual (match .group (1 ), value )
656+ input_str = self ._detached_git_v1_tmpl .substitute (ref = value )
630657 match = GitRepository .RE_DETACHED .search (input_str )
631658 self .assertIsNotNone (match )
632659 self .assertEqual (match .group (1 ), value )
@@ -635,7 +662,11 @@ def test_re_detached_hyphen(self):
635662 """Test re matches -
636663 """
637664 value = 'feature-2'
638- input_str = self ._detached_tmpl .substitute (ref = value )
665+ input_str = self ._detached_git_v2_tmpl .substitute (ref = value )
666+ match = GitRepository .RE_DETACHED .search (input_str )
667+ self .assertIsNotNone (match )
668+ self .assertEqual (match .group (1 ), value )
669+ input_str = self ._detached_git_v1_tmpl .substitute (ref = value )
639670 match = GitRepository .RE_DETACHED .search (input_str )
640671 self .assertIsNotNone (match )
641672 self .assertEqual (match .group (1 ), value )
@@ -644,7 +675,11 @@ def test_re_detached_period(self):
644675 """Test re matches .
645676 """
646677 value = 'feature.2'
647- input_str = self ._detached_tmpl .substitute (ref = value )
678+ input_str = self ._detached_git_v2_tmpl .substitute (ref = value )
679+ match = GitRepository .RE_DETACHED .search (input_str )
680+ self .assertIsNotNone (match )
681+ self .assertEqual (match .group (1 ), value )
682+ input_str = self ._detached_git_v1_tmpl .substitute (ref = value )
648683 match = GitRepository .RE_DETACHED .search (input_str )
649684 self .assertIsNotNone (match )
650685 self .assertEqual (match .group (1 ), value )
@@ -653,7 +688,11 @@ def test_re_detached_slash(self):
653688 """Test re matches /
654689 """
655690 value = 'feature/2'
656- input_str = self ._detached_tmpl .substitute (ref = value )
691+ input_str = self ._detached_git_v2_tmpl .substitute (ref = value )
692+ match = GitRepository .RE_DETACHED .search (input_str )
693+ self .assertIsNotNone (match )
694+ self .assertEqual (match .group (1 ), value )
695+ input_str = self ._detached_git_v1_tmpl .substitute (ref = value )
657696 match = GitRepository .RE_DETACHED .search (input_str )
658697 self .assertIsNotNone (match )
659698 self .assertEqual (match .group (1 ), value )
0 commit comments