Skip to content

Commit

Permalink
Merge pull request #935 from NeogitOrg/fix/multiline-descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey authored Nov 13, 2023
2 parents d3c5687 + e5d6d0a commit c28cd00
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 4 deletions.
44 changes: 44 additions & 0 deletions lua/neogit/buffers/description_editor.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
local Buffer = require("neogit.lib.buffer")
local config = require("neogit.config")

local M = {}

function M.new(filename, on_close)
local instance = {
filename = filename,
on_close = on_close,
buffer = nil,
}

setmetatable(instance, { __index = M })

return instance
end

function M:open()
self.buffer = Buffer.create {
name = self.filename,
load = true,
filetype = "NeogitBranchDescription",
buftype = "",
kind = config.values.description_editor.kind,
modifiable = true,
readonly = false,
autocmds = {
["BufUnload"] = function()
self.on_close()
vim.cmd("silent w!")
require("neogit.process").defer_show_preview_buffers()
end,
},
mappings = {
n = {
["q"] = function(buffer)
buffer:close(true)
end,
},
},
}
end

return M
2 changes: 2 additions & 0 deletions lua/neogit/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ function M.editor(target, client)
editor.merge_editor(target, send_client_quit)
elseif target:find("TAG_EDITMSG$") then
editor.tag_editor(target, send_client_quit)
elseif target:find("EDIT_DESCRIPTION$") then
editor.description_editor(target, send_client_quit)
else
local notification = require("neogit.lib.notification")
notification.warn(target .. " has not been implemented yet")
Expand Down
4 changes: 4 additions & 0 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ end
---@field rebase_editor? NeogitConfigPopup Rebase editor options
---@field reflog_view? NeogitConfigPopup Reflog view options
---@field merge_editor? NeogitConfigPopup Merge editor options
---@field description_editor? NeogitConfigPopup Merge editor options
---@field tag_editor? NeogitConfigPopup Tag editor options
---@field preview_buffer? NeogitConfigPopup Preview options
---@field popup? NeogitConfigPopup Set the default way of opening popups
Expand Down Expand Up @@ -189,6 +190,9 @@ function M.get_default_values()
merge_editor = {
kind = "auto",
},
description_editor = {
kind = "auto",
},
tag_editor = {
kind = "auto",
},
Expand Down
5 changes: 5 additions & 0 deletions lua/neogit/editor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local RebaseEditorBuffer = require("neogit.buffers.rebase_editor")
local CommitEditorBuffer = require("neogit.buffers.commit_editor")
local MergeEditorBuffer = require("neogit.buffers.merge_editor")
local TagEditorBuffer = require("neogit.buffers.tag_editor")
local DescriptionEditorBuffer = require("neogit.buffers.description_editor")

local M = {}

Expand All @@ -21,4 +22,8 @@ function M.tag_editor(target, on_unload)
TagEditorBuffer.new(target, on_unload):open()
end

function M.description_editor(target, on_unload)
DescriptionEditorBuffer.new(target, on_unload):open()
end

return M
2 changes: 2 additions & 0 deletions lua/neogit/lib/git/cli.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ local configurations = {
_get = "--get",
_add = "--add",
_unset = "--unset",
null = "--null",
},
aliases = {
set = function(tbl)
Expand Down Expand Up @@ -320,6 +321,7 @@ local configurations = {
remotes = "-r",
force = "--force",
current = "--show-current",
edit_description = "--edit-description",
very_verbose = "-vv",
move = "-m",
},
Expand Down
10 changes: 7 additions & 3 deletions lua/neogit/lib/git/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,13 @@ end
local function build_config()
local result = {}

for _, option in ipairs(cli.config.list._local.call_sync():trim().stdout) do
local key, value = option:match([[^(.-)=(.*)$]])
result[key] = ConfigEntry.new(key, value, "local")
local out = vim.split(table.concat(cli.config.list.null._local.call_sync():trim().stdout_raw, "\0"), "\n")
for _, option in ipairs(out) do
local key, value = unpack(vim.split(option, "\0"))

if key ~= "" then
result[key] = ConfigEntry.new(key, value, "local")
end
end

return result
Expand Down
4 changes: 3 additions & 1 deletion lua/neogit/popups/branch/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function M.create(env)
.builder()
:name("NeogitBranchPopup")
:switch("r", "recurse-submodules", "Recurse submodules when checking out an existing branch")
:config_if(show_config, "d", "branch." .. current_branch .. ".description")
:config_if(show_config, "d", "branch." .. current_branch .. ".description", {
fn = config_actions.description_config(current_branch),
})
:config_if(show_config, "u", "branch." .. current_branch .. ".merge", {
fn = config_actions.merge_config(current_branch),
})
Expand Down
15 changes: 15 additions & 0 deletions lua/neogit/popups/branch_config/actions.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local a = require("plenary.async")
local git = require("neogit.lib.git")
local util = require("neogit.lib.util")
local client = require("neogit.client")

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

Expand Down Expand Up @@ -68,4 +69,18 @@ function M.merge_config(branch)
end)
end

function M.description_config(branch)
return a.void(function(popup, c)
client.wrap(git.cli.branch.edit_description, {
autocmd = "NeogitDescriptionComplete",
msg = {
success = "Description Updated",
},
})

c.value = git.config.get("branch." .. branch .. ".description"):read()
popup:repaint_config()
end)
end

return M

0 comments on commit c28cd00

Please sign in to comment.