feat: add neogit support (#117)

## TODO

1. docs (vimdoc + readme) - this is a non-trivial feature
2. push luarocks version

## Problem

diffs.nvim only activates on `fugitive`, `git`, and `gitcommit`
filetypes.
Neogit uses its own custom filetypes (`NeogitStatus`,
`NeogitCommitView`,
`NeogitDiffView`) and doesn't set `b:git_dir`, so the plugin never
attaches
and repo root resolution fails for filetype detection within diff hunks.

## Solution

Two changes:

1. **`lua/diffs/init.lua`** — Add the three Neogit filetypes to the
default
`filetypes` list. The `FileType` autocmd in `plugin/diffs.lua` already
handles them correctly since the `is_fugitive_buffer` guard only applies
   to the `git` filetype.

2. **`lua/diffs/parser.lua`** — Add a CWD-based fallback in
`get_repo_root()`.
After the existing `b:diffs_repo_root` and `b:git_dir` checks, fall back
to
`vim.fn.getcwd()` via `git.get_repo_root()` (already cached). Without
this,
   the parser can't resolve filetypes for files in Neogit buffers.

Neogit's expanded diffs use standard unified diff format, so the parser
handles
them without modification.

Closes #110.
This commit is contained in:
Barrett Ruth 2026-02-14 17:12:01 -05:00 committed by GitHub
parent 5d3bbc3631
commit 3d640c207b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 314 additions and 56 deletions

View file

@ -110,7 +110,9 @@ local function get_repo_root(bufnr)
return vim.fn.fnamemodify(git_dir, ':h')
end
return nil
local cwd = vim.fn.getcwd()
local git = require('diffs.git')
return git.get_repo_root(cwd .. '/.')
end
---@param bufnr integer
@ -194,7 +196,13 @@ function M.parse_buffer(bufnr)
for i, line in ipairs(lines) do
local diff_git_file = line:match('^diff %-%-git a/.+ b/(.+)$')
local filename = line:match('^[MADRCU%?!]%s+(.+)$') or diff_git_file
local neogit_file = line:match('^modified%s+(.+)$')
or line:match('^new file%s+(.+)$')
or line:match('^deleted%s+(.+)$')
or line:match('^renamed%s+(.+)$')
or line:match('^copied%s+(.+)$')
local bare_file = not hunk_start and line:match('^([^%s]+%.[^%s]+)$')
local filename = line:match('^[MADRCU%?!]%s+(.+)$') or diff_git_file or neogit_file or bare_file
if filename then
is_unified_diff = diff_git_file ~= nil
flush_hunk()