Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -231,6 +232,7 @@ List of status commands:
- HelpPopup
- PullPopup
- PushPopup
- FetchPopup
- CommitPopup
- LogPopup
- StashPopup
Expand Down Expand Up @@ -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:

Expand Down
2 changes: 2 additions & 0 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ p Open pull popup

*neogit_P*
P Open push popup
*neogit_f*
f Open fetch popup
==============================================================================
4. Highlights *neogit-highlights*

Expand Down
1 change: 1 addition & 0 deletions doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -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*
1 change: 1 addition & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ M.values = {
["L"] = "LogPopup",
["Z"] = "StashPopup",
["b"] = "BranchPopup",
["f"] = "FetchPopup",
},
},
}
Expand Down
1 change: 1 addition & 0 deletions lua/neogit/lib/git/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ local configurations = {
end,
},
},
fetch = config {},
["read-tree"] = config {
flags = {
merge = "-m",
Expand Down
14 changes: 14 additions & 0 deletions lua/neogit/lib/git/fetch.lua
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lua/neogit/popups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
57 changes: 57 additions & 0 deletions lua/neogit/popups/fetch.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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 <nomodeline> 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
3 changes: 3 additions & 0 deletions lua/neogit/popups/help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions lua/neogit/status.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1019,6 +1019,7 @@ local cmd_func_map = function()
}
end,
["BranchPopup"] = require("neogit.popups.branch").create,
["FetchPopup"] = require("neogit.popups.fetch").create,
}
end

Expand Down