Skip to content

Commit

Permalink
Respect "push.autoSetupRemote" - when pushing a branch to pushremote, if
Browse files Browse the repository at this point in the history
the value is true, add "--set-upstream" flag to CLI call.

Closes #1508
  • Loading branch information
CKolkey committed Oct 18, 2024
1 parent c80d4b1 commit 5e928fe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
18 changes: 18 additions & 0 deletions lua/neogit/lib/git/push.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,24 @@ function M.push_interactive(remote, branch, args)
return git.cli.push.args(remote or "", branch or "").arg_list(args).call { pty = true }
end

---@param branch string
---@return boolean
function M.auto_setup_remote(branch)
local push_autoSetupRemote = git.config.get("push.autoSetupRemote"):read()
or git.config.get_global("push.autoSetupRemote"):read()

local push_default = git.config.get("push.default"):read()
or git.config.get_global("push.default"):read()

local branch_remote = git.config.get("branch." .. branch .. ".remote"):read()

return (
push_autoSetupRemote
and (push_default == "current" or push_default == "simple" or push_default == "upstream")
and not branch_remote
) == true
end

local function update_unmerged(state)
local status = git.branch.status()

Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/popups/push/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ local M = {}
local function push_to(args, remote, branch, opts)
opts = opts or {}

if opts.set_upstream then
if opts.set_upstream or git.push.auto_setup_remote(branch) then
table.insert(args, "--set-upstream")
end

Expand Down

0 comments on commit 5e928fe

Please sign in to comment.