Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
Jaykul opened this issue Aug 11, 2024 · 1 comment
Open
2 tasks done
Labels
Milestone

Comments

@Jaykul
Copy link

Jaykul commented Aug 11, 2024

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

@Jaykul Jaykul changed the title [ISSUE]: branch config regex is matched against [EscapedBranchName} not {BranchName} (which is confusing). [ISSUE]: branch config regex is matched against {EscapedBranchName} not {BranchName} (which is confusing). Aug 11, 2024
@Jaykul Jaykul changed the title [ISSUE]: branch config regex is matched against {EscapedBranchName} not {BranchName} (which is confusing). [ISSUE]: branch regex is matched against {EscapedBranchName} not {BranchName} Aug 11, 2024
@HHobeck
Copy link
Contributor

HHobeck commented Aug 12, 2024

Yes I agree this behavior is not intentionally. I think the related source code is located in the ConfigurationExtensions class (see Attachment[1]). May I ask you to change it and create a pull-request?

Thank you!

Attachment[1]:
image

@HHobeck HHobeck added bug and removed needs triage labels Aug 12, 2024
@HHobeck HHobeck added this to the 6.x milestone Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants