diff --git a/lua/gitsigns/actions.lua b/lua/gitsigns/actions.lua index 5290c195d..198c4afd0 100644 --- a/lua/gitsigns/actions.lua +++ b/lua/gitsigns/actions.lua @@ -1122,11 +1122,10 @@ M.diffthis = function(base, opts) base = tostring(base) end opts = opts or {} - local diffthis = require('gitsigns.diffthis') if not opts.vertical then opts.vertical = config.diff_opts.vertical end - diffthis.diffthis(base, opts) + require('gitsigns.diffthis').diffthis(base, opts) end C.diffthis = function(args, params) diff --git a/lua/gitsigns/attach.lua b/lua/gitsigns/attach.lua index d8e1c301b..f99650746 100644 --- a/lua/gitsigns/attach.lua +++ b/lua/gitsigns/attach.lua @@ -62,35 +62,35 @@ local function parse_gitsigns_uri(name) end --- @param bufnr integer ---- @return string, string? +--- @return string buffer +--- @return string? commit +--- @return boolean? force_attach local function get_buf_path(bufnr) local file = uv.fs_realpath(api.nvim_buf_get_name(bufnr)) or api.nvim_buf_call(bufnr, function() return vim.fn.expand('%:p') end) - if not vim.wo.diff then - if vim.startswith(file, 'fugitive://') then - local path, commit = parse_fugitive_uri(file) - dprintf("Fugitive buffer for file '%s' from path '%s'", path, file) - if path then - local realpath = uv.fs_realpath(path) - if realpath then - return realpath, commit - end - end - end - - if vim.startswith(file, 'gitsigns://') then - local path, commit = parse_gitsigns_uri(file) - dprintf("Gitsigns buffer for file '%s' from path '%s'", path, file) + if vim.startswith(file, 'fugitive://') then + local path, commit = parse_fugitive_uri(file) + dprintf("Fugitive buffer for file '%s' from path '%s'", path, file) + if path then local realpath = uv.fs_realpath(path) if realpath then - return realpath, commit + return realpath, commit, true end end end + if vim.startswith(file, 'gitsigns://') then + local path, commit = parse_gitsigns_uri(file) + dprintf("Gitsigns buffer for file '%s' from path '%s' on commit '%s'", path, file, commit) + local realpath = uv.fs_realpath(path) + if realpath then + return realpath, commit, true + end + end + return file end @@ -271,12 +271,14 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd) return end - if vim.bo[cbuf].buftype ~= '' then + local force_attach + file, commit, force_attach = get_buf_path(cbuf) + + if vim.bo[cbuf].buftype ~= '' and not force_attach then dprint('Non-normal buffer') return end - file, commit = get_buf_path(cbuf) local file_dir = util.dirname(file) if not file_dir or not util.path_exists(file_dir) then diff --git a/lua/gitsigns/diffthis.lua b/lua/gitsigns/diffthis.lua index a2ff8fa82..7b8b0567f 100644 --- a/lua/gitsigns/diffthis.lua +++ b/lua/gitsigns/diffthis.lua @@ -45,6 +45,7 @@ local function bufread(bufnr, dbufnr, base) vim.bo[dbufnr].modifiable = modifiable vim.bo[dbufnr].modified = false + require('gitsigns.attach').attach(dbufnr, nil, 'BufReadCmd') end --- @param bufnr integer