Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ Here's an example spec for [Lazy](https://github.com/folke/lazy.nvim), but you'r
lazy = true,
dependencies = {
"nvim-lua/plenary.nvim", -- required
"sindrets/diffview.nvim", -- optional - Diff integration

-- Only one of these is needed.
"sindrets/diffview.nvim", -- optional
"esmuellert/codediff.nvim", -- optional

-- Only one of these is needed.
"nvim-telescope/telescope.nvim", -- optional
Expand Down Expand Up @@ -321,6 +324,10 @@ neogit.setup {
-- Requires you to have `sindrets/diffview.nvim` installed.
diffview = nil,

-- Alternative diff viewer integration.
-- Requires you to have `esmuellert/codediff.nvim` installed.
codediff = nil,

-- If enabled, uses fzf-lua for menu selection. If the telescope integration
-- is also selected then telescope is used instead
-- Requires you to have `ibhagwan/fzf-lua` installed.
Expand All @@ -336,6 +343,9 @@ neogit.setup {
-- Requires you to have `folke/snacks.nvim` installed.
snacks = nil,
},
-- Which diff viewer to use. nil = auto-detect (tries diffview first, then codediff).
-- Can be "diffview" or "codediff".
diff_viewer = nil,
sections = {
-- Reverting/Cherry Picking
sequencer = {
Expand Down
17 changes: 14 additions & 3 deletions doc/neogit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,10 @@ to Neovim users.
-- Requires you to have `sindrets/diffview.nvim` installed.
diffview = nil,

-- Alternative diff viewer integration.
-- Requires you to have `esmuellert/codediff.nvim` installed.
codediff = nil,

-- If enabled, uses fzf-lua for menu selection. If the telescope integration
-- is also selected then telescope is used instead
-- Requires you to have `ibhagwan/fzf-lua` installed.
Expand All @@ -302,6 +306,9 @@ to Neovim users.
-- Requires you to have `folke/snacks.nvim` installed.
snacks = nil,
},
-- Which diff viewer to use. nil = auto-detect (tries diffview first, then codediff).
-- Can be "diffview" or "codediff".
diff_viewer = nil,
sections = {
-- Reverting/Cherry Picking
sequencer = {
Expand Down Expand Up @@ -1403,9 +1410,13 @@ The diff popup actions allow inspection of changes in the index (staged
changes), the working tree (unstaged changes and untracked files), any
ref range.

For these actions to become available, Neogit needs to be configured to enable
`diffview.nvim` integration. See |neogit_setup_plugin| and
https://github.com/sindrets/diffview.nvim.
For these actions to become available, Neogit needs to have a diff viewer
integration enabled. Supported viewers are:
- `diffview.nvim`: https://github.com/sindrets/diffview.nvim
- `codediff.nvim`: https://github.com/esmuellert/codediff.nvim

By default, Neogit will auto-detect which viewer is available. You can
explicitly set the viewer with the `diff_viewer` option. See |neogit_setup_plugin|.

• Diff this *neogit_diff_this*
Show the diff for the file referred to by a hunk under the cursor.
Expand Down
14 changes: 10 additions & 4 deletions lua/neogit/buffers/status/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,11 @@ M.n_stage = function(self)
end

if selection.item and selection.item.mode == "UU" then
if config.check_integration("diffview") and git.merge.is_conflicted(selection.item.escaped_path) then
require("neogit.integrations.diffview").open("conflict", selection.item.name, {
local diff_viewer = config.get_diff_viewer()
if diff_viewer and git.merge.is_conflicted(selection.item.escaped_path) then
local integration = diff_viewer == "codediff" and require("neogit.integrations.codediff")
or require("neogit.integrations.diffview")
integration.open("conflict", selection.item.name, {
on_close = {
handle = self.buffer.handle,
fn = function()
Expand Down Expand Up @@ -1186,8 +1189,11 @@ M.n_stage = function(self)
self:dispatch_refresh({ update_diffs = { "untracked:*" } }, "n_stage")
elseif section.options.section == "unstaged" then
if git.status.any_unmerged() then
if config.check_integration("diffview") then
require("neogit.integrations.diffview").open("conflict", nil, {
local diff_viewer = config.get_diff_viewer()
if diff_viewer then
local integration = diff_viewer == "codediff" and require("neogit.integrations.codediff")
or require("neogit.integrations.diffview")
integration.open("conflict", nil, {
on_close = {
handle = self.buffer.handle,
fn = function()
Expand Down
52 changes: 50 additions & 2 deletions lua/neogit/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,8 @@ end
---@field preview_buffer? NeogitConfigPopup Preview options
---@field popup? NeogitConfigPopup Set the default way of opening popups
---@field signs? NeogitConfigSigns Signs used for toggled regions
---@field integrations? { diffview: boolean, telescope: boolean, fzf_lua: boolean, mini_pick: boolean, snacks: boolean } Which integrations to enable
---@field integrations? { diffview: boolean, codediff: boolean, telescope: boolean, fzf_lua: boolean, mini_pick: boolean, snacks: boolean } Which integrations to enable
---@field diff_viewer? "diffview"|"codediff"|nil Which diff viewer to use (nil = auto-detect)
---@field sections? NeogitConfigSections
---@field ignored_settings? string[] Settings to never persist, format: "Filetype--cli-value", i.e. "NeogitCommitPopup--author"
---@field mappings? NeogitConfigMappings
Expand Down Expand Up @@ -541,10 +542,12 @@ function M.get_default_values()
integrations = {
telescope = nil,
diffview = nil,
codediff = nil,
fzf_lua = nil,
mini_pick = nil,
snacks = nil,
},
diff_viewer = nil,
sections = {
sequencer = {
folded = false,
Expand Down Expand Up @@ -857,8 +860,26 @@ function M.validate_config()
end
end

local function validate_diff_viewer()
if config.diff_viewer == nil then
return
end

local valid_viewers = { "diffview", "codediff" }
if not vim.tbl_contains(valid_viewers, config.diff_viewer) then
err(
"diff_viewer",
string.format(
"Expected diff_viewer to be one of %s or nil, got '%s'",
table.concat(valid_viewers, ", "),
tostring(config.diff_viewer)
)
)
end
end

local function validate_integrations()
local valid_integrations = { "diffview", "telescope", "fzf_lua", "mini_pick", "snacks" }
local valid_integrations = { "diffview", "codediff", "telescope", "fzf_lua", "mini_pick", "snacks" }
if not validate_type(config.integrations, "integrations", "table") or #config.integrations == 0 then
return
end
Expand Down Expand Up @@ -1279,6 +1300,7 @@ function M.validate_config()
end

validate_integrations()
validate_diff_viewer()
validate_sections()
validate_ignored_settings()
validate_mappings()
Expand Down Expand Up @@ -1310,6 +1332,32 @@ function M.check_integration(name)
return enabled
end

---Returns the configured diff viewer, or auto-detects if not set
---@return string|nil The diff viewer to use ("diffview", "codediff"), or nil if none available
function M.get_diff_viewer()
local logger = require("neogit.logger")
local viewer = M.values.diff_viewer

if viewer then
-- Explicit choice - verify it's available
if M.check_integration(viewer) then
return viewer
else
logger.warn(("[CONFIG] Configured diff_viewer '%s' is not available"):format(viewer))
return nil
end
end

-- Auto-detect: try diffview first (backwards compatible), then codediff
if M.check_integration("diffview") then
return "diffview"
elseif M.check_integration("codediff") then
return "codediff"
end

return nil
end

function M.setup(opts)
if opts == nil then
return
Expand Down
Loading
Loading