Skip to content

Commit

Permalink
Merge pull request #737 from NeogitOrg/upgrade-revert
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Aug 11, 2023
2 parents f4cd28f + 5467761 commit e80cd64
Show file tree
Hide file tree
Showing 19 changed files with 306 additions and 166 deletions.
67 changes: 55 additions & 12 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,21 @@ NeogitFold Folded text highlight
NeogitRebaseDone Current position within rebase

STATUS BUFFER SECTION HEADERS
NeogitUnpushedTo
NeogitUnmergedInto
NeogitUnpulledFrom
NeogitUntrackedfiles
NeogitUnstagedchanges
NeogitUnmergedchanges
NeogitUnpulledchanges
NeogitRecentcommits
NeogitStagedchanges
NeogitStashes
NeogitRebasing
NeogitSectionHeader

NeogitUnpushedTo Linked to NeogitSectionHeader
NeogitUnmergedInto ^
NeogitUnpulledFrom ^
NeogitUntrackedfiles ^
NeogitUnstagedchanges ^
NeogitUnmergedchanges ^
NeogitUnpulledchanges ^
NeogitRecentcommits ^
NeogitStagedchanges ^
NeogitStashes ^
NeogitRebasing ^
NeogitReverting ^
NeogitPicking ^

STATUS BUFFER FILE
Applied to the label on the left of filenames.
Expand Down Expand Up @@ -778,7 +782,6 @@ Arguments: *neogit_fetch_popup_args*
pruning, even if --prune is used (though tags may be pruned anyway if
they are also the destination of an explicit refspec; see --prune).


Actions: *neogit_fetch_popup_actions*

• Fetch from pushRemote *neogit_fetch_pushremote*
Expand Down Expand Up @@ -815,4 +818,44 @@ Actions: *neogit_fetch_popup_actions*
• Set Variables *neogit_fetch_set_variables*
Opens Branch Config popup for the current branch.

==============================================================================
Revert Popup *neogit_revert_popup*

Arguments: *neogit_revert_popup_args*
• --mainline
Usually you cannot revert a merge because you do not know which side of the
merge should be considered the mainline. This option specifies the parent
number (starting from 1) of the mainline and allows revert to reverse the
change relative to the specified parent.

Reverting a merge commit declares that you will never want the tree changes
brought in by the merge. As a result, later merges will only bring in tree
changes introduced by commits that are not ancestors of the previously
reverted merge. This may or may not be what you want.

• --edit
With this option, git revert will let you edit the commit message prior to
committing the revert. This is the default.

Cannot be used with --no-edit

• --no-edit
With this option, git revert will auto-generate the commit message without
bringing up the commit message editor.

Cannot be used with --edit

Actions: *neogit_fetch_revert_actions*

• Revert Commit(s) *neogit_revert_commits*
Reverts one or more commits. If any commits are under the cursor, or
selected, they will be used. Otherwise a selector interface will come up.

Will create a commit of the reverted changes.

• Revert Changes *neogit_revert_changes*
Reverts one or more commits WITHOUT committing the worktree. If any commits
are under the cursor, or selected, they will be used. Otherwise a selector
interface will come up.

vim:tw=78:ts=8:ft=help
15 changes: 2 additions & 13 deletions lua/neogit/buffers/commit_select_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ end
function M:open(action)
-- TODO: Pass this in as a param instead of reading state from object
local _, item = require("neogit.status").get_current_section_item()
print("Found item: ", vim.inspect(item))

