Add support for git remotes#42819
Conversation
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
crates/git_ui/src/branch_picker.rs
Outdated
| cx.spawn(async move |_, cx| { | ||
| repo.update(cx, |repo, _| repo.create_remote(remote_name, remote_url))? | ||
| .await??; | ||
|
|
||
| Ok(()) | ||
| }) | ||
| .detach_and_prompt_err("Failed to create remote", window, cx, |e, _, _| { | ||
| Some(e.to_string()) | ||
| }); |
There was a problem hiding this comment.
If this task can ever run for more than a second (e.g. poor internet) we should put a loading icon in the status bar. I'll be happy to help with this
There was a problem hiding this comment.
If you have examples in your codebase I would be interested
crates/git_ui/src/branch_picker.rs
Outdated
| format!("refs/heads/{query}").into() | ||
| } else { | ||
| format!("refs/remotes/{query}").into() | ||
| } |
There was a problem hiding this comment.
Are these paths correct on non-unix systems (Windows)?
There was a problem hiding this comment.
Yes git references work the same on Windows
crates/project/src/git_store.rs
Outdated
| unimplemented!(); | ||
| // client | ||
| // .request(proto::GitCreateBranch { | ||
| // project_id: project_id.0, | ||
| // repository_id: id.to_proto(), | ||
| // branch_name, | ||
| // }) | ||
| // .await?; | ||
|
|
There was a problem hiding this comment.
If you need help with creating the proto messages and handlers I'll be happy to pair with you on it
| let remote_names: HashSet<Remote> = String::from_utf8_lossy(&output.stdout) | ||
| .lines() | ||
| .filter(|line| !line.is_empty()) | ||
| .filter_map(|line| { | ||
| let mut splitted_line = line.split_whitespace(); | ||
| let remote_name = splitted_line.next()?; | ||
| let remote_url = splitted_line.next()?; | ||
|
|
||
| Some(remote::Remote { | ||
| name: remote_name.trim().to_string().into(), | ||
| url: RemoteUrl::from_str(remote_url).ok()?, | ||
| }) | ||
| }) | ||
| .collect(); | ||
| Ok(remote_names) | ||
|
|
||
| Ok(remote_names.into_iter().collect()) |
There was a problem hiding this comment.
Nit: Seems like you're calling collect twice here. The first in when creating remote_names and the second when returning remote_names.into_iter().collect()
you should be able to get away with only one call to collect
There was a problem hiding this comment.
Not really because I just convert from an hashset to a vec
| fn remove_remote(&self, name: String) -> BoxFuture<'_, Result<()>> { | ||
| let repo = self.repository.clone(); | ||
| self.executor | ||
| .spawn(async move { | ||
| let repo = repo.lock(); | ||
| repo.remote_delete(&name)?; |
There was a problem hiding this comment.
Nit: remove_remote and repo.remote_delete should have the same names IMO.
I personally prefer remove_remote/delete_remote because it's consistent with the naming pattern for the rest of the repository functions. Where it's verb_noun
There was a problem hiding this comment.
I completely agree with you but remote_delete comes from the external crate git2 https://docs.rs/git2/latest/git2/struct.Repository.html#method.remote_delete
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
|
I think I need guidance on how to write tests for this kind of feature @Anthony-Eid if you're available |
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
|
I added some tests to also test the previous behavior with the branch and the new one with remote. Let me know if you want me to add other tests. |
crates/git_ui/src/branch_picker.rs
Outdated
| .border_color(cx.theme().colors().border_variant) | ||
| .child( | ||
| h_flex().gap_0p5().child( | ||
| ToggleButtonGroup::single_row( |
There was a problem hiding this comment.
I don't know why but since ToggleButton no longer exists it looks like the style doesn't change when it's selected or not. When debugging I can see the Boolean being updated properly but maybe the style when a toggle button is selected is incorrect... I don't know
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
| client.add_entity_request_handler(Self::handle_change_branch); | ||
| client.add_entity_request_handler(Self::handle_create_branch); | ||
| client.add_entity_request_handler(Self::handle_rename_branch); | ||
| client.add_entity_request_handler(Self::handle_create_remote); |
There was a problem hiding this comment.
@dvdsk need to test this with test server or just cross fingers :)
There was a problem hiding this comment.
look over the remote stuff in more detail and fix anything needed. (I should do this)
yara-blue
left a comment
There was a problem hiding this comment.
Amazing, I want this now. Some minor refactoring and we will check that collab works!
🥳 🥳 🥇
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
|
cc @dvdsk It should be ready to review again :) |
Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
sorry GitHub did not notify me for some reason..... I'll review it right now. |
yara-blue
left a comment
There was a problem hiding this comment.
Looks great! Tests are super readable now. Like the is_new_branch solution too btw!
LGTM
* main: (155 commits) Add support for git remotes (zed-industries#42819) python: Improve sorting order of toolchains to give higher precedence to project-local virtual environments that are within current subproject (zed-industries#44141) Use buffer language when formatting with Prettier (zed-industries#43368) search: Fix sort order not being maintained in presence of open buffers (zed-industries#44135) bedrock: Support global endpoints and new regional endpoints (zed-industries#44103) linux: Spawn at least two background threads (zed-industries#44110) macos: Add missing file access entitlements (zed-industries#43609) Re-colorize the brackets when the theme changes (zed-industries#44130) Reduce priority of Windows thread pool work items (zed-industries#44121) Update fancy-regex (zed-industries#44120) Prefer to disable options over hiding (git panel entry context menu) (zed-industries#44102) tab_switcher: Subscribe to workspace events instead of pane events (zed-industries#44101) editor: Add active match highlight for buffer and project search (zed-industries#44098) Add more preview tab settings and fix janky behavior (zed-industries#43921) ai: Add an eval for the inline assistant (zed-industries#43291) Fix circular reference issue around PopoverMenu again (zed-industries#44084) Run `git2::Repository::find_remote` in the background (zed-industries#44092) Improve support for multiple registrations of `textDocument/diagnostic` (zed-industries#43703) Revert "http_client: Add integrity checks for GitHub binaries using digest checks (zed-industries#43737)" (zed-industries#44086) editor: Fix blame hover not working when inline git blame is disabled (zed-industries#42992) ...
… on the branch name (#44206) The bug was introduced in this recent PR: #42819. Since it's still in nightly, there is no need for release notes. I also polished the feature a bit by: - Ensuring branch names are always a single line so the branch picker's uniform list uses the correct element height. - Adding tooltip text for the filter remotes button. - Fixing the create branch from default icon showing up for non-new branch entries. Release Notes: - N/A
Follow up of zed-industries#42486 Closes zed-industries#26559 https://github.com/user-attachments/assets/e2f54dda-a78b-4d9b-a910-16d51f98a111 Release Notes: - Added support for git remotes --------- Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
… on the branch name (zed-industries#44206) The bug was introduced in this recent PR: zed-industries#42819. Since it's still in nightly, there is no need for release notes. I also polished the feature a bit by: - Ensuring branch names are always a single line so the branch picker's uniform list uses the correct element height. - Adding tooltip text for the filter remotes button. - Fixing the create branch from default icon showing up for non-new branch entries. Release Notes: - N/A
Follow up to #42819 and #44206. - Make this picker feel more consistent with other similar pickers (namely, the project picker) - Move actions to the footer and toggle them conditionally - Only show the "Create" and "Create New From: {default}" when we're selecting the "Create" list item _or_ when that item is the only visible. This means I'm changing here the state transition to only change to `NewBranch/NewRemote` if we only have those items available. - Reuse more UI code and use components when available (e.g., `ListHeader`) - Remove secondary actions from the list item Next step (in another PR), will be refine the same picker in the smaller, panel version. https://github.com/user-attachments/assets/fe72ac06-c1df-4829-a8a4-df8a9222672f Release Notes: - N/A
Follow up of zed-industries#42486 Closes zed-industries#26559 https://github.com/user-attachments/assets/e2f54dda-a78b-4d9b-a910-16d51f98a111 Release Notes: - Added support for git remotes --------- Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
… on the branch name (zed-industries#44206) The bug was introduced in this recent PR: zed-industries#42819. Since it's still in nightly, there is no need for release notes. I also polished the feature a bit by: - Ensuring branch names are always a single line so the branch picker's uniform list uses the correct element height. - Adding tooltip text for the filter remotes button. - Fixing the create branch from default icon showing up for non-new branch entries. Release Notes: - N/A
Follow up to zed-industries#42819 and zed-industries#44206. - Make this picker feel more consistent with other similar pickers (namely, the project picker) - Move actions to the footer and toggle them conditionally - Only show the "Create" and "Create New From: {default}" when we're selecting the "Create" list item _or_ when that item is the only visible. This means I'm changing here the state transition to only change to `NewBranch/NewRemote` if we only have those items available. - Reuse more UI code and use components when available (e.g., `ListHeader`) - Remove secondary actions from the list item Next step (in another PR), will be refine the same picker in the smaller, panel version. https://github.com/user-attachments/assets/fe72ac06-c1df-4829-a8a4-df8a9222672f Release Notes: - N/A
Follow up of zed-industries#42486 Closes zed-industries#26559 https://github.com/user-attachments/assets/e2f54dda-a78b-4d9b-a910-16d51f98a111 Release Notes: - Added support for git remotes --------- Signed-off-by: Benjamin <5719034+bnjjj@users.noreply.github.com>
… on the branch name (zed-industries#44206) The bug was introduced in this recent PR: zed-industries#42819. Since it's still in nightly, there is no need for release notes. I also polished the feature a bit by: - Ensuring branch names are always a single line so the branch picker's uniform list uses the correct element height. - Adding tooltip text for the filter remotes button. - Fixing the create branch from default icon showing up for non-new branch entries. Release Notes: - N/A
Follow up to zed-industries#42819 and zed-industries#44206. - Make this picker feel more consistent with other similar pickers (namely, the project picker) - Move actions to the footer and toggle them conditionally - Only show the "Create" and "Create New From: {default}" when we're selecting the "Create" list item _or_ when that item is the only visible. This means I'm changing here the state transition to only change to `NewBranch/NewRemote` if we only have those items available. - Reuse more UI code and use components when available (e.g., `ListHeader`) - Remove secondary actions from the list item Next step (in another PR), will be refine the same picker in the smaller, panel version. https://github.com/user-attachments/assets/fe72ac06-c1df-4829-a8a4-df8a9222672f Release Notes: - N/A
Follow up of #42486
Closes #26559
Enregistrement.de.l.ecran.2025-11-15.a.22.43.44.mov
Release Notes: