git: Add diff_base setting for showing changes since the default branch (#61501)
# Objective Let git indicators — the editor gutter, file colors, and `git::Diff` — show all changes on the current branch relative to its merge base with the default branch, instead of only uncommitted changes. Supersedes #60398; thanks to @samuelcolvin for the original implementation and motivation. Closes FR-135 ## Solution - New `git.diff_base` setting (`"head"` | `"default_branch"`), applied live and toggleable per session from the editor controls menu ("Diff Against Default Branch"). - Statuses come from a real merge-base-to-worktree tree diff (`git diff --merge-base`), so local edits that revert branch changes correctly show as unchanged. - `GitStore` shares one `DiffBufferList` per repository with the Branch Diff view; `repo_snapshots` and `project_path_git_status` keep returning index/worktree truth, while display surfaces use separate `display_*` APIs. - `BufferDiff` now records what its base is (`DiffBaseKind`); hunks whose base isn't HEAD are read-only in the gutter — stage/restore buttons and keybindings are inert, so committed work can't be silently rewritten. - `git::Diff` follows the setting; new `git::DiffHead` always opens the HEAD diff; `git::BranchDiff` is renamed `git::DiffBranch` (deprecated alias kept). Tradeoffs / known limitations: - Hunk-level staging is unavailable while in `default_branch` mode (whole-file staging via the git panel still works). Staging just the uncommitted sub-ranges of a branch hunk is a follow-up. - Remote hosts running an older server ignore the new `GetTreeDiff.includes_worktree` proto field and degrade to committed-changes-only branch diffs. - Repositories with no resolvable default branch fall back to HEAD-relative behavior; a failed first resolution retries on the next branch-list change. ## Testing - Real-git-repo tests for the merge-base-to-worktree diff's edge cases: files recreated after index deletion, committed deletions recreated on disk, and symlinks. - GPUI tests for status semantics (a branch change reverted on disk shows clean), `git::Diff` routing, live setting changes, and read-only hunk enforcement (restore/stage leave buffer and index untouched). ## 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 adheres to Zed's UI standards ([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) and [icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md) guidelines) - [x] Tests cover the new/changed behavior - [x] Performance impact has been considered and is acceptable --- Release Notes: - Git: Added a `git.diff_base` setting (`"head"` or `"default_branch"`) that makes the editor gutter, file colors, and diff view show all changes on the current branch since its merge base with the default branch, instead of only uncommitted changes. --------- Co-authored-by: Ben Kunkle <ben@zed.dev>
This commit is contained in:
1 parent
5e03f2d387
commit
5e1fd392f6
35 files changed
+1742
-465
No files matched your search
@@ -373,6 +373,7 @@ impl CommitView {
|
||||
&snapshot,
|
||||
snapshot.language().cloned(),
|
||||
Some(language_registry.clone()),
|
||||
buffer_diff::DiffBaseKind::Oid,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
@@ -1003,8 +1004,15 @@ async fn build_buffer_diff(
|
||||
let language = cx.update(|_, cx| buffer.read(cx).language().cloned())?;
|
||||
let buffer = cx.update(|_, cx| buffer.read(cx).snapshot())?;
|
||||
|
||||
let diff =
|
||||
cx.new(|cx| BufferDiff::new(&buffer.text, language, Some(language_registry.clone()), cx));
|
||||
let diff = cx.new(|cx| {
|
||||
BufferDiff::new(
|
||||
&buffer.text,
|
||||
language,
|
||||
Some(language_registry.clone()),
|
||||
buffer_diff::DiffBaseKind::Oid,
|
||||
cx,
|
||||
)
|
||||
});
|
||||
|
||||
diff.update(cx, |diff, cx| {
|
||||
diff.set_base_text(
|
||||
|
||||
Reference in new issue
Block a user