From 9706007f2d61a096f43de677a7a91dc9c9063e06 Mon Sep 17 00:00:00 2001 From: Brian Pritchett Date: Wed, 22 Feb 2023 10:07:07 -0600 Subject: [PATCH 1/4] Implement fetch popup --- README.md | 3 ++ doc/neogit.txt | 2 ++ doc/tags | 1 + lua/neogit/config.lua | 1 + lua/neogit/lib/git/cli.lua | 1 + lua/neogit/lib/git/fetch.lua | 14 +++++++++ lua/neogit/popups.lua | 1 + lua/neogit/popups/fetch.lua | 59 ++++++++++++++++++++++++++++++++++++ lua/neogit/popups/help.lua | 3 ++ lua/neogit/status.lua | 1 + 10 files changed, 86 insertions(+) create mode 100644 lua/neogit/lib/git/fetch.lua create mode 100644 lua/neogit/popups/fetch.lua diff --git a/README.md b/README.md index c3460169b..20c0c8ab9 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ The create function takes 1 optional argument that can be one of the following v | c | Open commit popup | | r | Open rebase popup | | m | Open merge popup | +| f | Open fetch popup | | L | Open log popup | | p | Open pull popup | | P | Open push popup | @@ -231,6 +232,7 @@ List of status commands: - HelpPopup - PullPopup - PushPopup +- FetchPopup - CommitPopup - LogPopup - StashPopup @@ -288,6 +290,7 @@ Neogit emits the following events: | `NeogitCommitComplete` | Commit has been created | | `NeogitPushComplete` | Push has completed | | `NeogitPullComplete` | Pull has completed | +| `NeogitFetchComplete` | Fetch has completed | You can listen to the events using the following code: diff --git a/doc/neogit.txt b/doc/neogit.txt index 38cd07a6b..196d02920 100644 --- a/doc/neogit.txt +++ b/doc/neogit.txt @@ -100,6 +100,8 @@ p Open pull popup *neogit_P* P Open push popup + *neogit_f* +f Open fetch popup ============================================================================== 4. Highlights *neogit-highlights* diff --git a/doc/tags b/doc/tags index 37f6d8cd3..65266177c 100644 --- a/doc/tags +++ b/doc/tags @@ -24,3 +24,4 @@ neogit_p neogit.txt /*neogit_p* neogit_s neogit.txt /*neogit_s* neogit_u neogit.txt /*neogit_u* neogit_x neogit.txt /*neogit_x* +neogit_f neogit.txt /*neogit_f* diff --git a/lua/neogit/config.lua b/lua/neogit/config.lua index 9b2f19dde..507f4aae3 100644 --- a/lua/neogit/config.lua +++ b/lua/neogit/config.lua @@ -96,6 +96,7 @@ M.values = { ["L"] = "LogPopup", ["Z"] = "StashPopup", ["b"] = "BranchPopup", + ["f"] = "FetchPopup", }, }, } diff --git a/lua/neogit/lib/git/cli.lua b/lua/neogit/lib/git/cli.lua index 04e6edd09..a918c01bf 100644 --- a/lua/neogit/lib/git/cli.lua +++ b/lua/neogit/lib/git/cli.lua @@ -227,6 +227,7 @@ local configurations = { end, }, }, + fetch = config {}, ["read-tree"] = config { flags = { merge = "-m", diff --git a/lua/neogit/lib/git/fetch.lua b/lua/neogit/lib/git/fetch.lua new file mode 100644 index 000000000..fc04427c0 --- /dev/null +++ b/lua/neogit/lib/git/fetch.lua @@ -0,0 +1,14 @@ +local cli = require("neogit.lib.git.cli") + +local M = {} + +---Fetches from the remote and handles password questions +---@param remote string +---@param branch string +---@param args string[] +---@return ProcessResult +function M.fetch_interactive(remote, branch, args) + return cli.fetch.args(remote or "", branch or "").arg_list(args).call_interactive() +end + +return M diff --git a/lua/neogit/popups.lua b/lua/neogit/popups.lua index cd7ecb542..87d15983d 100644 --- a/lua/neogit/popups.lua +++ b/lua/neogit/popups.lua @@ -5,4 +5,5 @@ return { pull = require("neogit.popups.pull"), stash = require("neogit.popups.stash"), help = require("neogit.popups.help"), + fetch = require("neogit.popups.fetch"), } diff --git a/lua/neogit/popups/fetch.lua b/lua/neogit/popups/fetch.lua new file mode 100644 index 000000000..fc59c1a5c --- /dev/null +++ b/lua/neogit/popups/fetch.lua @@ -0,0 +1,59 @@ +local popup = require("neogit.lib.popup") +local git = require("neogit.lib.git") +local a = require("plenary.async") +local notif = require("neogit.lib.notification") +local fetch_lib = require("neogit.lib.git.fetch") +local input = require("neogit.lib.input") +local status = require("neogit.status") + +local M = {} + +local function fetch_from(name, remote, branch, args) + notif.create("Fetching from " .. name) + local res = fetch_lib.fetch_interactive(remote, branch, args) + + if res and res.code == 0 then + a.util.scheduler() + notif.create("Fetched from " .. name) + vim.cmd("do User NeogitFetchComplete") + end +end + +function M.create() + local p = popup + .builder() + :name("NeogitFetchPopup") + :switch("p", "prune", "Prune deleted branches", false) + :switch("t", "tags", "Fetch all tags", false) + :action("p", "Fetch from pushremote", function(popup) + + fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) + end) + :action("u", "Fetch from upstream", function(popup) + + local upstream = git.branch.get_upstream() + if not upstream then + return + end + + fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) + end) + :action("a", "Fetch from all remotes", function(popup) + local args = popup:get_arguments() + table.insert(args, "--all") + + fetch_from("all remotes", "", "", args) + end) + :action("e", "Fetch from elsewhere", function(popup) + local remote = input.get_user_input("remote: ") + local branch = git.branch.prompt_for_branch() + fetch_from(remote .. ' ' .. branch, remote, branch, popup:get_arguments()) + end) + :build() + + p:show() + + return p +end + +return M diff --git a/lua/neogit/popups/help.lua b/lua/neogit/popups/help.lua index 2cfa1c58f..7a5a18aef 100644 --- a/lua/neogit/popups/help.lua +++ b/lua/neogit/popups/help.lua @@ -31,6 +31,9 @@ function M.create(env) :action("b", "Branch", function() require("neogit.popups.branch").create() end) + :action("f", "Fetch", function() + require('neogit.popups.fetch').create() + end) :action("$", "Git Command History", function() GitCommandHistory:new():show() end) diff --git a/lua/neogit/status.lua b/lua/neogit/status.lua index 09b5fc1d9..7d131b599 100644 --- a/lua/neogit/status.lua +++ b/lua/neogit/status.lua @@ -1019,6 +1019,7 @@ local cmd_func_map = function() } end, ["BranchPopup"] = require("neogit.popups.branch").create, + ["FetchPopup"] = require("neogit.popups.fetch").create, } end From f11d3a031d4b03f61f224b4dc75452c41efd2d4a Mon Sep 17 00:00:00 2001 From: Tei Roberts Date: Mon, 27 Feb 2023 14:32:32 +0100 Subject: [PATCH 2/4] fix: stylua --- lua/neogit/popups/fetch.lua | 56 ++++++++++++++++++------------------- lua/neogit/popups/help.lua | 2 +- 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/lua/neogit/popups/fetch.lua b/lua/neogit/popups/fetch.lua index fc59c1a5c..c4f891764 100644 --- a/lua/neogit/popups/fetch.lua +++ b/lua/neogit/popups/fetch.lua @@ -21,35 +21,33 @@ end function M.create() local p = popup - .builder() - :name("NeogitFetchPopup") - :switch("p", "prune", "Prune deleted branches", false) - :switch("t", "tags", "Fetch all tags", false) - :action("p", "Fetch from pushremote", function(popup) - - fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) - end) - :action("u", "Fetch from upstream", function(popup) - - local upstream = git.branch.get_upstream() - if not upstream then - return - end - - fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) - end) - :action("a", "Fetch from all remotes", function(popup) - local args = popup:get_arguments() - table.insert(args, "--all") - - fetch_from("all remotes", "", "", args) - end) - :action("e", "Fetch from elsewhere", function(popup) - local remote = input.get_user_input("remote: ") - local branch = git.branch.prompt_for_branch() - fetch_from(remote .. ' ' .. branch, remote, branch, popup:get_arguments()) - end) - :build() + .builder() + :name("NeogitFetchPopup") + :switch("p", "prune", "Prune deleted branches", false) + :switch("t", "tags", "Fetch all tags", false) + :action("p", "Fetch from pushremote", function(popup) + fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) + end) + :action("u", "Fetch from upstream", function(popup) + local upstream = git.branch.get_upstream() + if not upstream then + return + end + + fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) + end) + :action("a", "Fetch from all remotes", function(popup) + local args = popup:get_arguments() + table.insert(args, "--all") + + fetch_from("all remotes", "", "", args) + end) + :action("e", "Fetch from elsewhere", function(popup) + local remote = input.get_user_input("remote: ") + local branch = git.branch.prompt_for_branch() + fetch_from(remote .. " " .. branch, remote, branch, popup:get_arguments()) + end) + :build() p:show() diff --git a/lua/neogit/popups/help.lua b/lua/neogit/popups/help.lua index 7a5a18aef..2b29df99a 100644 --- a/lua/neogit/popups/help.lua +++ b/lua/neogit/popups/help.lua @@ -32,7 +32,7 @@ function M.create(env) require("neogit.popups.branch").create() end) :action("f", "Fetch", function() - require('neogit.popups.fetch').create() + require("neogit.popups.fetch").create() end) :action("$", "Git Command History", function() GitCommandHistory:new():show() From a79369849e195846005f556099bc10d386e8d5c9 Mon Sep 17 00:00:00 2001 From: Brian Pritchett Date: Wed, 22 Feb 2023 10:07:07 -0600 Subject: [PATCH 3/4] Implement fetch popup --- lua/neogit/popups/fetch.lua | 56 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/lua/neogit/popups/fetch.lua b/lua/neogit/popups/fetch.lua index c4f891764..fc59c1a5c 100644 --- a/lua/neogit/popups/fetch.lua +++ b/lua/neogit/popups/fetch.lua @@ -21,33 +21,35 @@ end function M.create() local p = popup - .builder() - :name("NeogitFetchPopup") - :switch("p", "prune", "Prune deleted branches", false) - :switch("t", "tags", "Fetch all tags", false) - :action("p", "Fetch from pushremote", function(popup) - fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) - end) - :action("u", "Fetch from upstream", function(popup) - local upstream = git.branch.get_upstream() - if not upstream then - return - end - - fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) - end) - :action("a", "Fetch from all remotes", function(popup) - local args = popup:get_arguments() - table.insert(args, "--all") - - fetch_from("all remotes", "", "", args) - end) - :action("e", "Fetch from elsewhere", function(popup) - local remote = input.get_user_input("remote: ") - local branch = git.branch.prompt_for_branch() - fetch_from(remote .. " " .. branch, remote, branch, popup:get_arguments()) - end) - :build() + .builder() + :name("NeogitFetchPopup") + :switch("p", "prune", "Prune deleted branches", false) + :switch("t", "tags", "Fetch all tags", false) + :action("p", "Fetch from pushremote", function(popup) + + fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) + end) + :action("u", "Fetch from upstream", function(popup) + + local upstream = git.branch.get_upstream() + if not upstream then + return + end + + fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) + end) + :action("a", "Fetch from all remotes", function(popup) + local args = popup:get_arguments() + table.insert(args, "--all") + + fetch_from("all remotes", "", "", args) + end) + :action("e", "Fetch from elsewhere", function(popup) + local remote = input.get_user_input("remote: ") + local branch = git.branch.prompt_for_branch() + fetch_from(remote .. ' ' .. branch, remote, branch, popup:get_arguments()) + end) + :build() p:show() From 1a5395fa4f60fa2fc36c5f7dea0e20e79fe2042a Mon Sep 17 00:00:00 2001 From: Brian Pritchett Date: Fri, 14 Apr 2023 07:28:17 -0500 Subject: [PATCH 4/4] stylua --- lua/neogit/popups/fetch.lua | 56 ++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 29 deletions(-) diff --git a/lua/neogit/popups/fetch.lua b/lua/neogit/popups/fetch.lua index fc59c1a5c..c4f891764 100644 --- a/lua/neogit/popups/fetch.lua +++ b/lua/neogit/popups/fetch.lua @@ -21,35 +21,33 @@ end function M.create() local p = popup - .builder() - :name("NeogitFetchPopup") - :switch("p", "prune", "Prune deleted branches", false) - :switch("t", "tags", "Fetch all tags", false) - :action("p", "Fetch from pushremote", function(popup) - - fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) - end) - :action("u", "Fetch from upstream", function(popup) - - local upstream = git.branch.get_upstream() - if not upstream then - return - end - - fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) - end) - :action("a", "Fetch from all remotes", function(popup) - local args = popup:get_arguments() - table.insert(args, "--all") - - fetch_from("all remotes", "", "", args) - end) - :action("e", "Fetch from elsewhere", function(popup) - local remote = input.get_user_input("remote: ") - local branch = git.branch.prompt_for_branch() - fetch_from(remote .. ' ' .. branch, remote, branch, popup:get_arguments()) - end) - :build() + .builder() + :name("NeogitFetchPopup") + :switch("p", "prune", "Prune deleted branches", false) + :switch("t", "tags", "Fetch all tags", false) + :action("p", "Fetch from pushremote", function(popup) + fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments()) + end) + :action("u", "Fetch from upstream", function(popup) + local upstream = git.branch.get_upstream() + if not upstream then + return + end + + fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments()) + end) + :action("a", "Fetch from all remotes", function(popup) + local args = popup:get_arguments() + table.insert(args, "--all") + + fetch_from("all remotes", "", "", args) + end) + :action("e", "Fetch from elsewhere", function(popup) + local remote = input.get_user_input("remote: ") + local branch = git.branch.prompt_for_branch() + fetch_from(remote .. " " .. branch, remote, branch, popup:get_arguments()) + end) + :build() p:show()