Skip to content

Commit

Permalink
Merge pull request #716 from NeogitOrg/fetch-documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Aug 7, 2023
2 parents 00af4ee + 3ad3e31 commit e5e85b3
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 29 deletions.
57 changes: 57 additions & 0 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -638,4 +638,61 @@ Actions: *neogit_commit_popup_actions*
• Instant Squash *neogit_commit_instant_squash*
Similar to |neogit_commit_squash|, but instantly rebases after.

==============================================================================
Fetch Popup *neogit_fetch_popup*

Arguments: *neogit_fetch_popup_args*
• --prune
Before fetching, remove any remote-tracking references that no longer
exist on the remote. Tags are not subject to pruning if they are fetched
only because of the default tag auto-following or due to a --tags option.

However, if tags are fetched due to an explicit refspec (either on the
command line or in the remote configuration, for example if the remote was
cloned with the --mirror option), then they are also subject to pruning.

• --tags
Fetch all tags from the remote (i.e., fetch remote tags refs/tags/* into
local tags with the same name), in addition to whatever else would
otherwise be fetched. Using this option alone does not subject tags to
pruning, even if --prune is used (though tags may be pruned anyway if
they are also the destination of an explicit refspec; see --prune).


Actions: *neogit_fetch_popup_actions*

• Fetch from pushRemote *neogit_fetch_pushremote*
Fetches from the current pushRemote.

When the pushRemote is not configured, the user will be prompted to choose
from the existing remotes to set it.

• Fetch from upstream *neogit_fetch_upstream*
Fetches from the upstream of the current branch.

If the upstream is configured for the current branch and names an existing
remote, then use that. Otherwise try to use another remote: If only a
single remote is configured, then use that. Otherwise if a remote named
"origin" exists, then use that.

• Fetch from elsewhere *neogit_fetch_elsewhere*
Provides a select interface for the user to choose which remote to fetch
from.

• Fetch from All Remotes *neogit_fetch_all*
Fetches from all configured remotes.

• Fetch Another Branch *neogit_fetch_branch*
Fetches only a specific branch from a remote, both of which are selected
by the user.

• Fetch Explicit Refspec *neogit_fetch_refspec*
Fetches from a remote using an explicit refspec.

• Fetch Submodules *neogit_fetch_submodules*
Fetches all submodules.

• Set Variables *neogit_fetch_set_variables*
Opens Branch Config popup for the current branch.

vim:tw=78:ts=8:ft=help
18 changes: 8 additions & 10 deletions lua/neogit/lib/git/branch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ function M.set_pushRemote()
end

if pushRemote then
config_lib.set(
string.format("branch.%s.pushRemote", require("neogit.lib.git").repo.head.branch),
pushRemote
)
config_lib.set(string.format("branch.%s.pushRemote", M.current()), pushRemote)
end

return pushRemote
Expand All @@ -155,19 +152,20 @@ function M.upstream_label()
return M.upstream() or "@{upstream}, creating it"
end

function M.upstream_remote_label()
return M.upstream_remote() or "@{upstream}, setting it"
end

function M.upstream_remote()
local git = require("neogit.lib.git")
local remote = git.repo.upstream.remote

if not remote then
local remotes = git.remote.list()

if git.config.get("push.autoSetupRemote").value == "true" and vim.tbl_contains(remotes, "origin") then
remote = "origin"
elseif #remotes == 1 then
if #remotes == 1 then
remote = remotes[1]
else
remote = FuzzyFinderBuffer.new(remotes):open_async { prompt_prefix = "remote > " }
elseif vim.tbl_contains(remotes, "origin") then
remote = "origin"
end
end

Expand Down
20 changes: 15 additions & 5 deletions lua/neogit/lib/git/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ function ConfigEntry.new(name, value, scope)
}, ConfigEntry)
end

-- ---@return string
-- function ConfigEntry:value()
-- return self._value or ""
-- end

---@return string
function ConfigEntry:type()
if self.value == "true" or self.value == "false" then
Expand All @@ -41,6 +36,21 @@ function ConfigEntry:is_set()
return self.value ~= ""
end

---@return boolean|number|string|nil
function ConfigEntry:read()
if not self:is_set() then
return nil
end

if self:type() == "boolean" then
return self.value == "true"
elseif self:type() == "number" then
return tonumber(self.value)
else
return self.value
end
end

---@return nil
function ConfigEntry:update(value)
if not value or value == "" then
Expand Down
10 changes: 6 additions & 4 deletions lua/neogit/lib/popup.lua
Original file line number Diff line number Diff line change
Expand Up @@ -570,15 +570,17 @@ function M:show()
vim.cmd([[setlocal nocursorline]])

if self.state.env.highlight then
for _, text in ipairs(self.state.env.highlight) do
vim.fn.matchadd("NeogitPopupBranchName", text, 100)
for i = 1, #self.state.env.highlight, 1 do
vim.fn.matchadd("NeogitPopupBranchName", self.state.env.highlight[i], 100)
end
else
vim.fn.matchadd("NeogitPopupBranchName", git.repo.head.branch, 100)
end

for _, text in ipairs(self.state.env.bold or {}) do
vim.fn.matchadd("NeogitPopupBold", text, 100)
if self.state.env.bold then
for i = 1, #self.state.env.bold, 1 do
vim.fn.matchadd("NeogitPopupBold", self.state.env.bold[i], 100)
end
end

if config.values.popup.kind == "split" or config.values.popup.kind == "split_above" then
Expand Down
19 changes: 16 additions & 3 deletions lua/neogit/popups/fetch/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ local util = require("neogit.lib.util")

local FuzzyFinderBuffer = require("neogit.buffers.fuzzy_finder")

local function select_remote()
return FuzzyFinderBuffer.new(git.remote.list()):open_async { prompt_prefix = "remote > " }
end

local function fetch_from(name, remote, branch, args)
notif.create("Fetching from " .. name)
local res = git.fetch.fetch_interactive(remote, branch, args)
Expand Down Expand Up @@ -39,6 +43,15 @@ function M.fetch_upstream(popup)
local upstream = git.branch.upstream_remote()
if upstream then
fetch_from(upstream, upstream, "", popup:get_arguments())
else
upstream = select_remote()

if upstream then
local args = popup:get_arguments()
table.insert(args, "--set-upstream")

fetch_from(upstream, upstream, "", args)
end
end
end

Expand All @@ -50,7 +63,7 @@ function M.fetch_all_remotes(popup)
end

function M.fetch_elsewhere(popup)
local remote = FuzzyFinderBuffer.new(git.remote.list()):open_async { prompt_prefix = "remote > " }
local remote = select_remote()
if not remote then
logger.error("No remote selected")
return
Expand All @@ -65,7 +78,7 @@ end
-- git@

function M.fetch_another_branch(popup)
local remote = FuzzyFinderBuffer.new(git.remote.list()):open_async { prompt_prefix = "remote > " }
local remote = select_remote()
if not remote then
return
end
Expand All @@ -85,7 +98,7 @@ function M.fetch_another_branch(popup)
end

function M.fetch_refspec(popup)
local remote = FuzzyFinderBuffer.new(git.remote.list()):open_async { prompt_prefix = "remote > " }
local remote = select_remote()
if not remote then
return
end
Expand Down
9 changes: 5 additions & 4 deletions lua/neogit/popups/fetch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,14 @@ local popup = require("neogit.lib.popup")
local M = {}

function M.create()
local upstream = git.branch.upstream_remote()

local p = popup
.builder()
:name("NeogitFetchPopup")
:switch("p", "prune", "Prune deleted branches")
:switch("t", "tags", "Fetch all tags")
:group_heading("Fetch from")
:action("p", git.branch.pushRemote_label(), actions.fetch_pushremote)
:action_if(upstream, "u", upstream, actions.fetch_upstream)
:action("u", git.branch.upstream_remote_label(), actions.fetch_upstream)
:action("e", "elsewhere", actions.fetch_elsewhere)
:action("a", "all remotes", actions.fetch_all_remotes)
:new_action_group("Fetch")
Expand All @@ -23,7 +21,10 @@ function M.create()
:action("m", "submodules", actions.fetch_submodules)
:new_action_group("Configure")
:action("C", "Set variables...", actions.set_variables)
:env({ highlight = { git.branch.pushRemote(), upstream }, bold = { "pushRemote" } })
:env({
highlight = { git.branch.pushRemote(), git.branch.upstream_remote() },
bold = { "@{upstream}", "pushRemote" },
})
:build()

p:show()
Expand Down
7 changes: 4 additions & 3 deletions lua/neogit/popups/push/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,21 @@ function M.to_pushremote(popup)
end

if pushRemote then
push_to(popup:get_arguments(), pushRemote, git.repo.head.branch)
push_to(popup:get_arguments(), pushRemote, git.branch.current())
end
end

function M.to_upstream(popup)
local upstream = git.repo.upstream.ref
local upstream = git.branch.upstream()
local remote, branch, set_upstream

if upstream then
remote, branch = upstream:match("^([^/]*)/(.*)$")
else
set_upstream = true
branch = git.repo.head.branch
branch = git.branch.current()
remote = git.branch.upstream_remote()
or FuzzyFinderBuffer.new(git.remote.list()):open_async { prompt_prefix = "remote > " }
end

if remote then
Expand Down

0 comments on commit e5e85b3

Please sign in to comment.