fix: bug copying file multiple times
This commit is contained in:
parent
8f0bf3789f
commit
05cb8257cb
4 changed files with 47 additions and 29 deletions
|
|
@ -68,8 +68,6 @@ M.create_actions_from_diffs = function(all_diffs)
|
||||||
table.insert(actions, action)
|
table.insert(actions, action)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
---@type table<integer, string>
|
|
||||||
local dest_by_id = {}
|
|
||||||
for bufnr, diffs in pairs(all_diffs) do
|
for bufnr, diffs in pairs(all_diffs) do
|
||||||
local adapter = util.get_adapter(bufnr)
|
local adapter = util.get_adapter(bufnr)
|
||||||
if not adapter then
|
if not adapter then
|
||||||
|
|
@ -80,7 +78,9 @@ M.create_actions_from_diffs = function(all_diffs)
|
||||||
if diff.type == "new" then
|
if diff.type == "new" then
|
||||||
if diff.id then
|
if diff.id then
|
||||||
local by_id = diff_by_id[diff.id]
|
local by_id = diff_by_id[diff.id]
|
||||||
dest_by_id[diff.id] = parent_url .. diff.name
|
---HACK: set the destination on this diff for use later
|
||||||
|
---@diagnostic disable-next-line: inject-field
|
||||||
|
diff.dest = parent_url .. diff.name
|
||||||
table.insert(by_id, diff)
|
table.insert(by_id, diff)
|
||||||
else
|
else
|
||||||
-- Parse nested files like foo/bar/baz
|
-- Parse nested files like foo/bar/baz
|
||||||
|
|
@ -145,7 +145,9 @@ M.create_actions_from_diffs = function(all_diffs)
|
||||||
add_action({
|
add_action({
|
||||||
type = i == #diffs and "move" or "copy",
|
type = i == #diffs and "move" or "copy",
|
||||||
entry_type = entry[FIELD_TYPE],
|
entry_type = entry[FIELD_TYPE],
|
||||||
dest_url = dest_by_id[diff.id],
|
---HACK: access the dest field we set above
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
|
dest_url = diff.dest,
|
||||||
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
|
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
@ -164,7 +166,9 @@ M.create_actions_from_diffs = function(all_diffs)
|
||||||
type = "copy",
|
type = "copy",
|
||||||
entry_type = entry[FIELD_TYPE],
|
entry_type = entry[FIELD_TYPE],
|
||||||
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
|
src_url = cache.get_parent_url(id) .. entry[FIELD_NAME],
|
||||||
dest_url = dest_by_id[diff.id],
|
---HACK: access the dest field we set above
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
|
dest_url = diff.dest,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ a.describe("regression tests", function()
|
||||||
a.after_each(function()
|
a.after_each(function()
|
||||||
if tmpdir then
|
if tmpdir then
|
||||||
tmpdir:dispose()
|
tmpdir:dispose()
|
||||||
a.util.scheduler()
|
|
||||||
tmpdir = nil
|
tmpdir = nil
|
||||||
end
|
end
|
||||||
test_util.reset_editor()
|
test_util.reset_editor()
|
||||||
|
|
@ -117,4 +116,19 @@ a.describe("regression tests", function()
|
||||||
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
test_util.wait_for_autocmd({ "User", pattern = "OilEnter" })
|
||||||
assert.are.same({ bufnr }, require("oil.view").get_all_buffers())
|
assert.are.same({ bufnr }, require("oil.view").get_all_buffers())
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
a.it("can copy a file multiple times", function()
|
||||||
|
test_util.actions.open({ tmpdir.path })
|
||||||
|
vim.api.nvim_feedkeys("ifoo.txt", "x", true)
|
||||||
|
test_util.actions.save()
|
||||||
|
vim.api.nvim_feedkeys("yyp$ciWbar.txt", "x", true)
|
||||||
|
vim.api.nvim_feedkeys("yyp$ciWbaz.txt", "x", true)
|
||||||
|
test_util.actions.save()
|
||||||
|
assert.are.same({ "bar.txt", "baz.txt", "foo.txt" }, test_util.parse_entries(0))
|
||||||
|
tmpdir:assert_fs({
|
||||||
|
["foo.txt"] = "",
|
||||||
|
["bar.txt"] = "",
|
||||||
|
["baz.txt"] = "",
|
||||||
|
})
|
||||||
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
|
|
@ -114,4 +114,18 @@ M.actions = {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
---Get the raw list of filenames from an unmodified oil buffer
|
||||||
|
---@param bufnr? integer
|
||||||
|
---@return string[]
|
||||||
|
M.parse_entries = function(bufnr)
|
||||||
|
bufnr = bufnr or 0
|
||||||
|
if vim.bo[bufnr].modified then
|
||||||
|
error("parse_entries doesn't work on a modified oil buffer")
|
||||||
|
end
|
||||||
|
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
||||||
|
return vim.tbl_map(function(line)
|
||||||
|
return line:match("^/%d+ +(.+)$")
|
||||||
|
end, lines)
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,6 @@ require("plenary.async").tests.add_to_env()
|
||||||
local TmpDir = require("tests.tmpdir")
|
local TmpDir = require("tests.tmpdir")
|
||||||
local test_util = require("tests.test_util")
|
local test_util = require("tests.test_util")
|
||||||
|
|
||||||
---Get the raw list of filenames from an unmodified oil buffer
|
|
||||||
---@param bufnr? integer
|
|
||||||
---@return string[]
|
|
||||||
local function parse_entries(bufnr)
|
|
||||||
bufnr = bufnr or 0
|
|
||||||
if vim.bo[bufnr].modified then
|
|
||||||
error("parse_entries doesn't work on a modified oil buffer")
|
|
||||||
end
|
|
||||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)
|
|
||||||
return vim.tbl_map(function(line)
|
|
||||||
return line:match("^/%d+ +(.+)$")
|
|
||||||
end, lines)
|
|
||||||
end
|
|
||||||
|
|
||||||
a.describe("freedesktop", function()
|
a.describe("freedesktop", function()
|
||||||
local tmpdir
|
local tmpdir
|
||||||
local tmphome
|
local tmphome
|
||||||
|
|
@ -50,7 +36,7 @@ a.describe("freedesktop", function()
|
||||||
tmpdir:assert_not_exists("a.txt")
|
tmpdir:assert_not_exists("a.txt")
|
||||||
tmpdir:assert_exists("foo/b.txt")
|
tmpdir:assert_exists("foo/b.txt")
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("deleting a file moves it to trash", function()
|
a.it("deleting a file moves it to trash", function()
|
||||||
|
|
@ -62,7 +48,7 @@ a.describe("freedesktop", function()
|
||||||
tmpdir:assert_not_exists("a.txt")
|
tmpdir:assert_not_exists("a.txt")
|
||||||
tmpdir:assert_exists("foo/b.txt")
|
tmpdir:assert_exists("foo/b.txt")
|
||||||
test_util.actions.open({ "--trash", tmpdir.path })
|
test_util.actions.open({ "--trash", tmpdir.path })
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("deleting a directory moves it to trash", function()
|
a.it("deleting a directory moves it to trash", function()
|
||||||
|
|
@ -74,7 +60,7 @@ a.describe("freedesktop", function()
|
||||||
tmpdir:assert_not_exists("foo")
|
tmpdir:assert_not_exists("foo")
|
||||||
tmpdir:assert_exists("a.txt")
|
tmpdir:assert_exists("a.txt")
|
||||||
test_util.actions.open({ "--trash", tmpdir.path })
|
test_util.actions.open({ "--trash", tmpdir.path })
|
||||||
assert.are.same({ "foo/" }, parse_entries(0))
|
assert.are.same({ "foo/" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("deleting a file from trash deletes it permanently", function()
|
a.it("deleting a file from trash deletes it permanently", function()
|
||||||
|
|
@ -89,7 +75,7 @@ a.describe("freedesktop", function()
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
tmpdir:assert_not_exists("a.txt")
|
tmpdir:assert_not_exists("a.txt")
|
||||||
assert.are.same({}, parse_entries(0))
|
assert.are.same({}, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("cannot create files in the trash", function()
|
a.it("cannot create files in the trash", function()
|
||||||
|
|
@ -102,7 +88,7 @@ a.describe("freedesktop", function()
|
||||||
vim.api.nvim_feedkeys("onew_file.txt", "x", true)
|
vim.api.nvim_feedkeys("onew_file.txt", "x", true)
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("cannot rename files in the trash", function()
|
a.it("cannot rename files in the trash", function()
|
||||||
|
|
@ -115,7 +101,7 @@ a.describe("freedesktop", function()
|
||||||
vim.api.nvim_feedkeys("0facwnew_name", "x", true)
|
vim.api.nvim_feedkeys("0facwnew_name", "x", true)
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("cannot copy files in the trash", function()
|
a.it("cannot copy files in the trash", function()
|
||||||
|
|
@ -128,7 +114,7 @@ a.describe("freedesktop", function()
|
||||||
vim.api.nvim_feedkeys("yypp", "x", true)
|
vim.api.nvim_feedkeys("yypp", "x", true)
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("can restore files from trash", function()
|
a.it("can restore files from trash", function()
|
||||||
|
|
@ -143,7 +129,7 @@ a.describe("freedesktop", function()
|
||||||
vim.api.nvim_feedkeys("p", "x", true)
|
vim.api.nvim_feedkeys("p", "x", true)
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.reload()
|
test_util.actions.reload()
|
||||||
assert.are.same({ "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt" }, test_util.parse_entries(0))
|
||||||
tmpdir:assert_fs({
|
tmpdir:assert_fs({
|
||||||
["a.txt"] = "a.txt",
|
["a.txt"] = "a.txt",
|
||||||
})
|
})
|
||||||
|
|
@ -159,6 +145,6 @@ a.describe("freedesktop", function()
|
||||||
vim.api.nvim_feedkeys("dd", "x", true)
|
vim.api.nvim_feedkeys("dd", "x", true)
|
||||||
test_util.actions.save()
|
test_util.actions.save()
|
||||||
test_util.actions.open({ "--trash", tmpdir.path })
|
test_util.actions.open({ "--trash", tmpdir.path })
|
||||||
assert.are.same({ "a.txt", "a.txt" }, parse_entries(0))
|
assert.are.same({ "a.txt", "a.txt" }, test_util.parse_entries(0))
|
||||||
end)
|
end)
|
||||||
end)
|
end)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue