bug: submodule/directory in a commit causes exception #84

Closed
opened 2026-09-21 18:12:03 +00:00 by barrettruth · 1 comment
Owner

Original issue: barrettruth/diffs.nvim#189
Original author: achmutov
Original date: 2026-03-13T09:49:57Z

Prerequisites

Neovim version

NVIM v0.11.4
Build type: Release
LuaJIT 2.1.1731601260
Run "nvim -V1 -v" for more info

Operating system

Gentoo Linux x86_64

Description

When a commit contains submodule init/update or a symlink to a directory, an exception is raised:

Decoration provider "buf" (ns=diffs):
Lua: ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:355: Is a directory
stack traceback:
        [C]: in function '(for generator)'
        ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:355: in function 'read_file_lines'
        ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:376: in function 'compute_hunk_context'
        ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:435: in function 'ensure_cache'
        ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:911: in function <...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:906>

Adding a guard before reading the file seems to fix the issue:

diff --git a/lua/diffs/init.lua b/lua/diffs/init.lua
index 1244a3a..a6d7418 100644
--- a/lua/diffs/init.lua
+++ b/lua/diffs/init.lua
@@ -333,6 +333,9 @@ end
 ---@param path string
 ---@return string[]?
 local function read_file_lines(path)
+  if vim.fn.isdirectory(path) then
+    return nil
+  end
   local f = io.open(path, 'r')
   if not f then
     return nil

but you might want to check it yourself / add tests

Steps to reproduce

Create repro.git repository in current directory:

mkdir repro.git && cd repro.git
git init
mkdir src
touch src/main.c
git add .
git commit -m init
ln -s src src-link
git add .
git commit -m "error on link to a dir"
git submodule add https://github.com/barrettruth/diffs.nvim
git commit -m "error on submodule init"
pushd diffs.nvim
git checkout @^
popd
git add .
git commit -m "error on submodule update"

Health check

==============================================================================
diffs:                                                                      ✅

diffs.nvim ~
- ✅ OK Neovim 0.9.0+ detected
- ✅ OK vim-fugitive detected
- libvscode_diff not found (optional, using native vim.diff fallback)

Minimal reproduction

vim.env.LAZY_STDPATH = '.repro'
load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))()
require('lazy').setup({
  spec = {
    { 'barrettruth/midnight.nvim', lazy = false, config = function() vim.cmd.colorscheme('midnight') end },
    { 'NeogitOrg/neogit', dependencies = { 'nvim-lua/plenary.nvim' } },
    {
      'barrettruth/diffs.nvim',
      init = function()
        vim.g.diffs = {
          debug = '/tmp/diffs.log',
          integrations = {
            neogit = true,
          },
        }
      end,
    },
  },
})
> Original issue: barrettruth/diffs.nvim#189 > Original author: `achmutov` > Original date: 2026-03-13T09:49:57Z ### Prerequisites - [x] I have searched [existing issues](https://github.com/barrettruth/diffs.nvim/issues) - [x] I have updated to the latest version ### Neovim version ```text NVIM v0.11.4 Build type: Release LuaJIT 2.1.1731601260 Run "nvim -V1 -v" for more info ``` ### Operating system Gentoo Linux x86_64 ### Description When a commit contains submodule init/update or a symlink to a directory, an exception is raised: ``` Decoration provider "buf" (ns=diffs): Lua: ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:355: Is a directory stack traceback: [C]: in function '(for generator)' ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:355: in function 'read_file_lines' ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:376: in function 'compute_hunk_context' ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:435: in function 'ensure_cache' ...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:911: in function <...redacted/.local/share/nvim/lazy/diffs.nvim/lua/diffs/init.lua:906> ``` Adding a guard before reading the file seems to fix the issue: ```diff diff --git a/lua/diffs/init.lua b/lua/diffs/init.lua index 1244a3a..a6d7418 100644 --- a/lua/diffs/init.lua +++ b/lua/diffs/init.lua @@ -333,6 +333,9 @@ end ---@param path string ---@return string[]? local function read_file_lines(path) + if vim.fn.isdirectory(path) then + return nil + end local f = io.open(path, 'r') if not f then return nil ``` but you might want to check it yourself / add tests ### Steps to reproduce Create `repro.git` repository in current directory: ```bash mkdir repro.git && cd repro.git git init mkdir src touch src/main.c git add . git commit -m init ln -s src src-link git add . git commit -m "error on link to a dir" git submodule add https://github.com/barrettruth/diffs.nvim git commit -m "error on submodule init" pushd diffs.nvim git checkout @^ popd git add . git commit -m "error on submodule update" ``` ### Health check ```text ============================================================================== diffs: ✅ diffs.nvim ~ - ✅ OK Neovim 0.9.0+ detected - ✅ OK vim-fugitive detected - libvscode_diff not found (optional, using native vim.diff fallback) ``` ### Minimal reproduction ```lua vim.env.LAZY_STDPATH = '.repro' load(vim.fn.system('curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua'))() require('lazy').setup({ spec = { { 'barrettruth/midnight.nvim', lazy = false, config = function() vim.cmd.colorscheme('midnight') end }, { 'NeogitOrg/neogit', dependencies = { 'nvim-lua/plenary.nvim' } }, { 'barrettruth/diffs.nvim', init = function() vim.g.diffs = { debug = '/tmp/diffs.log', integrations = { neogit = true, }, } end, }, }, }) ```
barrettruth 2026-09-21 18:12:03 +00:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

Original comment: barrettruth/diffs.nvim#189, comment 4054358937
Original author: barrettruth
Original date: 2026-03-13T11:14:00Z

Thank you for the rigorous issue. Doing this made everything a lot easier to figure out. I am looking into it now.

> Original comment: barrettruth/diffs.nvim#189, comment 4054358937 > Original author: `barrettruth` > Original date: 2026-03-13T11:14:00Z Thank you for the rigorous issue. Doing this made everything a lot easier to figure out. I am looking into it now.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
barrettruth/diffs.nvim#84
No description provided.