Skip to content

Commit

Permalink
Merge pull request #708 from NeogitOrg/cherry-pick-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Aug 5, 2023
2 parents 684a984 + 542927c commit f756cf2
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 7 deletions.
74 changes: 69 additions & 5 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -380,14 +380,68 @@ git mechanism.
*neogit_stash*
"stash" see :Man git-stash

==============================================================================
Cherry-Pick Popup *neogit_cherry_pick_popup*

Arguments: *neogit_cherry_pick_popup_args*
- --ff
If the current HEAD is the same as the parent of the cherry-pick’ed
commit, then a fast forward to this commit will be performed.

Actions: *neogit_cherry_pick_popup_actions*
Actions for the branch popup are split into two categories: "Apply here",
and "Apply elsewhere". The former will update the current HEAD, whereas the
latter will prompt for a target.

When a Cherry-Pick isn't in progress, the following actions are available:

- Pick *neogit_cherry_pick_pick*
This command copies COMMITS from another branch onto the current branch.
If a commit is under the cursor, or multiple commits are selected, then
those are used instead of prompting. Otherwise the user is prompted to
select one or more commits.

- Apply *neogit_cherry_pick_apply*
This command applies the changes in COMMITS from another branch onto the
current branch, without committing. If a commit is under the cursor, or
multiple commits are selected, then those are used instead of prompting.
Otherwise the user is prompted to select one or more commits.

- Harvest *neogit_cherry_pick_harvest*
(not yet implemented)

- Squash *neogit_cherry_pick_squash*
(not yet implemented)

- Donate *neogit_cherry_pick_donate*
(not yet implemented)

- Spinout *neogit_cherry_pick_spinout*
(not yet implemented)

- Spinoff *neogit_cherry_pick_spinoff*
(not yet implemented)


When a Cherry-Pick is in progress, the following actions are available:

- Continue *neogit_cherry_pick_continue*
Resume current cherry-pick sequence.

- Skip *neogit_cherry_pick_skip*
Skip the current commit during a cherry-pick sequence.

- Abort *neogit_cherry_pick_abort*
Abort the current cherry-pick sequence. This discards all changes made.

==============================================================================
Branch Popup *neogit_branch_popup*

Variables: *neogit_branch_popup_variables*
- branch.<name>.description
- branch.<name>.description

- branch.<name>.merge
branch.<name>.remote
- branch.<name>.merge
branch.<name>.remote

- branch.<name>.rebase
Cycles branch.<name>.rebase value between true, false, and the value of
Expand All @@ -399,8 +453,18 @@ Variables: *neogit_branch_popup_variables*
repository. `remote.pushDefault` will be offered, if set.

Arguments: *neogit_branch_popup_args*
- recurse-submodules
Recurse submodules when checking out an existing branch
- --recurse-submodules
(EXPERIMENTAL) Causes the current command to recurse into submodules if
submodule.propagateBranches is enabled.

When used in branch creation, a new branch <branchname> will be created
in the superproject and all of the submodules in the superproject’s
<start-point>. In submodules, the branch will point to the submodule
commit in the superproject’s <start-point> but the branch’s tracking
information will be set up based on the submodule’s branches and remotes
e.g. git branch --recurse-submodules topic origin/main will create the
submodule branch "topic" that points to the submodule commit in the
superproject’s "origin/main", but tracks the submodule’s "origin/main".

Actions: *neogit_branch_popup_actions*
Actions for the branch popup are split into three categories: "Checkout",
Expand Down
22 changes: 22 additions & 0 deletions lua/neogit/buffers/commit_select_view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local a = require("plenary.async")
local Buffer = require("neogit.lib.buffer")
local ui = require("neogit.buffers.commit_select_view.ui")
local config = require("neogit.config")
local util = require("neogit.lib.util")

---@class CommitSelectViewBuffer
---@field commits CommitLogEntry[]
Expand Down Expand Up @@ -43,6 +44,27 @@ function M:open(action)
filetype = "NeogitCommitSelectView",
kind = config.values.commit_select_view.kind,
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
)

if action and commits[1] then
vim.schedule(function()
self:close()
end)

action(util.reverse(commits))
action = nil
end
end,
},
n = {
["<tab>"] = function()
-- no-op
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 @@ -52,7 +52,7 @@ function M:open()
end
)

CherryPickPopup.create { commits = commits }
CherryPickPopup.create { commits = util.reverse(commits) }
end,
["v"] = function()
-- local commits = util.filter_map(
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 @@ -48,7 +48,7 @@ function M:open()
end
)

CherryPickPopup.create { commits = commits }
CherryPickPopup.create { commits = util.reverse(commits) }
end,
["v"] = function()
-- local commits = util.filter_map(
Expand Down
16 changes: 16 additions & 0 deletions lua/neogit/lib/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ local function flatten(tbl)
return t
end

---@generic T: any
---@param tbl T[]
---@return T[]
--- Reverses list-like table
local function reverse(tbl)
local t = {}
local c = #tbl + 1

for i, v in ipairs(tbl) do
t[c - i] = v
end

return t
end

---@generic T: any
---@generic U: any
---@param list T[]
Expand Down Expand Up @@ -331,4 +346,5 @@ return {
remove_item_from_table = remove_item_from_table,
lists_equal = lists_equal,
pad_right = pad_right,
reverse = reverse,
}

0 comments on commit f756cf2

Please sign in to comment.