C3: chunk staging, unstaging and revert from the gutter and the diff viewer

- crates/vcs chunk.rs: chunks of a file (buffer text vs index, HEAD vs
  index), a minimal patch applied with git apply --cached, revert as a
  byte edit; token refusal when buffer, index or HEAD changed; CRLF
  (autocrlf and stored), no final newline, BOM, staged renames, first
  commit; binary and untracked refused. Real-git tests + property test.
- engine: git.chunks, git.stageChunk, git.unstageChunk, git.revertChunk
  (revert edits the buffer under the lock, undoable in the editor);
  cmd::git::start_then; git.lineChanges shares the vcs line diff.
- UI: chunk popup on a gutter marker click (Stage / Unstage / Revert /
  Previous / Next), hollow staged markers, vcs.showChunk, diff viewer
  hint, "partly staged" badge in the Changes window.
- Docs: G8 row, Git parity row evidence, ui-parity, architecture.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
danny 2026-11-01 12:50:11 +01:00
parent d8e66a4652
commit 301443db7d
28 changed files with 3159 additions and 101 deletions

View file

@ -446,6 +446,12 @@ watch(
:class="`changes__name--${stateColor(row.state)}`"
>{{ baseName(row.file.path) }}</span>
<span class="changes__dir">{{ detail(row) }}</span>
<span
v-if="row.partial"
class="changes__partial"
:title="t('vcs.changes.partlyStaged')"
data-test="changes-row-partial"
>{{ t("vcs.changes.partly") }}</span>
<span class="changes__state">{{ stateLabel(row.state) }}</span>
</div>
</div>
@ -637,6 +643,20 @@ watch(
color: var(--lt-fg-muted);
}
.changes__partial {
flex: none;
margin-left: auto;
padding: 0 4px;
color: var(--lt-fg-muted);
border: 1px solid var(--lt-border);
border-radius: 3px;
font-size: var(--lt-font-size-small);
}
.changes__partial + .changes__state {
margin-left: 6px;
}
.changes__row--selected .changes__dir,
.changes__row--selected .changes__state {
color: var(--lt-fg);

View file

@ -10,7 +10,8 @@
* - **Groups:** a file is Staged when its index side changed, in Changes
* when its work tree side changed or it is conflicted, and Untracked when
* git does not track it. A partly staged file is in both Staged and
* Changes. Ignored files are not listed by the backend.
* Changes, and both rows say so (`partial`, C8 C3: chunks staged from
* the gutter or the diff). Ignored files are not listed by the backend.
* - **Ignoring (C7 A3):** `git.ignore {paths}` for untracked rows adds a
* literal pattern per file to the root `.gitignore`, then re-reads.
* - **Staging:** `git.stage` / `git.unstage` per file or per group.
@ -69,6 +70,8 @@ export interface ChangeRow {
file: ChangedFile;
/** The state shown: the index side in Staged, the work tree side otherwise. */
state: FileState;
/** Whether the file is partly staged, so it has a row in Staged and in Changes too. */
partial: boolean;
}
/** What the window shows above the groups. */
@ -92,7 +95,8 @@ function changed(state: FileState): boolean {
export function groupFiles(files: ChangedFile[]): Record<GroupId, ChangeRow[]> {
const out: Record<GroupId, ChangeRow[]> = { staged: [], changes: [], untracked: [] };
const add = (group: GroupId, file: ChangedFile, state: FileState): void => {
out[group].push({ key: `${group}:${file.path}`, group, file, state });
const partial = state !== "untracked" && state !== "conflicted" && changed(file.index) && changed(file.worktree);
out[group].push({ key: `${group}:${file.path}`, group, file, state, partial });
};
for (const file of files) {
if (file.index === "untracked" || file.worktree === "untracked") {

View file

@ -18,6 +18,10 @@
* (`gitChanged` after staging).
* - **Colours:** only `--lt-*` tokens; changed lines are tinted with
* `--lt-vcs-deleted` (left) and `--lt-vcs-added` (right).
* - **Chunk actions (C8 C3):** the right side is an ordinary editor of the
* buffer, so its Git gutter shows unstaged and staged markers; a click
* opens the chunk popup with Stage, Unstage and Revert. A hint line says
* so.
* - **Navigation:** a navigator over the merge view is registered for
* `vcs.nextChange` / `vcs.previousChange` (`navigation.ts`): the focused
* side, else the working copy, moves to the next or previous chunk.
@ -270,6 +274,13 @@ onBeforeUnmount(() => {
>
{{ caption }}
</div>
<div
v-if="diff.activeTab && !diff.activeTab.commit && diff.activeContent?.phase === 'ready' && diff.activeContent.bufferId !== null"
class="diff-view__hint"
data-test="diff-chunk-hint"
>
{{ t("vcs.diff.chunkHint") }}
</div>
<div
v-if="notice"
class="diff-view__notice"
@ -314,6 +325,15 @@ onBeforeUnmount(() => {
text-overflow: ellipsis;
}
.diff-view__hint {
flex-shrink: 0;
padding: 2px 12px;
color: var(--lt-fg-muted);
background: var(--lt-bg);
border-bottom: 1px solid var(--lt-border);
font-size: var(--lt-font-size-small);
}
.diff-view__notice {
flex-shrink: 0;
padding: 4px 12px;