diff --git a/lua/mini/diff/jj.lua b/lua/mini/diff/jj.lua index 006f5b3..f4de5a0 100644 --- a/lua/mini/diff/jj.lua +++ b/lua/mini/diff/jj.lua @@ -52,14 +52,20 @@ local function set_ref_text(buf_id, file_path, cwd) local stat = vim.uv.fs_stat(cwd) if not stat or stat.type ~= "directory" then return end - jj( - { "file", "show", "-r", "@-", file_path }, - cwd, - ---@param res vim.SystemCompleted - vim.schedule_wrap( - function(res) MiniDiff.set_ref_text(buf_id, res.code == 0 and res.stdout or {}) end - ) - ) + ---@param text string | string[] | nil + local function set_text(text) + vim.schedule(function() MiniDiff.set_ref_text(buf_id, text) end) + end + + jj({ "file", "show", "-r", "@-", file_path }, cwd, function(res) + if res.code == 0 then return set_text(res.stdout) end + + -- Ignore if file is untracked in `@`. + jj({ "file", "list", "-r", "@", file_path }, cwd, function(list) + local tracked = list.code == 0 and list.stdout ~= nil and vim.trim(list.stdout) ~= "" + set_text(tracked and "" or nil) + end) + end) end ---@param buf_id integer