Add a git: copy branch name action (#54702)

I frequently use the branch name copy action in GitHub Desktop.
I want to do this in Zed.

Self-Review Checklist:

- [X] I've reviewed my own diff for quality, security, and reliability
- [X] Unsafe blocks (if any) have justifying comments
- [X] The content is consistent with the [UI/UX
checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
- [ ] Tests cover the new/changed behavior
- [X] Performance impact has been considered and is acceptable

Release Notes:

- Added a `git: copy branch name` action.
This commit is contained in:
Joseph T. Lyons 2026-04-23 15:51:57 -04:00 committed by GitHub
parent 74456c8b49
commit 4fc8a581e9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 21 additions and 2 deletions

View file

@ -105,6 +105,8 @@ actions!(
ViewCommit,
/// Adds a file to .gitignore.
AddToGitignore,
/// Copies the current branch name to the clipboard.
CopyBranchName,
]
);

View file

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