---@type fun(commit: CommitLogEntry[])|nil
local action = action
Expand All @@ -44,15 +43,7 @@ function M:open(action)
mappings = {
v = {
["<enter>"] = function()
local commits = util.filter_map(
self.buffer.ui:get_component_stack_in_linewise_selection(),
function(c)
if c.options.oid then
return c.options.oid
end
end
)

local commits = self.buffer.ui:get_commits_in_selection()
if action and commits[1] then
vim.schedule(function()
self:close()
Expand All @@ -74,9 +65,7 @@ function M:open(action)
self:close()
end,
["<enter>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
local commit = stack[#stack].options.oid

local commit = self.buffer.ui:get_commit_under_cursor()
if action and commit then
vim.schedule(function()
self:close()
Expand Down
25 changes: 16 additions & 9 deletions lua/neogit/buffers/commit_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ local parser = require("neogit.buffers.commit_view.parsing")
local ui = require("neogit.buffers.commit_view.ui")
local log = require("neogit.lib.git.log")
local config = require("neogit.config")

local CherryPickPopup = require("neogit.popups.cherry_pick")
local RevertPopup = require("neogit.popups.revert")
local popups = require("neogit.popups")

local api = vim.api

Expand Down Expand Up @@ -127,12 +125,21 @@ function M:open()
vim.cmd("normal! zt")
end
end,
["A"] = function()
CherryPickPopup.create { commits = { self.commit_info.oid } }
end,
["v"] = function()
RevertPopup.create { commits = { self.commit_info.oid } }
end,
["A"] = popups.open("cherry_pick", function(p)
p { commits = { self.commit_info.oid } }
end),
["b"] = popups.open("branch", function(p)
p { revisions = { self.commit_info.oid } }
end),
["c"] = popups.open("commit", function(p)
p { commit = self.commit_info.oid }
end),
["r"] = popups.open("rebase", function(p)
p { commit = self.commit_info.oid }
end),
["v"] = popups.open("revert", function(p)
p { commits = { self.commit_info.oid } }
end),
["q"] = function()
self:close()
end,
Expand Down
86 changes: 33 additions & 53 deletions lua/neogit/buffers/log_view/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local Buffer = require("neogit.lib.buffer")
local util = require("neogit.lib.util")
local ui = require("neogit.buffers.log_view.ui")
local config = require("neogit.config")
local popups = require("neogit.popups")

local CommitViewBuffer = require("neogit.buffers.commit_view")
local CherryPickPopup = require("neogit.popups.cherry_pick")
local RevertPopup = require("neogit.popups.revert")

---@class LogViewBuffer
---@field commits CommitLogEntry[]
Expand Down Expand Up @@ -43,35 +41,21 @@ function M:open()
context_highlight = false,
mappings = {
v = {
["A"] = function()
local commits = util.filter_map(
self.buffer.ui:get_component_stack_in_linewise_selection(),
function(c)
if c.options.oid then
return c.options.oid
end
end
)

CherryPickPopup.create { commits = util.reverse(commits) }
end,
["c"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
require("neogit.popups.commit").create { commit = stack[#stack].options.oid }
end,
["v"] = function()
require("neogit.lib.notification").error("Multiple commits not yet implimented")
-- local commits = util.filter_map(
-- self.buffer.ui:get_component_stack_in_linewise_selection(),
-- function(c)
-- if c.options.oid then
-- return c.options.oid
-- end
-- end
-- )
--
-- RevertPopup.create { commits = util.reverse(commits) }
end,
["A"] = popups.open("cherry_pick", function(p)
p { commits = self.buffer.ui:get_commits_in_selection() }
end),
["b"] = popups.open("branch", function(p)
p { revisions = self.buffer.ui:get_commits_in_selection() }
end),
["c"] = popups.open("commit", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["r"] = popups.open("rebase", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["v"] = popups.open("revert", function(p)
p { commits = self.buffer.ui:get_commits_in_selection() }
end),
},
n = {
["q"] = function()
Expand All @@ -80,21 +64,23 @@ function M:open()
["<esc>"] = function()
self:close()
end,
["A"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
CherryPickPopup.create { commits = { stack[#stack].options.oid } }
end,
["c"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
require("neogit.popups.commit").create { commit = stack[#stack].options.oid }
end,
["v"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
RevertPopup.create { commits = { stack[#stack].options.oid } }
end,
["A"] = popups.open("cherry_pick", function(p)
p { commits = { self.buffer.ui:get_commit_under_cursor() } }
end),
["b"] = popups.open("branch", function(p)
p { revisions = { self.buffer.ui:get_commit_under_cursor() } }
end),
["c"] = popups.open("commit", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["r"] = popups.open("rebase", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["v"] = popups.open("revert", function(p)
p { commits = { self.buffer.ui:get_commit_under_cursor() } }
end),
["<enter>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
CommitViewBuffer.new(stack[#stack].options.oid):open()
CommitViewBuffer.new(self.buffer.ui:get_commit_under_cursor()):open()
end,
["<c-k>"] = function(buffer)
local stack = self.buffer.ui:get_component_stack_under_cursor()
Expand Down Expand Up @@ -136,15 +122,9 @@ function M:open()
return
end

local stack = self.buffer.ui:get_component_stack_under_cursor()
local dv = require("neogit.integrations.diffview")
dv.open("log", stack[#stack].options.oid)
dv.open("log", self.buffer.ui:get_commit_under_cursor())
end,
["b"] = require("neogit.popups").open("branch", function(p)
local stack = self.buffer.ui:get_component_stack_under_cursor()
local commit = stack[#stack].options.oid
p { revisions = { commit } }
end),
},
},
after = function(buffer, win)
Expand Down
78 changes: 32 additions & 46 deletions lua/neogit/buffers/reflog_view/init.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local Buffer = require("neogit.lib.buffer")
local util = require("neogit.lib.util")
local ui = require("neogit.buffers.reflog_view.ui")
local config = require("neogit.config")
local popups = require("neogit.popups")

local CommitViewBuffer = require("neogit.buffers.commit_view")
local CherryPickPopup = require("neogit.popups.cherry_pick")
local RevertPopup = require("neogit.popups.revert")

---@class ReflogViewBuffer
---@field entries ReflogEntry[]
Expand Down Expand Up @@ -38,35 +36,21 @@ function M:open()
context_highlight = true,
mappings = {
v = {
["A"] = function()
local commits = util.filter_map(
self.buffer.ui:get_component_stack_in_linewise_selection(),
function(c)
if c.options.oid then
return c.options.oid
end
end
)

CherryPickPopup.create { commits = util.reverse(commits) }
end,
["c"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
require("neogit.popups.commit").create { commit = stack[#stack].options.oid }
end,
["v"] = function()
print("Multiple commits not yet implimented")
-- local commits = util.filter_map(
-- self.buffer.ui:get_component_stack_in_linewise_selection(),
-- function(c)
-- if c.options.oid then
-- return c.options.oid
-- end
-- end
-- )
--
-- RevertPopup.create { commits = util.reverse(commits) }
end,
["A"] = popups.open("cherry_pick", function(p)
p { commits = self.buffer.ui:get_commits_in_selection() }
end),
["b"] = popups.open("branch", function(p)
p { revisions = self.buffer.ui:get_commits_in_selection() }
end),
["c"] = popups.open("commit", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["r"] = popups.open("rebase", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["v"] = popups.open("revert", function(p)
p { commits = self.buffer.ui:get_commits_in_selection() }
end),
},
n = {
["q"] = function()
Expand All @@ -75,18 +59,21 @@ function M:open()
["<esc>"] = function()
self:close()
end,
["A"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
CherryPickPopup.create { commits = { stack[#stack].options.oid } }
end,
["c"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
require("neogit.popups.commit").create { commit = stack[#stack].options.oid }
end,
["v"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
RevertPopup.create { commits = { stack[#stack].options.oid } }
end,
["A"] = popups.open("cherry_pick", function(p)
p { commits = { self.buffer.ui:get_commit_under_cursor() } }
end),
["b"] = popups.open("branch", function(p)
p { revisions = { self.buffer.ui:get_commit_under_cursor() } }
end),
["c"] = popups.open("commit", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["r"] = popups.open("rebase", function(p)
p { commit = self.buffer.ui:get_commit_under_cursor() }
end),
["v"] = popups.open("revert", function(p)
p { commits = { self.buffer.ui:get_commit_under_cursor() } }
end),
["<enter>"] = function()
local stack = self.buffer.ui:get_component_stack_under_cursor()
CommitViewBuffer.new(stack[#stack].options.oid):open()
Expand All @@ -97,9 +84,8 @@ function M:open()
return
end

local stack = self.buffer.ui:get_component_stack_under_cursor()
local dv = require("neogit.integrations.diffview")
dv.open("log", stack[#stack].options.oid)
dv.open("log", self.buffer.ui:get_commit_under_cursor())
end,
},
},
Expand Down
3 changes: 3 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,9 @@ function M.get_default_values()
diffview = nil,
},
sections = {
sequencer = {
folded = false,
},
untracked = {
folded = false,
},
Expand Down
Loading

0 comments on commit e80cd64

Please sign in to comment.