nvim-neo-tree / neo-tree.nvim

Neovim plugin to manage the file system and other tree like structures.
MIT License
3.89k stars 225 forks source link

Git status colors not working #457

Closed Pernick closed 2 years ago

Pernick commented 2 years ago

Hello, I am trying to get git status color working for some time without any luck.

I am attaching init.lua which replicates the issue for me. No matter what git changes I do in the repository, it is not shown in the tree, nor when I do :Neotree git_status.

Changing colorscheme, terminal emulators nor disabling tmux did not have any effect. Probably just some issue with the configuration I am using.

Any help with how to debug this would be appreciated. Thank you.

Reproduction:

minimal_init.lua ``` -- `minimal_init.lua` used for reproducible configuration -- Open with `nvim --clean -u minimal_init.lua` local is_windows = vim.fn.has("win32") == 1 local function join(...) local sep = is_windows and "\\" or "/" return table.concat({ ... }, sep) end local root_tmp = is_windows and os.getenv("TEMP") or "/tmp" local site_path = join(root_tmp, "nvim", "site") local pack_path = join(site_path, "pack") local install_path = join(pack_path, "packer", "start", "packer.nvim") local compile_path = join(install_path, "plugin", "packer_compiled.lua") vim.opt.packpath = site_path local function load_plugins() local packer = require("packer") local use = packer.use packer.reset() packer.init({ compile_path = compile_path, package_root = pack_path }) use("wbthomason/packer.nvim") use("EdenEast/nightfox.nvim") -- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE use { "nvim-neo-tree/neo-tree.nvim", branch = "v2.x", requires = { "nvim-lua/plenary.nvim", "kyazdani42/nvim-web-devicons", -- not strictly required, but recommended "MunifTanjim/nui.nvim", } } packer.install() end _G.load_config = function() -- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE require("neo-tree").setup({ enable_git_status = true, default_component_configs = { indent = { padding = 1, with_expanders = false, }, icon = { folder_closed = "", folder_open = "", folder_empty = "", default = "", }, modified = { symbol = "[+]", highlight = "NeoTreeModified", }, name = { trailing_slash = false, use_git_status_colors = true, highlight = "NeoTreeFileName", }, git_status = { symbols = { added = "", deleted = "", modified = "", renamed = "➜", untracked = "★", ignored = "◌", unstaged = "✗", staged = "✓", conflict = "", }, }, }, }) require("nightfox").setup({ modules = { neotree = true } }) vim.cmd("colorscheme nordfox") end if vim.fn.isdirectory(install_path) == 0 then vim.fn.system({ "git", "clone", "--depth=1", "https://github.com/wbthomason/packer.nvim", install_path }) end load_plugins() vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]) ```

Screenshot

Screenshot 2022-07-25 at 22 48 58
cseickel commented 2 years ago

This should work with the default config of Neo-tree. I noticed two things of interest here:

  1. The terminal is in ~/c/test-repo while the Neo-tree working directory is ~/code/test-repo. Is there some kind of symlinking, WSL, or docker volumes going on here?
  2. I see you are using fish. The git status functionality is actually handled by running commands on the system shell and maybe those commands are not working on your system. Can you try setting your shell to something else? I think there is a setting within vim itself.

Odds are you will see some errors related to git if you turn on logging and take a look. See here for instructions on how to do that: https://github.com/nvim-neo-tree/neo-tree.nvim/wiki/Troubleshooting

Pernick commented 2 years ago
  1. No symlinking involved, just a shortened folder name.
  2. Great suggestion, just tried it with zsh, but still the same result.

I tried to go through the logs before, but I only focused on ERROR labels, which there were none.

Going through it now more carefully I see some interesting things:

[TRACE Tue Jul 26 09:32:55 2022] ...pack/packer/opt/neo-tree.nvim/lua/neo-tree/git/utils.lua:22: GIT ROOT for ' /Users/mypcname/code/test-repo ' is ' /Users/mypcname/code/test-repo '
[TRACE Tue Jul 26 09:32:55 2022] ...ack/packer/opt/neo-tree.nvim/lua/neo-tree/git/status.lua:205: git.status.status_async called
[DEBUG Tue Jul 26 09:32:55 2022] ...ack/packer/opt/neo-tree.nvim/lua/neo-tree/git/status.lua:315: git status.showUntrackedFiles = fatal: cannot change to '?[H?[J/Users/mypcname/code/test-repo': No such file or directory

Can you confirm that the git root should not look like this?

EDIT: Perhaps I should have mentioned I am doing this on macOS with M1 chip if it helps ring any bells.

cseickel commented 2 years ago

Can you confirm that the git root should not look like this?

That's definitely the problem. Here is what it should look like:

[TRACE Tue Jul 26 01:21:24 2022] ...ck/packer/start/neo-tree.nvim/lua/neotree/git/utils.lua:22: GIT ROOT for ' /home/cseickel/dotfiles ' is ' /home/cseickel/dotfiles '

It looks like you have some escape codes mixed in. Is there anything unusual about how the output of git commands is displayed on your system? What does this command show?

git -C /Users/mypcname/code/test-repo rev-parse --show-toplevel

2. Great suggestion, just tried it with zsh, but still the same result.

Perhaps sh is the safest option. Can you try adding this to your config?

set shell=/bin/sh

(assuming it's available and at the same location on a Mac)

Pernick commented 2 years ago

Thank you! I will continue with the assumption that the issue lies in the git root setting.

This outputs nothing unusual:

$ git -C /Users/mypcname/code/test-repo rev-parse --show-toplevel
> /Users/mypcname/code/test-repo

I tried with sh as well and the git root is the same. It seems it is safe to assume the shell has nothing to do with this (so far).

I will try to dig around more this evening and post update.

cseickel commented 2 years ago

Does it actually include the > character before the output of the folder name? Does the output have color, bold, or italics? If so then that could be the problem.

Here is what I get: image

Pernick commented 2 years ago

No it does not. Just the string, no color/bold/italics. The output looks same as yours (different path of course).

cseickel commented 2 years ago

Can you switch to the main branch and tell me if it works now?

Pernick commented 2 years ago

It does! Thank you for the effort, I haven't even had the chance to dig around myself.

EDIT: I was about to comment the git_status is not working, but you beat me to it with a fix. 👍