Skip to content

[Bug] can't open files with path containing the $ character #556

Open
@bryankenote

Description

@bryankenote

Description

Files with a path containing a $ character are not loaded in diffview. There are frontend routing frameworks that use the $ character for file-based routing.

Expected behavior

Files with a path containing a $ character can be viewed in diffview like any other file.

Actual behavior

Diffview seems to show the file under a path without the $ character. For example a file at the path $b/c would become b/c. Diffview will show this as a file that has been removed because it doesn't exist on disk. gf will show the error

File does not exist on disk: 'b/c'

Steps to reproduce

  1. mkdir -p a/\$b
  2. cd a
  3. git init
  4. touch \$b/c
  5. nvim \$b/c
  6. :DiffviewOpen
  7. gf

Health check

Output of :checkhealth diffview
==============================================================================
diffview: require("diffview.health").check()

Checking plugin dependencies ~
- OK nvim-web-devicons installed.

Checking VCS tools ~
- The plugin requires at least one of the supported VCS tools to be valid.
- OK Git found.
- OK Git is up-to-date. (2.48.1)
- WARNING Configured `hg_cmd` is not executable: 'hg'

Log info

Relevant info from :DiffviewLog
[ERROR 2025-02-19 11:41:32.311 -0800] ...cal/share/nvim/lazy/diffview.nvim/lua/diffview/utils.lua:42: File does not exist on disk: 'b/c'

Neovim version

NVIM v0.10.4
Build type: Release
LuaJIT 2.1.1713484068

Operating system and version

macOS Sonoma 14.4.1

Minimal config

-- #######################################
-- ### USAGE: nvim --clean -u mini.lua ###
-- #######################################

local root = vim.fn.stdpath("run") .. "/nvim/diffview.nvim"
local plugin_dir = root .. "/plugins"
vim.fn.mkdir(plugin_dir, "p")

for _, name in ipairs({ "config", "data", "state", "cache" }) do
  vim.env[("XDG_%s_HOME"):format(name:upper())] = root .. "/" .. name
end

local plugins = {
  { "nvim-web-devicons", url = "https://github.com/nvim-tree/nvim-web-devicons.git" },
  { "diffview.nvim", url = "https://github.com/sindrets/diffview.nvim.git" },
  -- ##################################################################
  -- ### ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##################################################################
}

for _, spec in ipairs(plugins) do
  local install_path = plugin_dir .. "/" .. spec[1]
  if vim.fn.isdirectory(install_path) ~= 1 then
    if spec.url then
      print(string.format("Installing '%s'...", spec[1]))
      vim.fn.system({ "git", "clone", "--depth=1", spec.url, install_path })
    end
  end
  vim.opt.runtimepath:append(spec.path or install_path)
end

require("diffview").setup({
  -- ##############################################################################
  -- ### ADD DIFFVIEW.NVIM CONFIG THAT IS _NECESSARY_ FOR REPRODUCING THE ISSUE ###
  -- ##############################################################################
})

vim.opt.termguicolors = true
vim.cmd("colorscheme " .. (vim.fn.has("nvim-0.8") == 1 and "habamax" or "slate"))

-- ############################################################################
-- ### ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE ###
-- ############################################################################

print("Ready!")

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions