Skip to content

Bug: branch component not displaying when opening files via snacks.nvim #1452

@vaspadi

Description

@vaspadi

Self Checks

  • [ x] I'm using the latest lualine.
  • [ x] I didn't find the issue in existing issues or PRs.

How to reproduce the problem

Install LazyVim (clean setup, no additional custom plugins).

  • Open a git project (run git init in any directory).
  • Open a file in a subdirectory using <leader><space> (subdir/file.lua).
  • Check lualine — the branch component is missing.
  • Open a file from the root directory (main.lua).
  • The branch component is shown as expected.

Expected behaviour

The branch component should always be visible.

Actual behaviour

When using snacks.nvim (the default file opener in LazyVim) to open files, the branch component is only visible if the file is opened from the top-level directory. If a file is opened from a subdirectory, the component disappears. If I use files.mini to open files, the issue does not occur.

Minimal config to reproduce the issue

I was using a clean installation of LazyVim and hadn’t made any custom configurations yet when I encountered the bug. The lualine configuration is the default one provided by LazyVim.

Additional information

neovim: v0.11.3
OS: Windows 11 Home
snacks.nvim: bc0630e
lualine.nvim: a94fc68

After some debugging, I found that the issue is related to path separator inconsistency.

  • snacks.nvim provides paths with / (Unix-style)
  • mini.files provides paths with \ (Windows-style)

This causes issues in this line in git_branch.lua, specifically in the find_git_dir method (line 78):

local file_dir = dir_path or vim.fn.expand('%:p:h')

The path being passed to further logic doesn't match what Git or libuv expects on Windows, so the branch isn't detected properly.

I fixed it locally by forcing backslashes:

local file_dir = dir_path or vim.fn.expand('%:p:h'):gsub('/', '\\')

But I believe this is a workaround and not an ideal long-term fix.

I originally created the issue in the LazyVim repository: LazyVim/LazyVim#6308.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions