Skip to content

Commit bcafbc9

Browse files
committed
Implement fetch popup
1 parent 8538091 commit bcafbc9

File tree

10 files changed

+85
-0
lines changed

10 files changed

+85
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ List of status commands:
222222
* HelpPopup
223223
* PullPopup
224224
* PushPopup
225+
* FetchPopup
225226
* CommitPopup
226227
* LogPopup
227228
* StashPopup
@@ -278,6 +279,7 @@ Neogit emits the following events:
278279
| `NeogitCommitComplete` | Commit has been created |
279280
| `NeogitPushComplete` | Push has completed |
280281
| `NeogitPullComplete` | Pull has completed |
282+
| `NeogitFetchComplete` | Fetch has completed |
281283

282284
You can listen to the events using the following code:
283285

doc/neogit.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ p Open pull popup
100100

101101
*neogit_P*
102102
P Open push popup
103+
*neogit_f*
104+
f Open fetch popup
103105
==============================================================================
104106
4. Highlights *neogit-highlights*
105107

doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ neogit_p neogit.txt /*neogit_p*
2424
neogit_s neogit.txt /*neogit_s*
2525
neogit_u neogit.txt /*neogit_u*
2626
neogit_x neogit.txt /*neogit_x*
27+
neogit_f neogit.txt /*neogit_f*

lua/neogit/config.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ M.values = {
9292
["L"] = "LogPopup",
9393
["Z"] = "StashPopup",
9494
["b"] = "BranchPopup",
95+
["f"] = "FetchPopup",
9596
},
9697
},
9798
}

lua/neogit/lib/git/cli.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ local configurations = {
221221
end,
222222
},
223223
},
224+
fetch = config {},
224225
["read-tree"] = config {
225226
flags = {
226227
merge = "-m",

lua/neogit/lib/git/fetch.lua

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
local cli = require("neogit.lib.git.cli")
2+
3+
local M = {}
4+
5+
---Fetches from the remote and handles password questions
6+
---@param remote string
7+
---@param branch string
8+
---@param args string[]
9+
---@return ProcessResult
10+
function M.fetch_interactive(remote, branch, args)
11+
return cli.fetch.args(remote or "", branch or "").arg_list(args).call_interactive()
12+
end
13+
14+
return M

lua/neogit/popups.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ return {
55
pull = require("neogit.popups.pull"),
66
stash = require("neogit.popups.stash"),
77
help = require("neogit.popups.help"),
8+
fetch = require("neogit.popups.fetch"),
89
}

lua/neogit/popups/fetch.lua

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
local popup = require("neogit.lib.popup")
2+
local git = require("neogit.lib.git")
3+
local a = require("plenary.async")
4+
local notif = require("neogit.lib.notification")
5+
local fetch_lib = require("neogit.lib.git.fetch")
6+
local input = require("neogit.lib.input")
7+
local status = require("neogit.status")
8+
9+
local M = {}
10+
11+
local function fetch_from(name, remote, branch, args)
12+
notif.create("Fetching from " .. name)
13+
local res = fetch_lib.fetch_interactive(remote, branch, args)
14+
15+
if res and res.code == 0 then
16+
a.util.scheduler()
17+
notif.create("Fetched from " .. name)
18+
vim.cmd("do <nomodeline> User NeogitFetchComplete")
19+
end
20+
end
21+
22+
function M.create()
23+
local p = popup
24+
.builder()
25+
:name("NeogitFetchPopup")
26+
:switch("p", "prune", "Prune deleted branches", false)
27+
:switch("t", "tags", "Fetch all tags", false)
28+
:action("p", "Fetch from pushremote", function(popup)
29+
30+
fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments())
31+
end)
32+
:action("u", "Fetch from upstream", function(popup)
33+
34+
local upstream = git.branch.get_upstream()
35+
if not upstream then
36+
return
37+
end
38+
39+
fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments())
40+
end)
41+
:action("a", "Fetch from all remotes", function(popup)
42+
local args = popup:get_arguments()
43+
table.insert(args, "--all")
44+
45+
fetch_from("all remotes", "", "", args)
46+
end)
47+
:action("e", "Fetch from elsewhere", function(popup)
48+
local remote = input.get_user_input("remote: ")
49+
local branch = git.branch.prompt_for_branch()
50+
fetch_from(remote .. ' ' .. branch, remote, branch, popup:get_arguments())
51+
end)
52+
:build()
53+
54+
p:show()
55+
56+
return p
57+
end
58+
59+
return M

lua/neogit/popups/help.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ function M.create(env)
3131
:action("b", "Branch", function()
3232
require("neogit.popups.branch").create()
3333
end)
34+
:action("f", "Fetch", function()
35+
require('neogit.popups.fetch').create()
36+
end)
3437
:action("$", "Git Command History", function()
3538
GitCommandHistory:new():show()
3639
end)

lua/neogit/status.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ local cmd_func_map = function()
981981
}
982982
end,
983983
["BranchPopup"] = require("neogit.popups.branch").create,
984+
["FetchPopup"] = require("neogit.popups.fetch").create,
984985
}
985986
end
986987

0 commit comments

Comments
 (0)