@@ -42,37 +42,27 @@ def get_latest_git_revision(branch_name):
4242 raise Exception (f"Failed to get the latest revision for branch '{ branch_name } '." ) from e
4343
4444
45- def get_trigger_branch (repo , default_branch , exclude_branches = None ):
45+ def get_trigger_branch (repo , default_branch ):
4646 """
4747 Gets the trigger branch name, handling detached HEAD state in CI environments.
4848
4949 In CI environments, the repository might be checked out at a specific commit (detached HEAD).
5050 This function tries multiple methods to determine the branch:
51- 1. Check if HEAD is attached to a branch (but skip if it's a release branch or excluded branch)
51+ 1. Check if HEAD is attached to a branch
5252 2. Check environment variables (YAMATO_BRANCH, CI_COMMIT_REF_NAME, etc.)
5353 3. Use git commands to find which remote branch contains the current commit
5454 4. Fall back to the default branch if nothing else works
5555
5656 Args:
5757 repo: GitPython Repo object
5858 default_branch: Default branch name to fall back to
59- exclude_branches: Optional list of branch names to exclude (e.g., release branches)
6059
6160 Returns:
6261 str: The branch name
6362 """
64- exclude_branches = exclude_branches or []
65- current_branch = None
66-
6763 try :
6864 # Try to get the active branch name (works when HEAD is attached)
69- current_branch = repo .active_branch .name
70- # If we're on a release branch or excluded branch, don't use it - use other methods
71- if current_branch .startswith ('release/' ) or current_branch in exclude_branches :
72- print (f"Current branch '{ current_branch } ' is a release/excluded branch, using other methods to find trigger branch..." )
73- current_branch = None
74- else :
75- return current_branch
65+ return repo .active_branch .name
7666 except (TypeError , ValueError ):
7767 # HEAD is detached, try other methods
7868 pass
@@ -105,24 +95,19 @@ def get_trigger_branch(repo, default_branch, exclude_branches=None):
10595 )
10696
10797 branches = [b .strip () for b in result .stdout .strip ().split ('\n ' ) if b .strip ()]
108- # Filter out release branches and excluded branches
109- valid_branches = []
98+ # Filter to find the most likely branch (prefer default branch, then develop, then others)
11099 for branch_line in branches :
111100 branch = branch_line .replace ('origin/' , '' ).strip ()
112- if branch and not branch .startswith ('release/' ) and branch not in exclude_branches :
113- valid_branches .append (branch )
114-
115- # Prefer default branch, then other valid branches
116- for branch in valid_branches :
117- if branch == default_branch :
101+ if branch and branch == default_branch :
118102 print (f"Found trigger branch from remote branches: { branch } " )
119103 return branch
120104
121- # If default branch not found, use the first valid branch
122- if valid_branches :
123- branch = valid_branches [0 ]
124- print (f"Found trigger branch from remote branches: { branch } " )
125- return branch
105+ # If default branch not found, use the first one
106+ if branches :
107+ branch = branches [0 ].replace ('origin/' , '' ).strip ()
108+ if branch :
109+ print (f"Found trigger branch from remote branches: { branch } " )
110+ return branch
126111 except Exception as e :
127112 print (f"Warning: Could not determine branch from remote branches: { e } " )
128113
0 commit comments