feat(neojj): add neojj (jujutsu) integration (#187)

This commit is contained in:
Barrett Ruth 2026-03-11 14:02:52 -04:00 committed by GitHub
parent de04381298
commit 0451445966
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 265 additions and 6 deletions

View file

@ -39,6 +39,8 @@
---@class diffs.NeogitConfig
---@class diffs.NeojjConfig
---@class diffs.GitsignsConfig
---@class diffs.CommittiaConfig
@ -65,6 +67,7 @@
---@class diffs.IntegrationsConfig
---@field fugitive diffs.FugitiveConfig|false
---@field neogit diffs.NeogitConfig|false
---@field neojj diffs.NeojjConfig|false
---@field gitsigns diffs.GitsignsConfig|false
---@field committia diffs.CommittiaConfig|false
---@field telescope diffs.TelescopeConfig|false
@ -77,6 +80,7 @@
---@field integrations diffs.IntegrationsConfig
---@field fugitive? diffs.FugitiveConfig|false deprecated: use integrations.fugitive
---@field neogit? diffs.NeogitConfig|false deprecated: use integrations.neogit
---@field neojj? diffs.NeojjConfig|false deprecated: use integrations.neojj
---@field gitsigns? diffs.GitsignsConfig|false deprecated: use integrations.gitsigns
---@field committia? diffs.CommittiaConfig|false deprecated: use integrations.committia
---@field telescope? diffs.TelescopeConfig|false deprecated: use integrations.telescope
@ -161,6 +165,7 @@ local default_config = {
integrations = {
fugitive = false,
neogit = false,
neojj = false,
gitsigns = false,
committia = false,
telescope = false,
@ -239,6 +244,15 @@ function M.compute_filetypes(opts)
table.insert(fts, 'NeogitCommitView')
table.insert(fts, 'NeogitDiffView')
end
local njj = intg.neojj
if njj == nil then
njj = opts.neojj
end
if njj == true or type(njj) == 'table' then
table.insert(fts, 'NeojjStatus')
table.insert(fts, 'NeojjCommitView')
table.insert(fts, 'NeojjDiffView')
end
if type(opts.extra_filetypes) == 'table' then
for _, ft in ipairs(opts.extra_filetypes) do
table.insert(fts, ft)
@ -610,7 +624,7 @@ local function compute_highlight_groups(is_default)
end
end
local integration_keys = { 'fugitive', 'neogit', 'gitsigns', 'committia', 'telescope' }
local integration_keys = { 'fugitive', 'neogit', 'neojj', 'gitsigns', 'committia', 'telescope' }
local function migrate_integrations(opts)
if opts.integrations then
@ -674,6 +688,10 @@ local function init()
intg.neogit = {}
end
if intg.neojj == true then
intg.neojj = {}
end
if intg.gitsigns == true then
intg.gitsigns = {}
end
@ -1032,6 +1050,21 @@ function M.attach(bufnr)
})
end
local neojj_augroup = nil
if config.integrations.neojj and vim.bo[bufnr].filetype:match('^Neojj') then
vim.b[bufnr].neojj_disable_hunk_highlight = true
neojj_augroup = vim.api.nvim_create_augroup('diffs_neojj_' .. bufnr, { clear = true })
vim.api.nvim_create_autocmd('User', {
pattern = 'NeojjDiffLoaded',
group = neojj_augroup,
callback = function()
if vim.api.nvim_buf_is_valid(bufnr) and attached_buffers[bufnr] then
M.refresh(bufnr)
end
end,
})
end
dbg('attaching to buffer %d', bufnr)
ensure_cache(bufnr)
@ -1045,6 +1078,9 @@ function M.attach(bufnr)
if neogit_augroup then
pcall(vim.api.nvim_del_augroup_by_id, neogit_augroup)
end
if neojj_augroup then
pcall(vim.api.nvim_del_augroup_by_id, neojj_augroup)
end
end,
})
end
@ -1101,6 +1137,12 @@ function M.get_fugitive_config()
return config.integrations.fugitive
end
---@return diffs.NeojjConfig|false
function M.get_neojj_config()
init()
return config.integrations.neojj
end
---@return diffs.CommittiaConfig|false
function M.get_committia_config()
init()

View file

@ -129,6 +129,18 @@ local function get_repo_root(bufnr)
return vim.fn.fnamemodify(neogit_git_dir, ':h')
end
if vim.bo[bufnr].filetype:match('^Neojj') then
local jj_ok, jj_mod = pcall(require, 'neojj.lib.jj')
if jj_ok then
local rok, repo = pcall(function()
return jj_mod.repo
end)
if rok and repo and repo.worktree_root then
return repo.worktree_root
end
end
end
local cwd = vim.fn.getcwd()
local git = require('diffs.git')
return git.get_repo_root(cwd .. '/.')
@ -244,6 +256,10 @@ function M.parse_buffer(bufnr)
or (not logical:match('^deleted file mode') and logical:match('^deleted%s+(.+)$'))
or logical:match('^renamed%s+(.+)$')
or logical:match('^copied%s+(.+)$')
or logical:match('^added%s+(.+)$')
or logical:match('^updated%s+(.+)$')
or logical:match('^changed%s+(.+)$')
or logical:match('^unmerged%s+(.+)$')
local bare_file = not hunk_start and logical:match('^([^%s]+%.[^%s]+)$')
local filename = logical:match('^[MADRCU%?!]%s+(.+)$')
or diff_git_file