Skip to content

Fix branch names with slashes truncated in GetRemoteBranches#3717

Merged
fiftin merged 2 commits intodevelopfrom
copilot/fix-branch-parsing-logic
Mar 24, 2026
Merged

Fix branch names with slashes truncated in GetRemoteBranches#3717
fiftin merged 2 commits intodevelopfrom
copilot/fix-branch-parsing-logic

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 23, 2026

getRepositoryBranchNames was extracting branch names by splitting on the last /, causing branches like env/test to be returned as test. The fix strips the refs/heads/ prefix instead, preserving embedded slashes.

Changes

  • db_lib/CmdGitClient.go: Replace strings.LastIndex(refPath, "/") with strings.HasPrefix + strings.TrimPrefix("refs/heads/"). Also adds strings.TrimSpace on the ref path to handle trailing whitespace.
  • db_lib/CmdGitClient_test.go: New test file covering simple branches, branches with slashes, non-heads refs, and edge cases.
// git ls-remote --heads output
abc123	refs/heads/env/test

// Before: "test"
// After:  "env/test"
Original prompt

This section details on the original issue you should resolve

<issue_title>Repository branches API returns incorrect values for branches with /</issue_title>
<issue_description>Hi, I'm using Semaphore to provide an UI for Ansible deployments. I am running into an issue with what I think is the branch parsing logic.

Basically, I have a branch named env/test which represents the current state of the test environment. However, the endpoint seems to parse this branch name as just test. This prevents me from inputting env/test in the template edit UI and picking test leads to failure to run the template (because test branch does not exist).

The API itself seems okay with env/test because if I send the PUT /project/{}/templates/{} request manually it gets saved with the slash and runs correctly. I can also provide the branch name with a slash when overriding the branch name for a specific run in the UI.

I think this line is the culprit, where it parses the symbolic ref name by splitting at the last slash which breaks since we have a slash in the branch name.

if idx := strings.LastIndex(refPath, "/"); idx != -1 {

I think it should instead strip the refs/heads/ prefix and pick up anything after that.</issue_description>

Comments on the Issue (you are @copilot in this section)


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Copilot AI changed the title [WIP] Fix repository branches API parsing for branches with / Fix branch names with slashes truncated in GetRemoteBranches Mar 23, 2026
Copilot AI requested a review from fiftin March 23, 2026 14:16
@fiftin fiftin changed the base branch from develop to 2-17-stable March 24, 2026 21:34
@fiftin fiftin marked this pull request as ready for review March 24, 2026 21:34
@fiftin fiftin changed the base branch from 2-17-stable to develop March 24, 2026 21:35
@fiftin fiftin merged commit 2025ba7 into develop Mar 24, 2026
17 checks passed
fiftin added a commit that referenced this pull request Mar 24, 2026
* Initial plan

* Fix branch name parsing for branches containing slashes

Co-authored-by: fiftin <[email protected]>
Agent-Logs-Url: https://github.com/semaphoreui/semaphore/sessions/0eca8209-542b-47bb-8f3f-443080c78d6e

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: fiftin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Repository branches API returns incorrect values for branches with /

2 participants