Skip to content

Commit

Permalink
fix: delete task bundle on save if no tasks and on_conflict=overwrite (
Browse files Browse the repository at this point in the history
…#374)

* fix: delete bundle if no tasks and on_conflict=overwrite

* feat: ignore_missing delete_task_bundle option
  • Loading branch information
derethil authored Oct 26, 2024
1 parent 80156d8 commit c416be5
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions lua/overseer/task_bundle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ M.save_task_bundle = function(name, tasks, opts)
end, task_list.list_tasks(config.bundles.save_task_opts))
end
if vim.tbl_isempty(serialized) then
if opts.on_conflict == "overwrite" then
M.delete_task_bundle(name, { ignore_missing = true })
end
return
end
local filepath = files.join(get_bundle_dir(), filename)
Expand Down Expand Up @@ -205,11 +208,19 @@ M.save_task_bundle = function(name, tasks, opts)
end

---@param name? string
M.delete_task_bundle = function(name)
---@param opts? {ignore_missing?: boolean}
M.delete_task_bundle = function(name, opts)
vim.validate({
name = { name, "s", true },
opts = { opts, "t", true },
})
opts = opts or {}
if name then
local filename = string.format("%s.bundle.json", name)
if not files.delete_file(files.join(get_bundle_dir(), filename)) then
vim.notify(string.format("No task bundle at %s", filename))
if not opts.ignore_missing then
vim.notify(string.format("No task bundle at %s", filename))
end
end
else
local tasks = M.list_task_bundles()
Expand Down

0 comments on commit c416be5

Please sign in to comment.