Skip to content

Commit cee9700

Browse files
(PTFE-2534) Remove sort and modify test assertion
1 parent de90e55 commit cee9700

3 files changed

Lines changed: 35 additions & 21 deletions

File tree

bert_e/tests/test_bert_e.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def test_branch_cascade_mixed_versions(self):
569569
2: {'name': 'development/4.3', 'ignore': True},
570570
3: {'name': 'development/5.1.8', 'ignore': True},
571571
4: {'name': 'development/5.1', 'ignore': False},
572-
5: {'name': 'development/10', 'ignore': False}
572+
5: {'name': 'development/10.0', 'ignore': False}
573573
})
574574
tags = ['4.3.16', '4.3.18', '5.1.3', '5.1.7']
575575
fixver = ['5.1.9', '10.0.0']

bert_e/tests/unit/test_sorted.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ def test_compare_branches_major_only_vs_major_minor():
7474
def test_compare_branches_major_minor_micro_vs_major_minor():
7575
branch1 = ((4, 3, 2),)
7676
branch2 = ((4, 3),)
77-
assert compare_branches(branch1, branch2) == -997
77+
assert compare_branches(branch1, branch2) == -1
7878

7979

8080
def test_compare_branches_major_minor_vs_major_minor_micro():
8181
branch1 = ((4, 3),)
8282
branch2 = ((4, 3, 2),)
83-
assert compare_branches(branch1, branch2) == 997
83+
assert compare_branches(branch1, branch2) == 1

bert_e/workflow/gitwaterflow/branches.py

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,38 @@ def compare_branches(branch1, branch2):
6363
return -1
6464

6565
# Both are major.minor or longer - compare normally
66-
minor1 = version1[1] if len(version1) > 1 else 999
67-
minor2 = version2[1] if len(version2) > 1 else 999
68-
69-
# Compare minor versions
70-
if minor1 != minor2:
71-
return minor1 - minor2
72-
73-
# Same major.minor - extract micro versions
74-
# Default to 0 if no micro
75-
micro1 = version1[2] if len(version1) > 2 else 999
76-
# Default to 0 if no micro
77-
micro2 = version2[2] if len(version2) > 2 else 999
78-
79-
# Compare micro versions
80-
if micro1 != micro2:
81-
return micro1 - micro2
82-
else:
83-
return 0
66+
# Handle cases where one version has missing components
67+
len1 = len(version1)
68+
len2 = len(version2)
69+
70+
# Compare minor versions if both exist
71+
if len1 > 1 and len2 > 1:
72+
minor1 = version1[1]
73+
minor2 = version2[1]
74+
if minor1 != minor2:
75+
return minor1 - minor2
76+
elif len1 > 1 and len2 == 1:
77+
# version1 has minor, version2 doesn't -> version1 comes first
78+
return -1
79+
elif len1 == 1 and len2 > 1:
80+
# version2 has minor, version1 doesn't -> version2 comes first
81+
return 1
82+
# Both have same length (1) -> major versions already compared above
83+
84+
# Same major.minor - compare micro versions if both exist
85+
if len1 > 2 and len2 > 2:
86+
micro1 = version1[2]
87+
micro2 = version2[2]
88+
if micro1 != micro2:
89+
return micro1 - micro2
90+
elif len1 > 2 and len2 <= 2:
91+
# version1 has micro, version2 doesn't -> version1 comes first
92+
return -1
93+
elif len1 <= 2 and len2 > 2:
94+
# version2 has micro, version1 doesn't -> version2 comes first
95+
return 1
96+
97+
return 0
8498

8599

86100
def compare_queues(version1, version2):

0 commit comments

Comments
 (0)