diff --git a/lua/oil/mutator/init.lua b/lua/oil/mutator/init.lua index b4f52786..ab24a914 100644 --- a/lua/oil/mutator/init.lua +++ b/lua/oil/mutator/init.lua @@ -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) diff --git a/tests/mutator_spec.lua b/tests/mutator_spec.lua index 13349e20..17548d37 100644 --- a/tests/mutator_spec.lua +++ b/tests/mutator_spec.lua @@ -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",