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

@ -6,7 +6,7 @@ vim.g.loaded_diffs = 1
require('diffs.commands').setup()
vim.api.nvim_create_autocmd('FileType', {
pattern = (vim.g.diffs or {}).filetypes or { 'fugitive', 'git', 'gitcommit' },
pattern = require('diffs').compute_filetypes(vim.g.diffs or {}),
callback = function(args)
local diffs = require('diffs')
if args.match == 'git' and not diffs.is_fugitive_buffer(args.buf) then