Skip to content

[BUG]: branch regex is matched against {EscapedBranchName} not {BranchName} #4154

@Jaykul

Description

@Jaykul

Prerequisites

  • I have written a descriptive issue title
  • I have searched issues to ensure it has not already been reported

GitVersion package

GitVersion.Tool

GitVersion version

6.0.1

Operating system

Windows

What are you seeing?

It took me a lot of experimentation to understand why I was getting the text "{BranchName}" in my GitVersion output ... and more confusingly: "--BranchName-" in my informational version numbers ...

It turns out that even though all the default configuration uses [/-] in the regex patterns, the actual value that the regex configuration is being matched against is the {EscapedBranchName} not the {BranchName} (so the / will never match).

What is expected?

I expected the regex to be matched against the branch name, with slashes in it (so I can use dashes WITHIN the path segments without breaking the regex matching). That is, we need to be able to use a branch name like feature/jaykul/new-terminal and have the {BranchName} come out as "new-terminal" not "terminal"

Additionally, I think the documentation needs to call out when variable output is being set by the regex patterns. This was not clear to me until I got the wrong output and started investigating -- the old behavior (5.x) allowed me to override the regex without needing to re-define the capture group.

Steps to Reproduce

Create branches config:

branches:
  feature:
    regex: .*/(?<BranchName>[^/]+)$
    source-branches: ["main", "feature", "release"]

Create a branch named:
/feature/yourname/dash-separated-words

Run gitversion, and see {BranchName} everywhere.

RepositoryFixture Test

No response

Output log or link to your CI build (if appropriate).

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions