Skip to content

Copy the right-clicked commit, not the selection (issue #406) - #621

Merged
hannesa2 merged 1 commit into
gitx:masterfrom
anandghegde:fix-copy-clicked-commit
Sep 13, 2026
Merged

hannesa2 merged 1 commit into
gitx:masterfrom
anandghegde:fix-copy-clicked-commit

Conversation

@anandghegde

Copy link
Copy Markdown
Contributor

Fixes #406.

Right-clicking a commit that isn't selected opens the menu for that commit.
Checkout, Cherry Pick, Reset and the other actions in that menu act on the
clicked commit: menuItemsForCommits: stores it as each item's
representedObject, and refishForSender: reads it back. The three copy
items (Copy SHA, Copy short SHA, Copy Patch) were the exception.
They read commitController.selectedObjects instead, so they copied the
selection, and a SHA pasted into a terminal pointed at the wrong commit.

The copy actions now go through a small commitsForSender: helper that takes
the commit, or commits, from the menu item. It falls back to the selection
when the item carries none, which is the case for the Edit menu and ⌘C.
Right-clicking inside a multi-commit selection still copies the whole
selection, because the context menu is built for those commits.

Test plan

  • make unit-test: 75 tests, 0 failures, 4 of them new (in PBGitHistorySelectionTests)
  • Confirmed red first: with the helper made to return the selection again,
    testAContextMenuItemCopiesTheClickedCommitNotTheSelection and
    testAContextMenuItemForSeveralCommitsCopiesThemAll fail
  • Manually, in a Debug build:
    • right-click an unselected commit → Copy short SHA pastes that commit's SHA
    • ⌘C / Edit → Copy SHA still copy the selection
    • right-click within a two-commit selection → Copy SHA copies both

Separately: the repo's .clang-format lists AllowShortFunctionsOnASingleLine
twice, and current clang-format (23.x) refuses to load it. I checked the
changed lines against a copy with the duplicate removed; they need no changes.

Right-clicking a commit that isn't selected opens the menu for that commit,
and Checkout, Cherry Pick, Reset and the rest act on it, but Copy SHA, Copy
short SHA and Copy Patch still copied whatever was selected. Pasting that
SHA into a terminal then acts on the wrong commit.

The copy actions now read the commit(s) the menu item was built for, and
fall back to the selection for the Edit menu and key equivalents, which
carry none.

@hannesa2 hannesa2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works as expected 👍
Thank you !

@hannesa2
hannesa2 merged commit f2fc3ed into gitx:master Sep 13, 2026
6 checks passed
@goneng

goneng commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

(LGTM - and found another cosmetic bug while reviewing this... 🙂)

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.

Right-click on commit not selected - actions perform on selected commit instead

3 participants