Fixes #888
This commit is contained in:
Lewis Russell 2023-10-03 15:48:32 +01:00 committed by Lewis Russell
parent b14b9fba7d
commit 2272cf9f0c
4 changed files with 62 additions and 4 deletions

View File

@ -68,7 +68,7 @@ local function apply_win_signs(bufnr, top, bot, clear)
return
end
local untracked = bcache.git_obj.object_name == nil and bcache.base ~= 'FILE'
local untracked = bcache.git_obj.object_name == nil and not bcache.base
apply_win_signs0(bufnr, signs_normal, bcache.hunks, top, bot, clear, untracked)
if signs_staged then
apply_win_signs0(bufnr, signs_staged, bcache.hunks_staged, top, bot, clear, false)

View File

@ -34,7 +34,7 @@ local eq = helpers.eq
helpers.env()
describe('gitsigns', function()
describe('gitsigns (with screen)', function()
local screen --- @type NvimScreen
local config --- @type table
@ -740,3 +740,44 @@ describe('gitsigns', function()
end)
end)
describe('gitsigns', function()
local config --- @type table
before_each(function()
clear()
-- Make gitisigns available
exec_lua('package.path = ...', package.path)
config = vim.deepcopy(test_config)
command('cd '..system{"dirname", os.tmpname()})
end)
after_each(function()
cleanup()
end)
it('handle #888', function()
setup_test_repo()
local path1 = scratch..'/cargo.toml'
local subdir = scratch..'/subdir'
local path2 = subdir..'/cargo.toml'
write_to_file(path1, {'some text'})
git{'add', path1}
git{'commit', '-m', 'add cargo'}
-- move file and stage move
system{'mkdir', subdir}
system{'mv', path1, path2}
git{'add', path1, path2}
config.base = 'HEAD'
setup_gitsigns(config)
edit(path1)
command("write")
helpers.sleep(100)
end)
end)

View File

@ -88,7 +88,9 @@ function M.setup_git()
M.gitf{'config', 'init.defaultBranch', 'master'}
end
---@param opts? {test_file_text?: string[], no_add?: boolean}
--- Setup a basic git repository in directory `helpers.scratch` with a single file
--- `helpers.test_file` committed.
--- @param opts? {test_file_text?: string[], no_add?: boolean}
function M.setup_test_repo(opts)
local text = opts and opts.test_file_text or test_file_text
M.cleanup()
@ -122,6 +124,8 @@ function M.edit(path)
helpers.command("edit " .. path)
end
--- @param path string
--- @param text string[]
function M.write_to_file(path, text)
local f = assert(io.open(path, 'wb'))
for _, l in ipairs(text) do
@ -232,7 +236,7 @@ function M.setup_gitsigns(config, on_attach)
return false
end
end
require('gitsigns').setup(...)
require('gitsigns').setup(config)
]], config, on_attach)
M.expectf(function()
return exec_lua[[return require'gitsigns'._setup_done == true]]

View File

@ -388,6 +388,19 @@ function M.clear()
check_close()
local child_stream = ProcessStream.spawn(nvim_argv)
session = Session.new(child_stream)
local status, info = session:request('nvim_get_api_info')
assert(status)
assert(session:request('nvim_exec_lua', [[
local channel = ...
local orig_error = error
function error(...)
vim.rpcnotify(channel, 'nvim_error_event', debug.traceback(), ...)
return orig_error(...)
end
]], {info[1]}))
end
---@param ... string