feat(baseBranch): improve `shortName` calculation
๐งข Changes
- Renamed original
shortNamegetter tolastPathComponentto better reflect its actual functionality - Added an enhanced implementation of
shortNamethat properly handles Git reference formats - Added support for stripping common Git prefixes (
refs/remotes/remoteName/,remoteName/,refs/heads/)
โ๏ธ Reasoning
The previous shortName implementation only extracted the last path component of a branch name without handling Git's reference formats properly. The new implementation normalizes branch names by intelligently stripping Git-specific prefixes based on context (remote vs. local), resulting in more consistent and user-friendly branch name representation throughout the application.
Further context:
- This affected me when I had my target set to
origin/release/2025.18. When I tried to create a PR it was attempting to use2025.18as the base branch. GitHub refused and GitButler showed an error. This fix allowed me to successfully create the PR. I also invested the other locations that leveragedshortNameand they all appeared to use it in a context where they would expect the full branch name.
The latest updates on your projects. Learn more about Vercel for Git โ๏ธ
| Name | Status | Preview | Comments | Updated (UTC) |
|---|---|---|---|---|
| gitbutler-components | โ Ready (Inspect) | Visit Preview | ๐ฌ Add feedback | May 18, 2025 10:41pm |
@matthewevans is attempting to deploy a commit to the GitButler Team on Vercel.
A member of the Team first needs to authorize it.
That's great, thanks so much! It would be lovely if this could fix the linked PR-creation issue.
Do you think it's possible to add a simple task list to the PR so it's possible to see what's missing? Maybe even turn it into a draft.
The reason I am asking is that the new shortName() function doesn't seem to be used yet.
Thanks again
CC @estib-vega .
That's great, thanks so much! It would be lovely if this could fix the linked PR-creation issue. Do you think it's possible to add a simple task list to the PR so it's possible to see what's missing? Maybe even turn it into a draft. The reason I am asking is that the new
shortName()function doesn't seem to be used yet. Thanks againCC @estib-vega .
Forgive me if I'm misunderstanding, but the new shortName function (that's been renamed) is just a copy of the old shortName.
- Renamed
shortNametolastPathComponent - Implemented a fixed version of
shortNamethat works with branches that contain/. This is the actual fix of this PR. lastPathComponentis left purely for posterity (if there's a use-case that desires just the last part of the branch path).
@matthewevans another great contribution! Much appreciated :)
We should probably use the rust function given_name for this since remove names can include forward slashes