Skip to content

Commit

Permalink
fix: process deletes in dir before moving dir
Browse files Browse the repository at this point in the history
  • Loading branch information
stevearc committed Aug 26, 2024
1 parent a632c89 commit 349bca8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lua/oil/mutator/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,10 @@ M.enforce_action_order = function(actions)
-- Process children before moving
-- e.g. NEW /a/b BEFORE MOVE /a -> /b
dest_trie:accum_children_of(action.src_url, ret)
-- Copy children before moving parent dir
-- Process children before moving parent dir
-- e.g. COPY /a/b -> /b BEFORE MOVE /a -> /d
src_trie:accum_children_of(action.src_url, ret, function(a)
return a.type == "copy"
end)
-- e.g. CHANGE /a/b BEFORE MOVE /a -> /d
src_trie:accum_children_of(action.src_url, ret)
-- Process remove path before moving to new path
-- e.g. MOVE /a -> /b BEFORE MOVE /c -> /a
src_trie:accum_actions_at(action.dest_url, ret, function(a)
Expand Down
20 changes: 20 additions & 0 deletions tests/mutator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,26 @@ a.describe("mutator", function()
assert.are.same({ move1, move2 }, ordered_actions)
end)

it("Handles a delete inside a moved folder", function()
-- delete in directory and move directory
-- DELETE /a/b.txt
-- MOVE /a/ -> /b/
local del = {
type = "delete",
url = "oil-test:///a/b.txt",
entry_type = "file",
}
local move = {
type = "move",
src_url = "oil-test:///a",
dest_url = "oil-test:///b",
entry_type = "directory",
}
local actions = { move, del }
local ordered_actions = mutator.enforce_action_order(actions)
assert.are.same({ del, move }, ordered_actions)
end)

it("Detects move directory loops", function()
local move = {
type = "move",
Expand Down

0 comments on commit 349bca8

Please # to comment.