-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_branch_names.py
More file actions
53 lines (42 loc) · 1.69 KB
/
test_branch_names.py
File metadata and controls
53 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
"""
Test script to verify branch name display with origin paths.
"""
import subprocess
import os
def test_branch_name_parsing():
"""Test the branch name parsing logic"""
# Simulate git for-each-ref output with remote branches
mock_git_output = """master|03ce5073abc123
origin/master|03ce5073abc123
origin/feature-branch|1e41f60cabc456
origin/develop|65f29476abc789
origin/HEAD|03ce5073abc123"""
print("Testing branch name parsing with origin paths:")
print("Mock git output:")
print(mock_git_output)
print()
# Simulate the parsing logic from _add_branch_info_to_commits
commit_to_branches = {}
for line in mock_git_output.split('\n'):
line = line.strip()
if not line:
continue
parts = line.split('|', 1)
if len(parts) >= 2:
branch_name = parts[0]
commit_sha = parts[1]
# Keep remote branch names with origin path, but skip origin/HEAD
if branch_name == 'origin/HEAD':
print(f"Skipping: {branch_name}")
continue # Skip origin/HEAD
if commit_sha not in commit_to_branches:
commit_to_branches[commit_sha] = []
commit_to_branches[commit_sha].append(branch_name)
print(f"Added: {branch_name} -> {commit_sha}")
print("\nResult - Commits with their branch heads:")
for commit_sha, branches in commit_to_branches.items():
branch_display = "; ".join(branches)
print(f" {commit_sha}: {branch_display}")
if __name__ == "__main__":
test_branch_name_parsing()