git_ui: Replace spaces with hyphens in new branch names (#27873)

This PR improves UX by converting spaces to hyphens, following branch
naming conventions and allowing users to create branches without
worrying about naming restrictions.

I think a few other git tools do this, which was nice.



![image](https://github.com/user-attachments/assets/db40ec31-e461-4ab3-a3de-e249559994fc)

Release Notes:

- Updated the branch picker to convert spaces to hyphens when creating
new branch names.

---------

Co-authored-by: Marshall Bowers <git@maxdeviant.com>
This commit is contained in:
5brian 2025-05-27 13:10:20 -04:00 committed by GitHub
parent b01f7c848b
commit b7c5540075
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -221,6 +221,7 @@ impl BranchListDelegate {
let Some(repo) = self.repo.clone() else {
return;
};
let new_branch_name = new_branch_name.to_string().replace(' ', "-");
cx.spawn(async move |_, cx| {
repo.update(cx, |repo, _| {
repo.create_branch(new_branch_name.to_string())
@ -325,6 +326,7 @@ impl PickerDelegate for BranchListDelegate {
.first()
.is_some_and(|entry| entry.branch.name() == query)
{
let query = query.replace(' ', "-");
matches.push(BranchEntry {
branch: Branch {
ref_name: format!("refs/heads/{query}").into(),