mirror of
https://github.com/zoriya/jj.nvim.git
synced 2026-08-15 23:53:18 +00:00
feat(diff): Add options to diff command to allow diffing only current buffer
This commit is contained in:
+18
-3
@@ -37,7 +37,6 @@ local function handle_status_enter()
|
||||
|
||||
if renamed_file then
|
||||
-- For renamed files, we need to construct the full path
|
||||
-- Extract the directory part before the "{"
|
||||
local dir_pattern = "^R (.*)/{.*}$"
|
||||
local dir_path = line:match(dir_pattern)
|
||||
if dir_path then
|
||||
@@ -46,7 +45,7 @@ local function handle_status_enter()
|
||||
filepath = renamed_file
|
||||
end
|
||||
else
|
||||
-- jj status format: "M filename" or "A filename" or "D filename" etc.
|
||||
-- jj status format: "M filename" or "A filename"
|
||||
-- Match lines that start with status letter followed by space and filename
|
||||
local pattern = "^[MA?!] (.+)$"
|
||||
filepath = line:match(pattern)
|
||||
@@ -403,13 +402,29 @@ function M.log(opts)
|
||||
run(cmd)
|
||||
end
|
||||
|
||||
---@class jj.cmd.diff_opts
|
||||
---@field current boolean Wether or not to only diff the current buffer
|
||||
|
||||
--- Jujutsu diff
|
||||
function M.diff()
|
||||
--- @param opts? jj.cmd.diff_opts The options for the diff command
|
||||
function M.diff(opts)
|
||||
if not utils.ensure_jj() then
|
||||
return
|
||||
end
|
||||
|
||||
local cmd = "jj diff"
|
||||
|
||||
if opts and opts.current then
|
||||
local file = vim.fn.expand("%:p")
|
||||
utils.notify(file)
|
||||
if file and file ~= "" then
|
||||
cmd = string.format("%s %s", cmd, vim.fn.fnameescape(file))
|
||||
else
|
||||
utils.notify("Current buffer is not a file", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
run(cmd)
|
||||
end
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ local function get_files()
|
||||
local change, file_path = line:match("^(%a)%s(.+)$")
|
||||
|
||||
table.insert(files, {
|
||||
text = file_path,
|
||||
file = file_path,
|
||||
change = change,
|
||||
diff_cmd = string.format("jj diff %s", file_path),
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ end
|
||||
|
||||
---- Notify function to display messages with a title
|
||||
--- @param message string The message to display
|
||||
--- @param level number The log level (default: INFO)
|
||||
--- @param level? number The log level (default: INFO)
|
||||
function M.notify(message, level)
|
||||
level = level or vim.log.levels.INFO
|
||||
vim.notify(message, level, { title = "JJ", timeout = 3000 })
|
||||
|
||||
Reference in New Issue
Block a user