Skip to content

Commit

Permalink
Standardize revert popup API to be the same as cherry pick popup. Also
Browse files Browse the repository at this point in the history
add revert to commit view
  • Loading branch information
CKolkey committed Jul 13, 2023
1 parent b38e7eb commit 86400f6
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lua/neogit/buffers/commit_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@ function M:open()
["A"] = function()
CherryPickPopup.create { commits = { self.commit_info.oid } }
end,
["_"] = function()
RevertPopup.create{ commits = { self.commit_info.oid } }
end,
["q"] = function()
self:close()
end,
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/buffers/log_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function M:open()
end,
["_"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
RevertPopup.create(stack[#stack].options.oid)
RevertPopup.create { commits = { stack[#stack].options.oid } }
end,
["<enter>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/buffers/reflog_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function M:open()
end,
["_"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
RevertPopup.create(stack[#stack].options.oid)
RevertPopup.create { commits = { stack[#stack].options.oid } }
end,
["<enter>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/popups/revert/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ local M = {}
---@return table
local function get_commits(popup)
local commits
if popup.state.env.commits[1] then
if popup.state.env.commits and popup.state.env.commits[1] then
commits = popup.state.env.commits
else
commits = { CommitSelectViewBuffer.new(git.log.list { "--max-count=256" }):open_async() }
Expand Down
4 changes: 2 additions & 2 deletions lua/neogit/popups/revert/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ local popup = require("neogit.lib.popup")

local M = {}

function M.create(commits)
function M.create(env)
-- TODO: enabled = true needs to check if incompatible switch is toggled in internal state, and not apply.
-- if you enable 'no edit', and revert, next time you load the popup both will be enabled
--
Expand All @@ -19,7 +19,7 @@ function M.create(commits)
:switch("E", "no-edit", "Don't edit commit messages", { incompatible = { "edit" } })
:action("_", "Revert commit", actions.commits) -- TODO: Support multiple commits
:action("v", "Revert changes")
:env({ commits = commits or {} })
:env({ commits = env.commits })
:build()

p:show()
Expand Down
4 changes: 3 additions & 1 deletion lua/neogit/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,9 @@ local cmd_func_map = function()
end,
["RevertPopup"] = function()
local line = M.status_buffer:get_current_line()
require("neogit.popups.revert").create { line[1]:match("^(%x%x%x%x%x%x%x+)") }
require("neogit.popups.revert").create {
commits = { line[1]:match("^(%x%x%x%x%x%x%x+)") },
}
end,
["BranchPopup"] = require("neogit.popups.branch").create,
["FetchPopup"] = require("neogit.popups.fetch").create,
Expand Down

0 comments on commit 86400f6

Please sign in to comment.