Update all calls to notification module to use a standard variable name,

and add helper functions to get the right level
This commit is contained in:
Cameron 2023-09-19 15:16:39 +02:00
parent f0bd7c736c
commit a3d59b2863
26 changed files with 102 additions and 103 deletions

View file

@ -33,7 +33,7 @@ function M.setup(opts)
M.cli = M.lib.git.cli
M.popups = require("neogit.popups")
M.config = config
M.notif = require("neogit.lib.notification")
M.notification = require("neogit.lib.notification")
config.setup(opts)
hl.setup()
@ -71,7 +71,7 @@ function M.open(opts)
end
if not did_setup then
notification.create("Neogit has not been setup!", vim.log.levels.ERROR)
notification.error("Neogit has not been setup!")
logger.error("Neogit not setup!")
return
end
@ -85,7 +85,7 @@ function M.open(opts)
then
lib.git.init.create(opts.cwd or vim.fn.getcwd(), true)
else
notification.create("The current working directory is not a git repository", vim.log.levels.ERROR)
notification.error("The current working directory is not a git repository")
return
end
end

View file

@ -5,6 +5,7 @@ local ui = require("neogit.buffers.commit_view.ui")
local log = require("neogit.lib.git.log")
local config = require("neogit.config")
local popups = require("neogit.popups")
local notification = require("neogit.lib.notification")
local api = vim.api
@ -42,11 +43,10 @@ local M = {
--- @param notify boolean Should show a notification or not
--- @return CommitViewBuffer
function M.new(commit_id, notify)
local notification
if notify then
local notif = require("neogit.lib.notification")
notification = notif.create("Parsing commit...")
notification.info("Parsing commit...")
end
local commit_info = log.parse(cli.show.format("fuller").args(commit_id).call_sync().stdout)[1]
commit_info.commit_arg = commit_id
local instance = {
@ -59,9 +59,7 @@ function M.new(commit_id, notify)
buffer = nil,
}
if notification then
notification:delete()
end
notification.delete_all()
setmetatable(instance, { __index = M })

View file

@ -2,6 +2,7 @@ local Buffer = require("neogit.lib.buffer")
local ui = require("neogit.buffers.log_view.ui")
local config = require("neogit.config")
local popups = require("neogit.popups")
local notification = require("neogit.lib.notification")
local CommitViewBuffer = require("neogit.buffers.commit_view")
@ -134,7 +135,7 @@ function M:open()
end,
["d"] = function()
if not config.check_integration("diffview") then
require("neogit.lib.notification").error("Diffview integration must be enabled for log diff")
notification.error("Diffview integration must be enabled for log diff")
return
end

View file

@ -2,6 +2,7 @@ local Buffer = require("neogit.lib.buffer")
local ui = require("neogit.buffers.reflog_view.ui")
local config = require("neogit.config")
local popups = require("neogit.popups")
local notification = require("neogit.lib.notification")
local CommitViewBuffer = require("neogit.buffers.commit_view")
@ -86,7 +87,7 @@ function M:open()
end,
["d"] = function()
if not config.check_integration("diffview") then
require("neogit.lib.notification").error("Diffview integration must be enabled for reflog diff")
notification.error("Diffview integration must be enabled for reflog diff")
return
end

View file

@ -75,8 +75,8 @@ function M.editor(target, client)
elseif target:find("MERGE_MSG$") then
editor.merge_editor(target, send_client_quit)
else
local notif = require("neogit.lib.notification")
notif.create(target .. " has not been implemented yet", vim.log.levels.WARN)
local notification = require("neogit.lib.notification")
notification.warn(target .. " has not been implemented yet")
send_client_quit()
end
end
@ -84,24 +84,23 @@ end
---@param cmd any
---@param opts table
function M.wrap(cmd, opts)
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local a = require("plenary.async")
a.util.scheduler()
local notification = notif.create(opts.msg.setup, vim.log.levels.INFO, 9999)
notification.info(opts.msg.setup)
local result = cmd.env(M.get_envs_git_editor()):in_pty(true).call(true):trim()
a.util.scheduler()
if notification then
notification:delete()
end
notification.delete_all()
if result.code == 0 then
notif.create(opts.msg.success)
notification.info(opts.msg.success)
vim.api.nvim_exec_autocmds("User", { pattern = opts.autocmd, modeline = false })
else
notif.create(opts.msg.fail)
notification.warn(opts.msg.fail)
end
end

View file

@ -1,5 +1,5 @@
local cli = require("neogit.lib.git.cli")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local util = require("neogit.lib.util")
local M = {}
@ -7,7 +7,7 @@ local M = {}
function M.pick(commits, args)
local result = cli["cherry-pick"].arg_list(util.merge(args, commits)).call()
if result.code ~= 0 then
notif.create("Cherry Pick failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Cherry Pick failed. Resolve conflicts before continuing")
end
end
@ -20,7 +20,7 @@ function M.apply(commits, args)
local result = cli["cherry-pick"].no_commit.arg_list(util.merge(args, commits)).call()
if result.code ~= 0 then
notif.create("Cherry Pick failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Cherry Pick failed. Resolve conflicts before continuing")
end
end

View file

@ -1,4 +1,4 @@
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local logger = require("neogit.logger")
local a = require("plenary.async")
local process = require("neogit.process")
@ -555,10 +555,7 @@ local function handle_new_cmd(job, popup, hidden_text)
if popup and job.code ~= 0 then
vim.schedule(function()
notif.create(
"Git Error (" .. job.code .. "), press $ to see the git command history",
vim.log.levels.ERROR
)
notification.error("Git Error (" .. job.code .. "), press $ to see the git command history")
end)
end
end

View file

@ -1,5 +1,5 @@
local cli = require("neogit.lib.git.cli")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local input = require("neogit.lib.input")
local M = {}
@ -29,7 +29,7 @@ M.init_repo = function()
directory = vim.fn.fnamemodify(directory, ":p")
if vim.fn.isdirectory(directory) == 0 then
notif.create("You entered an invalid directory", vim.log.levels.ERROR)
notification.error("You entered an invalid directory")
return
end

View file

@ -1,5 +1,5 @@
local client = require("neogit.client")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local cli = require("neogit.lib.git.cli")
local branch_lib = require("neogit.lib.git.branch")
@ -16,9 +16,9 @@ function M.merge(branch, args)
a.util.scheduler()
local result = merge_command(cli.merge.args(branch).arg_list(args))
if result.code ~= 0 then
notif.create("Merging failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Merging failed. Resolve conflicts before continuing")
else
notif.create("Merged '" .. branch .. "' into '" .. branch_lib.current() .. "'", vim.log.levels.INFO)
notification.info("Merged '" .. branch .. "' into '" .. branch_lib.current() .. "'")
end
end

View file

@ -1,6 +1,6 @@
local logger = require("neogit.logger")
local client = require("neogit.client")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local M = {}
@ -18,9 +18,9 @@ function M.rebase_interactive(commit, args)
local git = require("neogit.lib.git")
local result = rebase_command(git.cli.rebase.interactive.args(commit).arg_list(args))
if result.code ~= 0 then
notif.create("Rebasing failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Rebasing failed. Resolve conflicts before continuing")
else
notif.create("Rebased successfully", vim.log.levels.INFO)
notification.info("Rebased successfully")
end
end
@ -29,9 +29,9 @@ function M.rebase_onto(branch, args)
local git = require("neogit.lib.git")
local result = rebase_command(git.cli.rebase.args(branch).arg_list(args))
if result.code ~= 0 then
notif.create("Rebasing failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Rebasing failed. Resolve conflicts before continuing")
else
notif.create("Rebased onto '" .. branch .. "'", vim.log.levels.INFO)
notification.info("Rebased onto '" .. branch .. "'")
end
end

View file

@ -1,5 +1,5 @@
local cli = require("neogit.lib.git.cli")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local a = require("plenary.async")
local M = {}
@ -28,9 +28,9 @@ function M.add(name, url, args)
local result = cli.remote.add.arg_list(args).args(name, url).call()
if result.code ~= 0 then
notif.create("Couldn't add remote", vim.log.levels.ERROR)
notification.error("Couldn't add remote")
else
notif.create("Added remote '" .. name .. "'", vim.log.levels.INFO)
notification.info("Added remote '" .. name .. "'")
end
return result
@ -39,9 +39,9 @@ end
function M.rename(from, to)
local result = cli.remote.rename.arg_list({ from, to }).call_sync()
if result.code ~= 0 then
notif.create("Couldn't rename remote", vim.log.levels.ERROR)
notification.error("Couldn't rename remote")
else
notif.create("Renamed '" .. from .. "' -> '" .. to .. "'", vim.log.levels.INFO)
notification.info("Renamed '" .. from .. "' -> '" .. to .. "'")
cleanup_push_variables(from, to)
end
@ -51,9 +51,9 @@ end
function M.remove(name)
local result = cli.remote.rm.args(name).call_sync()
if result.code ~= 0 then
notif.create("Couldn't remove remote", vim.log.levels.ERROR)
notification.error("Couldn't remove remote")
else
notif.create("Removed remote '" .. name .. "'", vim.log.levels.INFO)
notification.info("Removed remote '" .. name .. "'")
cleanup_push_variables(name)
end
@ -63,9 +63,9 @@ end
function M.prune(name)
local result = cli.remote.prune.args(name).call_sync()
if result.code ~= 0 then
notif.create("Couldn't prune remote", vim.log.levels.ERROR)
notification.error("Couldn't prune remote")
else
notif.create("Pruned remote '" .. name .. "'", vim.log.levels.INFO)
notification.info("Pruned remote '" .. name .. "'")
end
return result

View file

@ -1,5 +1,5 @@
local cli = require("neogit.lib.git.cli")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local a = require("plenary.async")
local M = {}
@ -9,9 +9,9 @@ function M.mixed(commit)
local result = cli.reset.mixed.args(commit).call()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
notif.create("Reset to " .. commit, vim.log.levels.INFO)
notification.info("Reset to " .. commit)
end
end
@ -20,9 +20,9 @@ function M.soft(commit)
local result = cli.reset.soft.args(commit).call()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
notif.create("Reset to " .. commit, vim.log.levels.INFO)
notification.info("Reset to " .. commit)
end
end
@ -31,9 +31,9 @@ function M.hard(commit)
local result = cli.reset.hard.args(commit).call()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
notif.create("Reset to " .. commit, vim.log.levels.INFO)
notification.info("Reset to " .. commit)
end
end
@ -42,9 +42,9 @@ function M.keep(commit)
local result = cli.reset.keep.args(commit).call()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
notif.create("Reset to " .. commit, vim.log.levels.INFO)
notification.info("Reset to " .. commit)
end
end
@ -53,9 +53,9 @@ function M.index(commit)
local result = cli.reset.args(commit).files(".").call()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
notif.create("Reset to " .. commit, vim.log.levels.INFO)
notification.info("Reset to " .. commit)
end
end
@ -72,12 +72,12 @@ end
function M.file(commit, files)
local result = cli.checkout.rev(commit).files(unpack(files)).call_sync()
if result.code ~= 0 then
notif.create("Reset Failed", vim.log.levels.ERROR)
notification.error("Reset Failed")
else
if #files > 1 then
notif.create("Reset " .. #files .. " files", vim.log.levels.info)
notification.info("Reset " .. #files .. " files")
else
notif.create("Reset " .. files[1], vim.log.levels.info)
notification.info("Reset " .. files[1])
end
end
end

View file

@ -2,7 +2,7 @@ local a = require("plenary.async")
local state = require("neogit.lib.state")
local config = require("neogit.lib.git.config")
local util = require("neogit.lib.util")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local logger = require("neogit.logger")
local M = {}
@ -290,7 +290,7 @@ function M:action(keys, description, callback)
for _, key in pairs(keys) do
if self.state.keys[key] then
notif.error(string.format("[POPUP] Duplicate key mapping %q", key))
notification.error(string.format("[POPUP] Duplicate key mapping %q", key))
return self
end
self.state.keys[key] = true

View file

@ -7,6 +7,7 @@ local util = require("neogit.lib.util")
local config = require("neogit.config")
local state = require("neogit.lib.state")
local input = require("neogit.lib.input")
local notification = require("neogit.lib.notification")
local git = require("neogit.lib.git")
@ -591,8 +592,7 @@ function M:show()
else
for _, key in ipairs(action.keys) do
mappings.n[key] = function()
local notif = require("neogit.lib.notification")
notif.create(action.description .. " has not been implemented yet", vim.log.levels.WARN)
notification.warn(action.description .. " has not been implemented yet")
end
end
end

View file

@ -3,7 +3,7 @@ local M = {}
local git = require("neogit.lib.git")
local input = require("neogit.lib.input")
local util = require("neogit.lib.util")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local operation = require("neogit.operations")
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
@ -23,7 +23,7 @@ end
local function spin_off_branch(checkout)
if git.status.is_dirty() and not checkout then
notif.create("Staying on HEAD due to uncommitted changes", vim.log.levels.INFO)
notification.info("Staying on HEAD due to uncommitted changes")
checkout = true
end
@ -188,7 +188,7 @@ M.reset_branch = operation("reset_branch", function()
git.cli.reset.hard.args(to).call_sync()
git.log.update_ref(git.branch.current_full_name(), to)
notif.create(string.format("Reset '%s' to '%s'", current, to), vim.log.levels.INFO)
notification.info(string.format("Reset '%s' to '%s'", current, to))
end)
M.delete_branch = operation("delete_branch", function()
@ -244,9 +244,9 @@ M.delete_branch = operation("delete_branch", function()
if success then
if remote then
notif.create(string.format("Deleted remote branch '%s/%s'", remote, branch_name), vim.log.levels.INFO)
notification.info(string.format("Deleted remote branch '%s/%s'", remote, branch_name))
else
notif.create(string.format("Deleted branch '%s'", branch_name), vim.log.levels.INFO)
notification.info(string.format("Deleted branch '%s'", branch_name))
end
end
end)

View file

@ -4,6 +4,7 @@ local CommitSelectViewBuffer = require("neogit.buffers.commit_select_view")
local git = require("neogit.lib.git")
local client = require("neogit.client")
local input = require("neogit.lib.input")
local notification = require("neogit.lib.notification")
local a = require("plenary.async")
local function confirm_modifications()
@ -49,7 +50,7 @@ local function commit_special(popup, method, opts)
return
end
else
require("neogit.lib.notification").create("No changes to commit.", vim.lsp.log_levels.WARN)
notification.warn("No changes to commit.")
return
end
end

View file

@ -2,10 +2,11 @@ local M = {}
local config = require("neogit.config")
local popup = require("neogit.lib.popup")
local notification = require("neogit.lib.notification")
function M.create()
if not config.check_integration("diffview") then
require("neogit.lib.notification").error("Diffview integration must be enabled for diff popup")
notification.error("Diffview integration must be enabled for diff popup")
return
end

View file

@ -1,9 +1,9 @@
--- This popup is for unit testing purposes and is not associated to any git command.
local notification = require("neogit.lib.notification")
local M = {}
function M.echo(value)
local notification = require("neogit.lib.notification")
notification.create("Echo: " .. value)
notification.info("Echo: " .. value)
end
return M

View file

@ -3,7 +3,7 @@ local M = {}
local a = require("plenary.async")
local git = require("neogit.lib.git")
local logger = require("neogit.logger")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local util = require("neogit.lib.util")
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
@ -13,12 +13,12 @@ local function select_remote()
end
local function fetch_from(name, remote, branch, args)
notif.create("Fetching from " .. name)
notification.info("Fetching from " .. name)
local res = git.fetch.fetch_interactive(remote, branch, args)
if res and res.code == 0 then
a.util.scheduler()
notif.create("Fetched from " .. name)
notification.info("Fetched from " .. name)
logger.debug("Fetched from " .. name)
vim.api.nvim_exec_autocmds("User", { pattern = "NeogitFetchComplete", modeline = false })
else
@ -101,7 +101,7 @@ function M.fetch_refspec(popup)
return
end
notif.create("Determining refspecs...")
notification.info("Determining refspecs...")
local refspecs = util.map(git.cli["ls-remote"].remote(remote).call():trim().stdout, function(ref)
return vim.split(ref, "\t")[2]
end)
@ -115,7 +115,7 @@ function M.fetch_refspec(popup)
end
function M.fetch_submodules(_)
notif.create("Fetching submodules")
notification.info("Fetching submodules")
git.cli.fetch.recurse_submodules().verbose().jobs(4).call()
end

View file

@ -1,4 +1,5 @@
local util = require("neogit.lib.util")
local notification = require("neogit.lib.notification")
local M = {}
---@param name string
@ -17,8 +18,7 @@ function M.open(name, f)
f(value.create)
else
local notification = require("neogit.lib.notification")
notification.create(string.format("Failed to load popup: %q\n%s", name, value), vim.log.levels.ERROR)
notification.error(string.format("Failed to load popup: %q\n%s", name, value))
end
end
end

View file

@ -1,7 +1,7 @@
local a = require("plenary.async")
local git = require("neogit.lib.git")
local logger = require("neogit.logger")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
@ -16,14 +16,14 @@ local function pull_from(args, remote, branch, opts)
local name = remote .. "/" .. branch
notif.create("Pulling from " .. name)
notification.info("Pulling from " .. name)
logger.debug("Pulling from " .. name)
local res = git.pull.pull_interactive(remote, branch, args)
if res and res.code == 0 then
a.util.scheduler()
notif.create("Pulled from " .. name)
notification.info("Pulled from " .. name)
logger.debug("Pulled from " .. name)
vim.api.nvim_exec_autocmds("User", { pattern = "NeogitPullComplete", modeline = false })
else

View file

@ -1,7 +1,7 @@
local a = require("plenary.async")
local git = require("neogit.lib.git")
local logger = require("neogit.logger")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")
@ -17,14 +17,14 @@ local function push_to(args, remote, branch, opts)
local name = remote .. "/" .. branch
logger.debug("Pushing to " .. name)
notif.create("Pushing to " .. name)
notification.info("Pushing to " .. name)
local res = git.push.push_interactive(remote, branch, args)
if res and res.code == 0 then
a.util.scheduler()
logger.error("Pushed to " .. name)
notif.create("Pushed to " .. name)
logger.debug("Pushed to " .. name)
notification.info("Pushed to " .. name)
vim.api.nvim_exec_autocmds("User", { pattern = "NeogitPushComplete", modeline = false })
else
logger.error("Failed to push to " .. name)

View file

@ -43,9 +43,9 @@ M.add = operation("add_remote", function(popup)
if set_default then
git.config.set("remote.pushDefault", name)
notification.create("Added remote " .. name .. " and set as pushDefault")
notification.info("Added remote " .. name .. " and set as pushDefault")
else
notification.create("Added remote " .. name)
notification.info("Added remote " .. name)
end
end)
@ -61,7 +61,7 @@ function M.rename(_)
end
git.remote.rename(selected_remote, new_name)
notification.create("Renamed remote " .. selected_remote .. " to " .. new_name)
notification.info("Renamed remote " .. selected_remote .. " to " .. new_name)
end
function M.remove(_)
@ -71,7 +71,7 @@ function M.remove(_)
end
git.remote.remove(selected_remote)
notification.create("Removed remote " .. selected_remote)
notification.info("Removed remote " .. selected_remote)
end
function M.configure(_)
@ -89,7 +89,7 @@ function M.prune_branches(_)
return
end
notification.create("Pruning remote " .. selected_remote)
notification.info("Pruning remote " .. selected_remote)
git.remote.prune(selected_remote)
end

View file

@ -2,7 +2,7 @@ local M = {}
local git = require("neogit.lib.git")
local client = require("neogit.client")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local CommitSelectViewBuffer = require("neogit.buffers.commit_select_view")
---@param popup any
@ -38,7 +38,7 @@ function M.commits(popup)
local args = popup:get_arguments()
local success = git.revert.commits(commits, args)
if not success then
notif.create("Revert failed. Resolve conflicts before continuing", vim.log.levels.ERROR)
notification.error("Revert failed. Resolve conflicts before continuing")
return
end

View file

@ -182,7 +182,7 @@ function Process:start_timer()
if config.values.auto_show_console then
Process.show_console()
else
notification.create(message .. "\n\nOpen the console for details", vim.log.levels.WARN)
notification.warn(message .. "\n\nOpen the console for details")
end
end
end)
@ -347,7 +347,7 @@ function Process:spawn(cb)
table.concat(output, "\n")
)
notification.create(message, vim.log.levels.ERROR)
notification.error(message)
end
-- vim.schedule(Process.show_console)
end

View file

@ -3,7 +3,7 @@ local GitCommandHistory = require("neogit.buffers.git_command_history")
local CommitView = require("neogit.buffers.commit_view")
local git = require("neogit.lib.git")
local cli = require("neogit.lib.git.cli")
local notif = require("neogit.lib.notification")
local notification = require("neogit.lib.notification")
local config = require("neogit.config")
local a = require("plenary.async")
local logger = require("neogit.logger")
@ -506,6 +506,7 @@ local refresh_lock = a.control.Semaphore.new(1)
local lock_holder = nil
local function refresh(which, reason)
notification.info("[DEBUG] Refreshing Status Buffer")
logger.info("[STATUS BUFFER]: Starting refresh")
if refresh_lock.permits == 0 then
@ -651,7 +652,7 @@ local function close(skip_close)
end
M.watcher:stop()
notif.delete_all()
notification.delete_all()
M.status_buffer = nil
vim.o.autochdir = M.prev_autochdir
if M.cwd_changed then
@ -981,7 +982,7 @@ local function handle_section_item(item)
cursor_row, cursor_col = unpack(vim.api.nvim_win_get_cursor(0))
end
notif.delete_all()
notification.delete_all()
M.status_buffer:close()
local relpath = vim.fn.fnamemodify(path, ":.")
@ -1209,7 +1210,7 @@ local cmd_func_map = function()
end),
["RefreshBuffer"] = function()
notif.create("Refreshing Status", vim.log.levels.INFO)
notification.info("Refreshing Status")
dispatch_refresh(true)
end,
@ -1217,7 +1218,7 @@ local cmd_func_map = function()
["DiffAtFile"] = function()
if not config.check_integration("diffview") then
require("neogit.lib.notification").error("Diffview integration is not enabled")
notification.error("Diffview integration is not enabled")
return
end