From 43b91a6f28fbd2a041ef5c1bbdfb3d3c0c8baa35 Mon Sep 17 00:00:00 2001 From: ejshafran Date: Tue, 23 Jul 2024 16:29:40 +0300 Subject: [PATCH 1/5] Add cherry-pick options/switches Not sure why these options were in a `TODO` comment; do we maybe need to keep it as a comment? --- lua/neogit/popups/cherry_pick/init.lua | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lua/neogit/popups/cherry_pick/init.lua b/lua/neogit/popups/cherry_pick/init.lua index fbef4d2a..deac0bb7 100644 --- a/lua/neogit/popups/cherry_pick/init.lua +++ b/lua/neogit/popups/cherry_pick/init.lua @@ -7,18 +7,16 @@ local M = {} function M.create(env) local in_progress = git.sequencer.pick_or_revert_in_progress() - -- TODO - -- :switch("x", "x", "Reference cherry in commit message", { cli_prefix = "-" }) - -- :switch("e", "edit", "Edit commit messages", false) - -- :switch("s", "signoff", "Add Signed-off-by lines", false) - -- :option("m", "mainline", "", "Replay merge relative to parent") - -- :option("s", "strategy", "", "Strategy") - -- :option("S", "gpg-sign", "", "Sign using gpg") - local p = popup .builder() :name("NeogitCherryPickPopup") :switch_if(not in_progress, "F", "ff", "Attempt fast-forward", { enabled = true }) + :switch_if(not in_progress, "x", "x", "Reference cherry in commit message", { cli_prefix = "-" }) + :switch_if(not in_progress, "e", "edit", "Edit commit messages", false) + :switch_if(not in_progress, "s", "signoff", "Add Signed-off-by lines", false) + :option_if(not in_progress, "m", "mainline", "", "Replay merge relative to parent") + :option_if(not in_progress, "s", "strategy", "", "Strategy") + :option_if(not in_progress, "S", "gpg-sign", "", "Sign using gpg") :group_heading_if(not in_progress, "Apply here") :action_if(not in_progress, "A", "Pick", actions.pick) :action_if(not in_progress, "a", "Apply", actions.apply) From 7e969ee076d210ea653c0502b42a32be16037db3 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 21:32:54 +0200 Subject: [PATCH 2/5] Make "cherry pick --edit" work with editor --- lua/neogit/lib/git/cherry_pick.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/neogit/lib/git/cherry_pick.lua b/lua/neogit/lib/git/cherry_pick.lua index 65d2b438..cdabcc91 100644 --- a/lua/neogit/lib/git/cherry_pick.lua +++ b/lua/neogit/lib/git/cherry_pick.lua @@ -1,6 +1,7 @@ local git = require("neogit.lib.git") local notification = require("neogit.lib.notification") local util = require("neogit.lib.util") +local client = require("neogit.client") ---@class NeogitGitCherryPick local M = {} @@ -10,7 +11,15 @@ local function fire_cherrypick_event(data) end function M.pick(commits, args) - local result = git.cli["cherry-pick"].arg_list(util.merge(args, commits)).call { async = false } + local cmd = git.cli["cherry-pick"].arg_list(util.merge(args, commits)) + + local result + if vim.tbl_contains(args, "--edit") then + result = cmd.env(client.get_envs_git_editor()).call { pty = true } + else + result = cmd.call { async = false } + end + if result.code ~= 0 then notification.error("Cherry Pick failed. Resolve conflicts before continuing") else From f420c48bbce66e107dc12e573c330251f50a592f Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 21:33:09 +0200 Subject: [PATCH 3/5] fix: --edit cannot be used with --ff --- lua/neogit/popups/cherry_pick/init.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/neogit/popups/cherry_pick/init.lua b/lua/neogit/popups/cherry_pick/init.lua index deac0bb7..dc58f36e 100644 --- a/lua/neogit/popups/cherry_pick/init.lua +++ b/lua/neogit/popups/cherry_pick/init.lua @@ -10,9 +10,15 @@ function M.create(env) local p = popup .builder() :name("NeogitCherryPickPopup") - :switch_if(not in_progress, "F", "ff", "Attempt fast-forward", { enabled = true }) + :switch_if( + not in_progress, + "F", + "ff", + "Attempt fast-forward", + { enabled = true, incompatible = { "edit" } } + ) :switch_if(not in_progress, "x", "x", "Reference cherry in commit message", { cli_prefix = "-" }) - :switch_if(not in_progress, "e", "edit", "Edit commit messages", false) + :switch_if(not in_progress, "e", "edit", "Edit commit messages", { incompatible = { "ff" } }) :switch_if(not in_progress, "s", "signoff", "Add Signed-off-by lines", false) :option_if(not in_progress, "m", "mainline", "", "Replay merge relative to parent") :option_if(not in_progress, "s", "strategy", "", "Strategy") From 64c2ac520b6b0c89d7c7edacda4ea83da74d57c2 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 21:43:45 +0200 Subject: [PATCH 4/5] Change ordering to match Magit, change key_prefix to match Magit, add strategy options, reorder options on merge popup to match order --- lua/neogit/popups/cherry_pick/init.lua | 19 ++++++++----------- lua/neogit/popups/merge/init.lua | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/lua/neogit/popups/cherry_pick/init.lua b/lua/neogit/popups/cherry_pick/init.lua index dc58f36e..daf94d56 100644 --- a/lua/neogit/popups/cherry_pick/init.lua +++ b/lua/neogit/popups/cherry_pick/init.lua @@ -10,19 +10,16 @@ function M.create(env) local p = popup .builder() :name("NeogitCherryPickPopup") - :switch_if( - not in_progress, - "F", - "ff", - "Attempt fast-forward", - { enabled = true, incompatible = { "edit" } } - ) + :option_if(not in_progress, "m", "mainline", "", "Replay merge relative to parent", { key_prefix = "-" }) + :option_if(not in_progress, "s", "strategy", "", "Strategy", { + key_prefix = "=", + choices = { "octopus", "ours", "resolve", "subtree", "recursive" }, + }) + :switch_if(not in_progress, "F", "ff", "Attempt fast-forward", { enabled = true, incompatible = { "edit" } }) :switch_if(not in_progress, "x", "x", "Reference cherry in commit message", { cli_prefix = "-" }) :switch_if(not in_progress, "e", "edit", "Edit commit messages", { incompatible = { "ff" } }) - :switch_if(not in_progress, "s", "signoff", "Add Signed-off-by lines", false) - :option_if(not in_progress, "m", "mainline", "", "Replay merge relative to parent") - :option_if(not in_progress, "s", "strategy", "", "Strategy") - :option_if(not in_progress, "S", "gpg-sign", "", "Sign using gpg") + :switch_if(not in_progress, "s", "signoff", "Add Signed-off-by lines") + :option_if(not in_progress, "S", "gpg-sign", "", "Sign using gpg", { key_prefix = "-" }) :group_heading_if(not in_progress, "Apply here") :action_if(not in_progress, "A", "Pick", actions.pick) :action_if(not in_progress, "a", "Apply", actions.apply) diff --git a/lua/neogit/popups/merge/init.lua b/lua/neogit/popups/merge/init.lua index 2ef0ef1f..8ec36b80 100644 --- a/lua/neogit/popups/merge/init.lua +++ b/lua/neogit/popups/merge/init.lua @@ -15,7 +15,7 @@ function M.create(env) :switch_if(not in_merge, "f", "ff-only", "Fast-forward only", { incompatible = { "no-ff" } }) :switch_if(not in_merge, "n", "no-ff", "No fast-forward", { incompatible = { "ff-only" } }) :option_if(not in_merge, "s", "strategy", "", "Strategy", { - choices = { "resolve", "recursive", "octopus", "ours", "subtree" }, + choices = { "octopus", "ours", "resolve", "subtree", "recursive" }, key_prefix = "-", }) :option_if(not in_merge, "X", "strategy-option", "", "Strategy Option", { From 1a44aa4d25ff5175bdbffa395d82bdbefe543a5c Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 23 Jul 2024 22:11:07 +0200 Subject: [PATCH 5/5] Linting --- lua/neogit/popups/cherry_pick/init.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lua/neogit/popups/cherry_pick/init.lua b/lua/neogit/popups/cherry_pick/init.lua index daf94d56..180d476a 100644 --- a/lua/neogit/popups/cherry_pick/init.lua +++ b/lua/neogit/popups/cherry_pick/init.lua @@ -15,7 +15,13 @@ function M.create(env) key_prefix = "=", choices = { "octopus", "ours", "resolve", "subtree", "recursive" }, }) - :switch_if(not in_progress, "F", "ff", "Attempt fast-forward", { enabled = true, incompatible = { "edit" } }) + :switch_if( + not in_progress, + "F", + "ff", + "Attempt fast-forward", + { enabled = true, incompatible = { "edit" } } + ) :switch_if(not in_progress, "x", "x", "Reference cherry in commit message", { cli_prefix = "-" }) :switch_if(not in_progress, "e", "edit", "Edit commit messages", { incompatible = { "ff" } }) :switch_if(not in_progress, "s", "signoff", "Add Signed-off-by lines")