lewis6991 / gitsigns.nvim

Git integration for buffers
MIT License
4.86k stars 186 forks source link

Blame Options for untracked file #1064

Closed daUnknownCoder closed 2 months ago

daUnknownCoder commented 2 months ago

Description

After the ! change, im experiencing this when using the current_line_blame_formatter

Neovim version

0.10.0

Operating system and version

6.7.9-arch1-1

Expected behavior

i also wanna ask if the file is untracked, can we show the blame as Untracked! ?

Actual behavior

there's a missing icon and it throws it...

current config: ```lua return { "lewis6991/gitsigns.nvim", enabled = vim.fn.executable("git") == 1, event = "LazyFile", keys = { { ";j", "lua require('gitsigns').next_hunk()", desc = "Next Hunk" }, { ";k", "lua require('gitsigns').prev_hunk()", desc = "Prev Hunk" }, { ";p", "lua require('gitsigns').preview_hunk()", desc = "Preview Hunk" }, { ";s", "lua require('gitsigns').stage_hunk()", desc = "Stage Hunk" }, { ";s", "lua require('gitsigns').stage_hunk({vim.fn.line('.'), vim.fn.line('v')})", desc = "Stage Hunk", mode = "v", }, { ";u", "lua require('gitsigns').undo_stage_hunk()", desc = "Undo Stage Hunk" }, { ";r", "lua require('gitsigns').reset_hunk()", desc = "Reset Hunk" }, { ";r", "lua require('gitsigns').reset_hunk({ vim.fn.line('.'), vim.fn.line('v') })", mode = "v", desc = "Reset Hunk", }, }, ft = { "gitcommit", "diff" }, config = function() vim.api.nvim_create_autocmd({ "BufReadPost" }, { group = vim.api.nvim_create_augroup("GitSignsLazyLoad", { clear = true }), callback = function() vim.fn.system("git -C " .. '"' .. vim.fn.expand("%:p:h") .. '"' .. " rev-parse") if vim.v.shell_error == 0 then vim.api.nvim_del_augroup_by_name("GitSignsLazyLoad") vim.schedule(function() require("lazy").load({ plugins = { "gitsigns.nvim" } }) end) end end, }) local icons_ok, icons = pcall(require, "NeutronVim.core.icons") if not icons_ok then print("Unable to import icons!") end local gitsigns_status_ok, gitsigns = pcall(require, "gitsigns") if not gitsigns_status_ok then print("Gitsigns not found!") end gitsigns.setup({ signs = { add = { text = "┃" }, change = { text = "┃" }, delete = { text = "_" }, topdelete = { text = "‾" }, changedelete = { text = "~" }, untracked = { text = "║" }, }, signcolumn = true, numhl = false, linehl = false, word_diff = false, watch_gitdir = { interval = 1000, follow_files = true, }, auto_attach = true, attach_to_untracked = true, current_line_blame = true, current_line_blame_opts = { virt_text = true, virt_text_pos = "eol", delay = 500, ignore_whitespace = true, }, current_line_blame_formatter = function(name, blame_info, opts) if blame_info.author == name then blame_info.author = "You" end local text if blame_info.author == "Not Committed Yet" then text = blame_info.author else local date_time if opts.relative_time then date_time = require("gitsigns.util").get_relative_time(tonumber(blame_info["author_time"])) else date_time = os.date("%R | %x", tonumber(blame_info["author_time"])) end text = string.format("%s, %s - %s", blame_info.author, date_time, blame_info.summary) end return { { icons.ui.GitHub .. " " .. text, "GitSignsCurrentLineBlame" } } end, sign_priority = 6, update_debounce = 100, status_formatter = nil, max_file_length = 40000, preview_config = { border = "rounded", style = "minimal", relative = "cursor", row = 0, col = 1, }, }) vim.api.nvim_set_hl(0, "GitSignsCurrentLineBlame", { link = "Comment" }) require("scrollbar.handlers.gitsigns").setup() end, } ```

the icons.ui.github -> (" ") is not coming and it throws the issue

Minimal config

for name, url in pairs{
  gitsigns = 'https://github.com/lewis6991/gitsigns.nvim',
} do
local install_path = vim.fn.fnamemodify('gitsigns_issue/'..name, ':p')
if vim.fn.isdirectory(install_path) == 0 then
vim.fn.system { 'git', 'clone', '--depth=1', url, install_path }
end
vim.opt.runtimepath:append(install_path)
end

require('gitsigns').setup{
  debug_mode = true, -- You must add this to enable debug messages
        current_line_blame_formatter = function(name, blame_info, opts)
        if blame_info.author == name then
          blame_info.author = "You"
        end
        local text
        if blame_info.author == "Not Committed Yet" then
          text = blame_info.author
        else
          local date_time
          if opts.relative_time then
            date_time = require("gitsigns.util").get_relative_time(tonumber(blame_info["author_time"]))
          else
            date_time = os.date("%R | %x", tonumber(blame_info["author_time"]))
          end
          text = string.format("%s, %s - %s", blame_info.author, date_time, blame_info.summary)
        end
        return { { " " .. text, "GitSignsCurrentLineBlame" } }
      end,
}

Steps to reproduce

i really dont know how to do the minimal config, but using that config into a committed before but has/does not have changes will suffice because its really the problem of line_blame or my config

Gitsigns debug messages

No response

Gitsigns cache

No response

lewis6991 commented 2 months ago

opts is no longer passed so you need to remove that from current_line_blame_formatter.

lewis6991 commented 2 months ago

https://github.com/lewis6991/gitsigns.nvim/commit/d03a1c9a1045122823af97e351719227ed3718eb will now also include the error in the message.

daUnknownCoder commented 2 months ago

opts is no longer passed so you need to remove that from current_line_blame_formatter.

so what should i use instead of opts?

can you send me the refactored code?

      current_line_blame_formatter = function(name, blame_info, opts)
        if blame_info.author == name then
          blame_info.author = "You"
        end
        local text
        if blame_info.author == "Not Committed Yet" then
          text = blame_info.author
        else
          local date_time
          if opts.relative_time then
            date_time = require("gitsigns.util").get_relative_time(tonumber(blame_info["author_time"]))
          else
            date_time = os.date("%R | %x", tonumber(blame_info["author_time"]))
          end
          text = string.format("%s, %s - %s", blame_info.author, date_time, blame_info.summary)
        end
        return { { icons.ui.GitHub .. " " .. text, "GitSignsCurrentLineBlame" } }
      end,

i also saw you mentioned that relative time is the default thing then how to remove it? and i would also like help for:

i also wanna ask if the file is untracked, can we show the blame as Untracked!?

daUnknownCoder commented 2 months ago

ok i got it working by doing this:

      current_line_blame_formatter = function(name, blame_info)
        if blame_info.author == name then
          blame_info.author = "You"
        end

        local text
        if blame_info.author == "Not Committed Yet" then
          text = blame_info.author
        else
          local date_time = require("gitsigns.util").get_relative_time(tonumber(blame_info["author_time"]))
          text = string.format("%s, %s - %s", blame_info.author, date_time, blame_info.summary)
        end

        return { { icons.ui.GitHub .. " " .. text, "GitSignsCurrentLineBlame" } }
      end,

but i still wanna want help for

if the file is untracked, can we show the blame as Untracked!?