Skip to content

Commit

Permalink
Change git.config.get() to query both local and global values, and
Browse files Browse the repository at this point in the history
create git.config.get_local() api to get local only. This reflects the
existing .get_global() function.
  • Loading branch information
CKolkey committed Oct 31, 2024
1 parent 001f43f commit 7bc6bc4
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
5 changes: 1 addition & 4 deletions lua/neogit/buffers/editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ function M:open(kind)
return pad(mapping[name] and mapping[name][1] or "<NOP>", padding)
end

local comment_char = git.config.get("core.commentChar"):read()
or git.config.get_global("core.commentChar"):read()
or "#"

local comment_char = git.config.get("core.commentChar"):read() or "#"
logger.debug("[EDITOR] Using comment character '" .. comment_char .. "'")

-- stylua: ignore
Expand Down
5 changes: 1 addition & 4 deletions lua/neogit/buffers/rebase_editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ function M.new(filename, on_unload)
end

function M:open(kind)
local comment_char = git.config.get("core.commentChar"):read()
or git.config.get_global("core.commentChar"):read()
or "#"

local comment_char = git.config.get("core.commentChar"):read() or "#"
local mapping = config.get_reversed_rebase_editor_maps()
local mapping_I = config.get_reversed_rebase_editor_maps_I()
local aborted = false
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/buffers/refs_view/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ function M.Remotes(remotes, head)
text.highlight("NeogitBranch")("Remote "),
text.highlight("NeogitRemote")(name, { align_right = max_len }),
text.highlight("NeogitBranch")(
string.format(" (%s)", git.config.get(string.format("remote.%s.url", name)):read())
string.format(" (%s)", git.config.get_local(string.format("remote.%s.url", name)):read())
),
}, head)
)
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/lib/git/branch.lua
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function M.pushRemote(branch)
branch = branch or M.current()

if branch then
local remote = git.config.get("branch." .. branch .. ".pushRemote")
local remote = git.config.get_local("branch." .. branch .. ".pushRemote")
if remote:is_set() then
return remote.value
end
Expand Down
13 changes: 12 additions & 1 deletion lua/neogit/lib/git/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,13 @@ end

---@return ConfigEntry
function M.get(key)
return config()[key:lower()] or ConfigEntry.new(key, "", "local")
if M.get_local(key):is_set() then
return M.get_local(key)
elseif M.get_global(key):is_set() then
return M.get_global(key)
else
return ConfigEntry.new(key, "", "local")
end
end

---@return ConfigEntry
Expand All @@ -118,6 +124,11 @@ function M.get_global(key)
return ConfigEntry.new(key, result, "global")
end

---@return ConfigEntry
function M.get_local(key)
return config()[key:lower()] or ConfigEntry.new(key, "", "local")
end

function M.get_matching(pattern)
local matches = {}
for key, value in pairs(config()) do
Expand Down
7 changes: 2 additions & 5 deletions lua/neogit/lib/git/push.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ function M.auto_setup_remote(branch)
end

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()
local push_default = git.config.get("push.default"):read()
local branch_remote = git.config.get_local("branch." .. branch .. ".remote"):read()

return (
push_autoSetupRemote
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/lib/git/remote.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local M = {}

-- https://github.com/magit/magit/blob/main/lisp/magit-remote.el#LL141C32-L141C32
local function cleanup_push_variables(remote, new_name)
if remote == git.config.get("remote.pushDefault").value then
if remote == git.config.get("remote.pushDefault"):read() then
git.config.set("remote.pushDefault", new_name)
end

Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/lib/popup/builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ local M = {}
---@field id string
---@field key string
---@field name string
---@field entry string
---@field entry ConfigEntry
---@field value string
---@field type string

Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/popups/branch_config/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function M.description_config(branch)
})
vim.o.eventignore = ""

return git.config.get("branch." .. branch .. ".description"):read()
return git.config.get_local("branch." .. branch .. ".description"):read()
end

return a.wrap(fn, 2)
Expand Down
2 changes: 1 addition & 1 deletion lua/neogit/popups/branch_config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ local actions = require("neogit.popups.branch_config.actions")
function M.create(branch)
branch = branch or git.branch.current()
local g_pull_rebase = git.config.get_global("pull.rebase")
local pull_rebase_entry = git.config.get("pull.rebase")
local pull_rebase_entry = git.config.get_local("pull.rebase")
local pull_rebase = pull_rebase_entry:is_set() and pull_rebase_entry.value or "false"

local p = popup
Expand Down
8 changes: 6 additions & 2 deletions lua/neogit/popups/remote/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ function M.add(popup)
return
end

local origin = git.config.get("remote.origin.url").value
local host, _, remote = origin:match("([^:/]+)[:/]([^/]+)/(.+)")
local origin = git.config.get("remote.origin.url"):read()
if not origin then
return
end

assert(type(origin) == "string", "remote.origin.url isn't a string")
local host, _, remote = origin:match("([^:/]+)[:/]([^/]+)/(.+)")
remote = remote and remote:gsub("%.git$", "")

local msg
Expand Down

0 comments on commit 7bc6bc4

Please sign in to comment.