gitbutler icon indicating copy to clipboard operation
gitbutler copied to clipboard

feat(baseBranch): improve `shortName` calculation

Open matthewevans opened this issue 7 months ago โ€ข 2 comments

๐Ÿงข Changes

  • Renamed original shortName getter to lastPathComponent to better reflect its actual functionality
  • Added an enhanced implementation of shortName that 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 use 2025.18 as 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 leveraged shortName and they all appeared to use it in a context where they would expect the full branch name.

matthewevans avatar May 16 '25 23:05 matthewevans

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

vercel[bot] avatar May 16 '25 23:05 vercel[bot]

@matthewevans is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

vercel[bot] avatar May 16 '25 23:05 vercel[bot]

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 .

Byron avatar May 18 '25 18:05 Byron

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 .

Forgive me if I'm misunderstanding, but the new shortName function (that's been renamed) is just a copy of the old shortName.

  1. Renamed shortName to lastPathComponent
  2. Implemented a fixed version of shortName that works with branches that contain /. This is the actual fix of this PR.
  3. lastPathComponent is left purely for posterity (if there's a use-case that desires just the last part of the branch path).

matthewevans avatar May 18 '25 19:05 matthewevans

@matthewevans another great contribution! Much appreciated :)

estib-vega avatar May 19 '25 11:05 estib-vega

We should probably use the rust function given_name for this since remove names can include forward slashes

Caleb-T-Owens avatar May 19 '25 11:05 Caleb-T-Owens