Skip to content

Commit ce462ce

Browse files
committed
excluding release branch from target branches
1 parent 921587b commit ce462ce

File tree

2 files changed

+28
-12
lines changed

2 files changed

+28
-12
lines changed

Tools/scripts/Utils/createPrAfterRelease.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ def createPrAfterRelease(config: ReleaseConfig):
3535

3636
try:
3737
repo = get_local_repo()
38-
trigger_branch = get_trigger_branch(repo, config.default_repo_branch)
38+
# Exclude the release branch when determining trigger branch (we might be on it)
39+
trigger_branch = get_trigger_branch(repo, config.default_repo_branch, exclude_branches=[config.release_branch_name])
3940
print(f"\nTrigger branch: {trigger_branch}")
4041

4142
if not config.github_manager.is_branch_present(trigger_branch):

Tools/scripts/Utils/git_utils.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,37 @@ 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):
45+
def get_trigger_branch(repo, default_branch, exclude_branches=None):
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
51+
1. Check if HEAD is attached to a branch (but skip if it's a release branch or excluded 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)
5960
6061
Returns:
6162
str: The branch name
6263
"""
64+
exclude_branches = exclude_branches or []
65+
current_branch = None
66+
6367
try:
6468
# Try to get the active branch name (works when HEAD is attached)
65-
return repo.active_branch.name
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
6676
except (TypeError, ValueError):
6777
# HEAD is detached, try other methods
6878
pass
@@ -95,19 +105,24 @@ def get_trigger_branch(repo, default_branch):
95105
)
96106

97107
branches = [b.strip() for b in result.stdout.strip().split('\n') if b.strip()]
98-
# Filter to find the most likely branch (prefer default branch, then develop, then others)
108+
# Filter out release branches and excluded branches
109+
valid_branches = []
99110
for branch_line in branches:
100111
branch = branch_line.replace('origin/', '').strip()
101-
if branch and branch == default_branch:
102-
print(f"Found trigger branch from remote branches: {branch}")
103-
return branch
112+
if branch and not branch.startswith('release/') and branch not in exclude_branches:
113+
valid_branches.append(branch)
104114

105-
# If default branch not found, use the first one
106-
if branches:
107-
branch = branches[0].replace('origin/', '').strip()
108-
if branch:
115+
# Prefer default branch, then other valid branches
116+
for branch in valid_branches:
117+
if branch == default_branch:
109118
print(f"Found trigger branch from remote branches: {branch}")
110119
return branch
120+
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
111126
except Exception as e:
112127
print(f"Warning: Could not determine branch from remote branches: {e}")
113128

0 commit comments

Comments
 (0)