Skip to content

Commit 632cf80

Browse files
authored
Merge pull request #448 from pritchett/master
feat: Implement fetch popup
2 parents efc1764 + 1a5395f commit 632cf80

File tree

10 files changed

+84
-0
lines changed

10 files changed

+84
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ The create function takes 1 optional argument that can be one of the following v
8787
| c | Open commit popup |
8888
| r | Open rebase popup |
8989
| m | Open merge popup |
90+
| f | Open fetch popup |
9091
| L | Open log popup |
9192
| p | Open pull popup |
9293
| P | Open push popup |
@@ -231,6 +232,7 @@ List of status commands:
231232
- HelpPopup
232233
- PullPopup
233234
- PushPopup
235+
- FetchPopup
234236
- CommitPopup
235237
- LogPopup
236238
- StashPopup
@@ -288,6 +290,7 @@ Neogit emits the following events:
288290
| `NeogitCommitComplete` | Commit has been created |
289291
| `NeogitPushComplete` | Push has completed |
290292
| `NeogitPullComplete` | Pull has completed |
293+
| `NeogitFetchComplete` | Fetch has completed |
291294

292295
You can listen to the events using the following code:
293296

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
@@ -96,6 +96,7 @@ M.values = {
9696
["L"] = "LogPopup",
9797
["Z"] = "StashPopup",
9898
["b"] = "BranchPopup",
99+
["f"] = "FetchPopup",
99100
},
100101
},
101102
}

lua/neogit/lib/git/cli.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ local configurations = {
227227
end,
228228
},
229229
},
230+
fetch = config {},
230231
["read-tree"] = config {
231232
flags = {
232233
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: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
fetch_from("pushremote", "origin", status.repo.head.branch, popup:get_arguments())
30+
end)
31+
:action("u", "Fetch from upstream", function(popup)
32+
local upstream = git.branch.get_upstream()
33+
if not upstream then
34+
return
35+
end
36+
37+
fetch_from(upstream.remote, upstream.remote, "", popup:get_arguments())
38+
end)
39+
:action("a", "Fetch from all remotes", function(popup)
40+
local args = popup:get_arguments()
41+
table.insert(args, "--all")
42+
43+
fetch_from("all remotes", "", "", args)
44+
end)
45+
:action("e", "Fetch from elsewhere", function(popup)
46+
local remote = input.get_user_input("remote: ")
47+
local branch = git.branch.prompt_for_branch()
48+
fetch_from(remote .. " " .. branch, remote, branch, popup:get_arguments())
49+
end)
50+
:build()
51+
52+
p:show()
53+
54+
return p
55+
end
56+
57+
return M

lua/neogit/popups/help.lua

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

lua/neogit/status.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,7 @@ local cmd_func_map = function()
10191019
}
10201020
end,
10211021
["BranchPopup"] = require("neogit.popups.branch").create,
1022+
["FetchPopup"] = require("neogit.popups.fetch").create,
10221023
}
10231024
end
10241025

0 commit comments

Comments
 (0)