Skip to content

git_graph: Add built-in branch and commit actions to the context menu#60370

Open
sergiooroman wants to merge 6 commits into
zed-industries:mainfrom
sergiooroman:add-git-graph-context-menu-actions
Open

git_graph: Add built-in branch and commit actions to the context menu#60370
sergiooroman wants to merge 6 commits into
zed-industries:mainfrom
sergiooroman:add-git-graph-context-menu-actions

Conversation

@sergiooroman

@sergiooroman sergiooroman commented Jul 3, 2026

Copy link
Copy Markdown

Objective

The Git Graph context menu currently only offers read-only entries (View Commit, Copy SHA / Ref Name / Tag) plus user-defined custom commands. Common Git operations — checking out a branch, merging it, creating a branch from a commit, deleting a branch, cherry-picking — require leaving the graph, even though the graph is the natural place to perform them (as in VS Code's Git Graph extension, Fork, or Sublime Merge).

Solution

Adds built-in actions to the Git Graph context menu, all running through the native git backend (no terminal round-trip), so they work in remote projects too and refresh Zed's Git state as usual.

Right-clicking a branch label:

  • Check Out BranchRepository::change_branch (which already creates a local tracking branch for remote refs); disabled for the checked-out branch.
  • Merge into <current branch> / Squash Merge into <current branch> — new native merge operation (git merge --no-edit <ref> / git merge --squash <ref>); disabled when the clicked ref is the checked-out branch. A squash merge stages the changes so they can be reviewed and committed from the Git Panel.
  • Create Branch from Here… / Create Tag… — opens a small modal asking for the name, then Repository::create_branch (creates and switches, matching the branch picker's behavior) or the new native create_tag. The tag modal has an optional message field: filled in creates an annotated tag, empty creates a lightweight tag.
  • Delete Branch… — confirmation prompt, then Repository::delete_branch, reusing the branch picker's force-delete fallback for unmerged branches. Remote-ness is resolved from the live branch list rather than guessed from the ref string.

Right-clicking a commit row:

  • Check Out Commit — new native checkout_commit operation (git checkout --detach <sha>).
  • Create Branch from Here… / Create Tag… — same modal, based on the commit SHA.
  • Cherry-Pick Commit — new native cherry_pick operation.
  • Revert Commit — new native revert operation (git revert --no-edit <sha>).

Right-clicking a tag label: Check Out Tag (detached), Create Branch from Here…, and Delete Tag… (with confirmation).

Backend changes:

  • GitRepository gains merge (with a squash flag), cherry_pick, revert, checkout_commit, create_tag, and delete_tag, implemented for RealGitRepository and FakeGitRepository.
  • New GitMerge, GitCherryPick, GitRevert, GitCheckoutCommit, GitCreateTag, and GitDeleteTag proto messages (462–467), with GitStore handlers and collab forwarding, so the operations work in shared/remote projects like the existing branch operations.
  • Repository (git_store) exposes the operations following the same send_job local/remote pattern as change_branch.

Failure cases (e.g. a merge or cherry-pick with conflicts) surface through the standard git error toast with View Log, and conflicts can then be resolved from the Git Panel as usual.

User-defined custom commands keep working and stay in their own section below the built-in entries. Docs: added a "Git Graph" section to docs/src/git.md.

Testing

  • New real-git test test_merge_cherry_pick_revert_and_checkout_commit in crates/git exercising the new backend operations end to end, including squash merge staging, lightweight vs. annotated tag creation, and tag deletion.
  • New gpui test test_checkout_commit_detaches_head in crates/git_ui covering the graph-level action against the fake backend.
  • Existing git_ui test suite passes (cargo test -p git_ui --lib), clippy clean with --deny warnings on all touched crates.
  • Exercised manually on macOS against a local build.

Self-Review Checklist:

  • I've reviewed my own diff for quality, security, and reliability
  • Unsafe blocks (if any) have justifying comments
  • The content adheres to Zed's UI standards (UX/UI and icon guidelines)
  • Tests cover the new/changed behavior
  • Performance impact has been considered and is acceptable

Release Notes:

  • Added checkout, merge, squash merge, cherry-pick, revert, and branch and tag management actions to the Git Graph context menu.

🤖 Generated with Claude Code

Adds checkout, merge, create branch, and delete branch entries for branch
refs, plus detached checkout, cherry-pick, revert, and create branch
entries for commits, to the Git Graph context menu. Branch operations use
the existing Repository methods; operations without native backend
support run as one-shot terminal tasks through the same infrastructure
as custom Git commands.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cla-bot

cla-bot Bot commented Jul 3, 2026

Copy link
Copy Markdown

We require contributors to sign our Contributor License Agreement, and we don't have @sergiooroman on file. You can sign our CLA at https://zed.dev/cla. Once you've signed, post a comment here that says '@cla-bot check'.

@zed-community-bot zed-community-bot Bot added the first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions label Jul 3, 2026
@cla-bot cla-bot Bot added the cla-signed The user has signed the Contributor License Agreement label Jul 3, 2026
sergiooroman and others added 5 commits July 3, 2026 21:42
Replaces the terminal-task implementation with native GitRepository
operations, including proto messages and collab forwarding so they work
in shared and remote projects.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Adds Create Tag on branches and commits, Check Out Tag and Delete Tag
on tag labels, and a Squash Merge variant alongside the regular merge,
with the corresponding native backend operations and proto messages.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
An optional message field creates an annotated tag when filled in and a
lightweight tag when left empty.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Ref changes like tag creation or deletion emit no repository event, so
the graph would otherwise wait indefinitely (or on watcher latency) to
reflect an operation it initiated itself.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Refreshing the view alone re-read the repository's cached graph data, so
ref changes that emit no repository event (such as tag edits) still
showed stale entries. Drop the repository's graph cache before rebuilding.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement first contribution the author's first pull request to Zed. NOTE: the label application is automated via github actions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant