lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
5.19k stars 191 forks source link

Gitsigns not working with yadm #754

Closed hqkhan closed 1 year ago

hqkhan commented 1 year ago

Description

I have a yadm repo. Path to repo is~/dots/yadm-repo which I have as an env var, YADM_REPO. Git signs works great for me normally but doesn't with yadm.

Because of my repo location, I have a shell script in ~/bin/yadm whose contents are:

#!/bin/sh
$HOME/dots/yadm-project/yadm --yadm-repo ${YADM_REPO} "$@"

In terminal, yadm ls-files works fine. It also works in neovim when I issue :!yadm ls-files. I can see all the files. However, gitsigns doesn't show me anything. I'm not sure what I'm missing.

I was originally using nvim version 0.9-dev. I noticed on gitsigns that dev builds can have weird behaviors and moved to stable 0.8.3 but the issue didn't fix itself.

Neovim version

NVIM v0.8.3

Operating system and version

AL2_x86

Expected behavior

Expected behavior would be to have gitsigns for files tracked by my yadm repo.

Actual behavior

image

The above image shows changes to lazy_bootstrap.lua.

image

The above image is at the changed line with nothing on the gitgutter.

Minimal config

vim.o.packpath = '/tmp/nvim/site'

local plugins = {
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim'
}

for name, url in pairs(plugins) do
  local install_path = '/tmp/nvim/site/pack/test/start/'..name
  if vim.fn.isdirectory(install_path) == 0 then
    vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
  end
end

require('gitsigns').setup{
    debug_mode = true,
    signs          = {
      add          = { text = "┃" },
      change       = { text = "┃" },
      delete       = { text = "_" },
      topdelete    = { text = "‾" },
      changedelete = { text = "~" },
      untracked    = { text = "┆" },
    },
    signcolumn     = true, -- Toggle with `:Gitsigns toggle_signs`
    numhl          = false, -- Toggle with `:Gitsigns toggle_numhl`
    linehl         = false, -- Toggle with `:Gitsigns toggle_linehl`
    word_diff      = false, -- Toggle with `:Gitsigns toggle_word_diff`
    sign_priority  = 4, -- Lower priorirty means diag signs supercede
    preview_config = { border = "rounded" },
    yadm           = { enable = true, },
    on_attach      = function(bufnr)
      local gs = package.loaded.gitsigns

      local function map(mode, l, r, opts)
        opts = opts or {}
        opts.buffer = bufnr
        vim.keymap.set(mode, l, r, opts)
      end

      map("n", "]c", function()
        if vim.wo.diff then return "]c" end
        vim.schedule(function() gs.next_hunk() end)
        return "<Ignore>"
      end, { expr = true, desc = "Next hunk" })

      map("n", "[c", function()
        if vim.wo.diff then return "[c" end
        vim.schedule(function() gs.prev_hunk() end)
        return "<Ignore>"
      end, { expr = true, desc = "Previous hunk" })

      -- Actions
      map({ "n", "v" }, "<leader>hr", '<cmd>lua require("gitsigns").reset_hunk()<CR>',
        { desc = "reset hunk" })
      map("n", "<leader>hS", '<cmd>lua require("gitsigns").stage_buffer()<CR>',
        { desc = "stage buffer" })
      map({ "n", "v" }, "<leader>hs", '<cmd>lua require("gitsigns").stage_hunk()<CR>',
        { desc = "stage hunk" })
      map("n", "<leader>hu", '<cmd>lua require("gitsigns").undo_stage_hunk()<CR>',
        { desc = "undo stage hunk" })
      -- doesn't exist yet
      -- map('n', '<leader>hU', '<cmd>lua require("gitsigns").undo_stage_buffer()<CR>')
      map("n", "<leader>hR", '<cmd>lua require("gitsigns").reset_buffer()<CR>',
        { desc = "reset buffer" })
      map("n", "<leader>hp", '<cmd>lua require("gitsigns").preview_hunk()<CR>',
        { desc = "preview hunk" })
      map("n", "<leader>hb", '<cmd>lua require("gitsigns").blame_line({full=true})<CR>',
        { desc = "line blame (popup)" })
      map("n", "<leader>hB", '<cmd>lua require("gitsigns").toggle_current_line_blame()<CR>',
        { desc = "line blame (toggle)" })
      map("n", "<leader>hd", '<cmd>lua require("gitsigns").diffthis()<CR>',
        { desc = "diff against the index" })
      map("n", "<leader>hD", '<cmd>lua require("gitsigns").diffthis("~1")<CR>',
        { desc = "diff against previous commit" })
      map("n", "<leader>hx", '<cmd>lua require("gitsigns").toggle_deleted()<CR>',
        { desc = "toggle deleted lines" })

      -- Text object
      map({ "o", "x" }, "ih", ":<C-U>Gitsigns select_hunk<CR>")
    end

}

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

Steps to reproduce

  1. nvim --clean -u minimal.lua
  2. ...

Gitsigns debug messages

image

The above image shows relevant debug messages saying the file isn't in git repo.

image

The above image shows the command yadm ls-files | rg boostrap being ran from inside nvim. The file lazy_bootstrap.lua has been edited as shown in the images above.

hqkhan commented 1 year ago

Mistake was on my end. Found out that my /home/user was a symlink to /local/home/user so yadm wasn't being picked up.