Commit graph

12 commits

Author SHA1 Message Date
09442f2e19 fix(commands): replace combined diffs with ours-vs-theirs for unmerged files
Problem: section diffs stripped combined diff entries entirely, so
sections containing only unmerged files produced an empty result and
showed "no changes in section".

Solution: extract filenames from diff --cc entries before filtering,
then generate proper unified diffs from :2: (ours) vs :3: (theirs)
and append them to the filtered output.
2026-02-08 19:28:12 -06:00
8bf6dd7b2e test(commands): add filter_combined_diffs tests 2026-02-08 18:26:46 -05:00
93ee38db8c fix(commands): filter combined diffs from section output
Problem: git diff produces diff --cc (combined format) for unmerged
files. This format uses @@@ triple-at headers and multi-column prefixes
that the parser cannot handle, resulting in no highlighting when
pressing du on a section header in a repo with merge conflicts.

Solution: add filter_combined_diffs() to strip diff --cc entries from
raw git diff output in both gdiff_section and read_buffer, leaving
only standard unified diffs that the parser understands.
2026-02-08 18:22:33 -05:00
7781904d65 feat: add unified diff conflict resolution for unmerged files
Problem: pressing du on a UU file in fugitive status fell through to
the unstaged path, where get_index_content(:0:) fails because unmerged
files have no stage 0 entry. The fallback produced a useless diff of
HEAD vs working file with conflict markers shown as changes.

Solution: add a merge.lua module that diffs git show :2: (ours) vs
:3: (theirs), displays the result with full syntax and intra-line
highlighting, and provides resolution keymaps (doo/dot/dob/don/]x/[x)
that write back to the working file's conflict markers. Hunks are
matched to conflict regions by comparing diff del-lines against each
region's ours content. Resolved hunks are tracked per-buffer with
virtual text. commands.lua gains an unmerged branch in gdiff_file and
read_buffer, and plugin/diffs.lua registers Plug(diffs-merge-*)
mappings.
2026-02-08 17:48:15 -05:00
c72efec77d fix(commands): add diff buffer UX improvements
Problem: diffs:// buffers could trigger spurious LSP diagnostics,
opening multiple diffs from fugitive created redundant splits, and
there was no quick way to close diff windows.

Solution: disable diagnostics on diff buffers, reuse existing
diffs:// windows in the tabpage instead of creating new splits,
and add a buffer-local q keymap to close diff windows.
2026-02-07 16:48:31 -05:00
f948982848 fix(commands): handle :e on diffs:// buffers via BufReadCmd
Problem: running :e on a :Gdiff buffer cleared all content because
diffs:// buffers had no BufReadCmd handler. Neovim tried to read the
buffer name as a file path, found nothing on disk, and emptied the
buffer. This affected all three buffer creation paths (gdiff,
gdiff_file, gdiff_section).

Solution: register a BufReadCmd autocmd for diffs://* that parses the
URL and regenerates diff content from git. Change buffer options from
nofile/wipe to nowrite/delete (matching fugitive's approach) so
buffer-local autocmds and variables survive across unload/reload
cycles. Store old filepath as buffer variable for rename support.
2026-02-06 22:21:33 -05:00
9e857d4b29 feat(fugitive): line position tracking for keymaps
When pressing `du`/`dU` from a hunk line in the fugitive status buffer
(after expanding with `=`), the unified diff now opens at the
corresponding line instead of line 1.

Implementation:
- `fugitive.get_hunk_position()` returns @@ header and offset when on a hunk line
- `commands.find_hunk_line()` finds matching @@ header in diff buffer
- `commands.gdiff_file()` accepts optional `hunk_position` and jumps after opening

Also updates @phanen's README credit for the previous two fixes.

Closes #65
2026-02-05 00:27:35 -05:00
c51d625dc6 fix(parser): detect filetype from existing buffer
Files detected via shebang or modeline (e.g., `build` with `#!/bin/bash`)
weren't getting syntax highlighting because `vim.filetype.match()` only
does filename-based detection.

Now `get_ft_from_filename()` first checks if a buffer already exists for
the file and uses its detected filetype. This requires knowing the repo
root to construct the full path, so:

- `parse_buffer()` reads `b:diffs_repo_root` or `b:git_dir` (fugitive)
- `commands.lua` sets `b:diffs_repo_root` on diff buffers it creates

Co-authored-by: phanen <phanen@qq.com>
2026-02-05 00:13:32 -05:00
9ed0639005 fix(fugitive): handle renamed files correctly
Parse both old and new filenames from rename lines (R old -> new).
When diffing staged renames, use old filename as base to correctly
show content changes rather than treating the file as entirely new.

Also adds comprehensive tests for filename edge cases:
- Double extensions, hyphens, underscores, dotfiles
- Deep nested paths, complex renames
- Documents known limitation with filenames containing ' -> '
2026-02-04 23:12:30 -05:00
6072dd0156 feat(fugitive): add section header and untracked file support
Section headers (Staged/Unstaged) now show all diffs in that section,
matching fugitive's behavior. Untracked files show as all-added diffs.
Deleted files show as all-removed diffs.

Also handles edge cases:
- Empty new/old content for deleted/new files
- Section header detection returns is_header flag
2026-02-04 22:39:07 -05:00
ea60ab8d01 feat(commands): add gdiff_file for diffing arbitrary paths
Adds gdiff_file() which can diff any file path (not just current buffer)
with support for staged vs unstaged changes:
- staged=true diffs index against HEAD
- staged=false diffs working tree against index
- Falls back to HEAD if file not in index (for untracked comparison)
2026-02-04 22:23:13 -05:00
045a9044b5 feat: add :Gdiff, :Gvdiff, :Ghdiff commands for unified diff view
Compares current buffer against any git revision (default HEAD), opens result
with full diffs.nvim syntax highlighting. Follows fugitive convention:
:Gdiff/:Gvdiff open vertical split, :Ghdiff opens horizontal split.
2026-02-04 19:52:17 -05:00