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

5brian and Marshall Bowers created

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>

Change summary

crates/git_ui/src/branch_picker.rs | 2 ++
1 file changed, 2 insertions(+)

Detailed changes

crates/git_ui/src/branch_picker.rs 🔗

@@ -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(),