|
| 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 |
0 commit comments