cleanup: remove disclaimer before saving files
Oil has been around for a few months now and there haven't been any reports of unexpected filesystem operations.
This commit is contained in:
parent
6b05c2e913
commit
d0efcc0c10
4 changed files with 22 additions and 245 deletions
|
|
@ -1,75 +0,0 @@
|
|||
local config = require("oil.config")
|
||||
local fs = require("oil.fs")
|
||||
local ReplLayout = require("oil.repl_layout")
|
||||
local M = {}
|
||||
|
||||
M.show = function(callback)
|
||||
if config.silence_disclaimer then
|
||||
return callback(true)
|
||||
end
|
||||
local marker_file = fs.join(vim.fn.stdpath("cache"), ".oil_accepted_disclaimer")
|
||||
vim.loop.fs_stat(
|
||||
marker_file,
|
||||
vim.schedule_wrap(function(err, stat)
|
||||
if stat and stat.type and not err then
|
||||
callback(true)
|
||||
return
|
||||
end
|
||||
|
||||
local confirmation = "I understand this may destroy my files"
|
||||
local lines = {
|
||||
"WARNING",
|
||||
"This plugin has been tested thoroughly, but it is still new.",
|
||||
"There is a chance that there may be bugs that could lead to data loss.",
|
||||
"I recommend that you ONLY use it for files that are checked in to version control.",
|
||||
"",
|
||||
string.format('Please type: "%s" below', confirmation),
|
||||
"",
|
||||
}
|
||||
local hints = {
|
||||
"Try again",
|
||||
"Not quite!",
|
||||
"It's right there ^^^^^^^^^^^",
|
||||
"...seriously?",
|
||||
"Just type this ^^^^",
|
||||
}
|
||||
local attempt = 0
|
||||
local repl
|
||||
repl = ReplLayout.new({
|
||||
lines = lines,
|
||||
on_submit = function(line)
|
||||
if line:upper() ~= confirmation:upper() then
|
||||
attempt = attempt % #hints + 1
|
||||
vim.api.nvim_buf_set_lines(repl.input_bufnr, 0, -1, true, {})
|
||||
vim.bo[repl.view_bufnr].modifiable = true
|
||||
vim.api.nvim_buf_set_lines(repl.view_bufnr, 6, 7, true, { hints[attempt] })
|
||||
vim.bo[repl.view_bufnr].modifiable = false
|
||||
vim.bo[repl.view_bufnr].modified = false
|
||||
else
|
||||
fs.mkdirp(vim.fn.fnamemodify(marker_file, ":h"))
|
||||
fs.touch(
|
||||
marker_file,
|
||||
vim.schedule_wrap(function(err2)
|
||||
if err2 then
|
||||
vim.notify(
|
||||
string.format("Error recording response: %s", err2),
|
||||
vim.log.levels.WARN
|
||||
)
|
||||
end
|
||||
callback(true)
|
||||
repl:close()
|
||||
end)
|
||||
)
|
||||
end
|
||||
end,
|
||||
on_cancel = function()
|
||||
callback(false)
|
||||
end,
|
||||
})
|
||||
local ns = vim.api.nvim_create_namespace("Oil")
|
||||
vim.api.nvim_buf_add_highlight(repl.view_bufnr, ns, "DiagnosticError", 0, 0, -1)
|
||||
end)
|
||||
)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -1,7 +1,6 @@
|
|||
local cache = require("oil.cache")
|
||||
local columns = require("oil.columns")
|
||||
local config = require("oil.config")
|
||||
local disclaimer = require("oil.mutator.disclaimer")
|
||||
local oil = require("oil")
|
||||
local parser = require("oil.mutator.parser")
|
||||
local pathutil = require("oil.pathutil")
|
||||
|
|
@ -505,38 +504,32 @@ M.try_write_changes = function(confirm)
|
|||
end
|
||||
|
||||
local actions = M.create_actions_from_diffs(all_diffs)
|
||||
-- TODO(2023-06-01) If no one has reported data loss by this time, we can remove the disclaimer
|
||||
disclaimer.show(function(disclaimed)
|
||||
if not disclaimed then
|
||||
preview.show(actions, confirm, function(proceed)
|
||||
if not proceed then
|
||||
return unlock()
|
||||
end
|
||||
preview.show(actions, confirm, function(proceed)
|
||||
if not proceed then
|
||||
return unlock()
|
||||
end
|
||||
|
||||
M.process_actions(
|
||||
actions,
|
||||
vim.schedule_wrap(function(err)
|
||||
view.unlock_buffers()
|
||||
if err then
|
||||
vim.notify(string.format("[oil] Error applying actions: %s", err), vim.log.levels.ERROR)
|
||||
view.rerender_all_oil_buffers({ preserve_undo = false })
|
||||
else
|
||||
local current_entry = oil.get_cursor_entry()
|
||||
if current_entry then
|
||||
-- get the entry under the cursor and make sure the cursor stays on it
|
||||
view.set_last_cursor(
|
||||
vim.api.nvim_buf_get_name(0),
|
||||
vim.split(current_entry.parsed_name or current_entry.name, "/")[1]
|
||||
)
|
||||
end
|
||||
view.rerender_all_oil_buffers({ preserve_undo = M.trash })
|
||||
M.process_actions(
|
||||
actions,
|
||||
vim.schedule_wrap(function(err)
|
||||
view.unlock_buffers()
|
||||
if err then
|
||||
vim.notify(string.format("[oil] Error applying actions: %s", err), vim.log.levels.ERROR)
|
||||
view.rerender_all_oil_buffers({ preserve_undo = false })
|
||||
else
|
||||
local current_entry = oil.get_cursor_entry()
|
||||
if current_entry then
|
||||
-- get the entry under the cursor and make sure the cursor stays on it
|
||||
view.set_last_cursor(
|
||||
vim.api.nvim_buf_get_name(0),
|
||||
vim.split(current_entry.parsed_name or current_entry.name, "/")[1]
|
||||
)
|
||||
end
|
||||
mutation_in_progress = false
|
||||
end)
|
||||
)
|
||||
end)
|
||||
view.rerender_all_oil_buffers({ preserve_undo = M.trash })
|
||||
end
|
||||
mutation_in_progress = false
|
||||
end)
|
||||
)
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue