Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
Add a `git: copy branch name` action (#54702)
Joseph T. Lyons4fc8a581e9c4
diff --git a/crates/git/src/git.rs b/crates/git/src/git.rsindex d965605fe08..debb7649ab7 100644--- a/crates/git/src/git.rs+++ b/crates/git/src/git.rs@@ -105,6 +105,8 @@ actions!(ViewCommit,/// Adds a file to .gitignore.AddToGitignore,+ /// Copies the current branch name to the clipboard.+ CopyBranchName,]);diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rsindex 0b44b1c5175..5aa6ffe7829 100644--- a/crates/git_ui/src/git_ui.rs+++ b/crates/git_ui/src/git_ui.rs@@ -17,8 +17,8 @@ use git::{status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode},};use gpui::{- App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, SharedString,- Subscription, Task, Window,+ App, ClipboardItem, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable,+ SharedString, Subscription, Task, Window,};use menu::{Cancel, Confirm};use project::git_store::Repository;@@ -270,6 +270,9 @@ pub fn init(cx: &mut App) {workspace.register_action(|workspace, _: &git::RenameBranch, window, cx| {rename_current_branch(workspace, window, cx);});+ workspace.register_action(|workspace, _: &git::CopyBranchName, _, cx| {+ copy_branch_name(workspace, cx);+ });workspace.register_action(show_ref_picker);workspace.register_action(|workspace, action: &DiffClipboardWithSelectionData, window, cx| {@@ -465,6 +468,20 @@ fn rename_current_branch(});}+fn copy_branch_name(workspace: &mut Workspace, cx: &mut Context<Workspace>) {+ let Some(panel) = workspace.panel::<GitPanel>(cx) else {+ return;+ };+ let branch_name = panel.update(cx, |panel, cx| {+ let repo = panel.active_repository.as_ref()?;+ let repo = repo.read(cx);+ repo.branch.as_ref().map(|branch| branch.name().to_string())+ });+ if let Some(name) = branch_name {+ cx.write_to_clipboard(ClipboardItem::new_string(name));+ }+}+struct RefPickerModal {editor: Entity<Editor>,repo: Entity<Repository>,