Skip to content

feat(baseBranch): improve shortName calculation #8608

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

Merged
merged 6 commits into from
May 19, 2025

Conversation

matthewevans
Copy link
Contributor

@matthewevans matthewevans commented May 16, 2025

🧢 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.

🎫 Affected issues

Fixes: #8596 (I believe – I was receiving the same error in my repro case)

Verified

This commit was signed with the committer’s verified signature.
outsideris Outsider
Improve the `shortName` calculation to handle various Git branch name
formats, including remote branches and local branches. This ensures
the branch name is always returned in a consistent format, without
any prefixes like "refs/remotes/", "refs/heads/", or the remote name.
Copy link

vercel bot commented May 16, 2025

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

Copy link

vercel bot commented May 16, 2025

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

A member of the Team first needs to authorize it.

@Byron
Copy link
Collaborator

Byron commented May 18, 2025

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 Byron added the feedback requested Feedback was requested to help resolve the issue label May 18, 2025
@matthewevans
Copy link
Contributor Author

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).

@Byron Byron removed the feedback requested Feedback was requested to help resolve the issue label May 18, 2025
@estib-vega
Copy link
Contributor

@matthewevans another great contribution!
Much appreciated :)

@estib-vega estib-vega merged commit 55d31a9 into gitbutlerapp:master May 19, 2025
18 of 20 checks passed
@Caleb-T-Owens
Copy link
Contributor

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

Comment on lines +7 to +12
{
branchName: 'refs/remotes/origin/feature/foo',
remoteName: 'origin',
expected: 'feature/foo',
description: 'full ref with remote'
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could have some horror of a scenario where you have a remote called origin/feature and the branch name is only foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitHub API Error while creating pull request
4 participants