diff --git a/lua/neogit/lib/git/push.lua b/lua/neogit/lib/git/push.lua index db142273b..adf9eb9b8 100644 --- a/lua/neogit/lib/git/push.lua +++ b/lua/neogit/lib/git/push.lua @@ -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() diff --git a/lua/neogit/popups/push/actions.lua b/lua/neogit/popups/push/actions.lua index 03e782a12..8bd30f6e8 100644 --- a/lua/neogit/popups/push/actions.lua +++ b/lua/neogit/popups/push/actions.lua @@ -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