Skip to content

Copy a ref's name to the clipboard from its menu - #711

Merged
hannesa2 merged 1 commit into
masterfrom
copy-a-ref-name-to-the-clipboard
Sep 22, 2026
Merged

hannesa2 merged 1 commit into
masterfrom
copy-a-ref-name-to-the-clipboard

Conversation

@goneng

@goneng goneng commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

A branch name too long for the sidebar to show has to be read off the
screen and retyped before it can be used, so the menu that every ref
already has now offers to copy it.

Description

  • Add the item to menuItemsForRef:, the one builder the sidebar and
    the ref labels in the history view both read, so both gain it at once
  • Copy the short name, feature/foo, which is what a git command
    takes; the full ref would have to be trimmed by hand
  • Reach the ref through refishForSender:refishTypes: with no type
    filter, so branches, tags, remotes and remote branches are all
    covered by the same action
  • Put it second, directly under the entry that opens or checks the ref
    out, rather than beside the one that removes it, and title it
    "Copy name" so it is clear what lands on the clipboard

Screenshot

image

Test plan

  • 183 unit tests pass, six covering this item: it is offered and
    enabled, carries its ref, names the branch rather than the full ref,
    is offered for tags and remote branches, sits second whether the
    first entry checks out or opens a worktree, comes first for a plain
    remote which has neither, and is never adjacent to Remove
  • Checked by hand in a running build against the GitX repo: the menu
    for master reads Checkout “master” then Copy name “master”, and
    invoking it puts master on the clipboard, not refs/heads/master
  • No automated test covers the pasteboard write itself. NSPasteboard generalPasteboard is system-wide, so a test would replace whatever
    the developer had copied, and restoring it would preserve only plain
    text. The wiring, the title, the placement and the ref types are
    covered instead.

@goneng
goneng force-pushed the copy-a-ref-name-to-the-clipboard branch from 990b053 to 12b47e4 Compare September 21, 2026 19:51
@goneng
goneng marked this pull request as ready for review September 21, 2026 20:00
@goneng
goneng requested a review from hannesa2 September 21, 2026 21:05
@hannesa2

Copy link
Copy Markdown
Contributor

Do you have an idea, why this menu is not shown in screenshots ?

@goneng

goneng commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Do you have an idea, why this menu is not shown in screenshots ?

yes, the new option is not showing because the right-click is done on the commit-message and not on the actual branch-tag.
because there could be a few branch-tags on a specific line (and sometimes there are none, of course), the application has a different popup-menu that depends on where we right-click.

@goneng
goneng force-pushed the copy-a-ref-name-to-the-clipboard branch from 12b47e4 to 3dab919 Compare September 22, 2026 05:19
A name too long for the sidebar to show has to be read off the screen
and retyped before it can be used, so the menu that every ref already
has offers to copy it.

- Add the item to the shared ref menu builder, so the sidebar rows and
  the ref labels in the history view both gain it at once
- Copy the short name, which is what a git command takes, rather than
  the full ref, which would have to be trimmed by hand
- Put it second, under the entry that opens or checks the ref out, so
  it is nowhere near the one that removes it
- Say "Copy name", since a menu of refs is not obvious about what a
  bare "Copy" would take
@goneng
goneng force-pushed the copy-a-ref-name-to-the-clipboard branch from 3dab919 to 11dc5c7 Compare September 22, 2026 05:21
@hannesa2

Copy link
Copy Markdown
Contributor

Screenshot differs: emulatorApi=arm64 with 1 screenshot(s)

setpoint (old) | diff | actual screenshot (new)

staging-view.pngscreenshot

@hannesa2
hannesa2 merged commit 031951c into master Sep 22, 2026
3 checks passed
@hannesa2
hannesa2 deleted the copy-a-ref-name-to-the-clipboard branch September 22, 2026 05:45
@hannesa2

hannesa2 commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

I used it recently the first time in real life. It's very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants