diff --git a/lua/jj_mini_diff/init.lua b/lua/jj_mini_diff/init.lua index cf5731b..dec0100 100644 --- a/lua/jj_mini_diff/init.lua +++ b/lua/jj_mini_diff/init.lua @@ -107,13 +107,36 @@ local function _place_signs_in_buffer() end end +-- Check if current buffer's file is in a jj repo +local function _is_jj_repo() + local file_path = vim.api.nvim_buf_get_name(0) + if file_path == "" then + return false + end + local dir = vim.fn.fnamemodify(file_path, ":h") + while dir ~= "" and dir ~= "/" do + if vim.fn.isdirectory(dir .. "/.jj") == 1 then + return true + end + dir = vim.fn.fnamemodify(dir, ":h") + end + return false +end + function M.setup(opts) opts = opts or {} _define_signs() -- Call to define signs - -- TODO: Implement configuration options + + -- Autocommands to update signs + vim.api.nvim_create_autocmd({ "BufReadPost", "BufWritePost", "CursorHold" }, { + group = vim.api.nvim_create_augroup("JjMiniDiff", { clear = true }), + callback = function() + if _is_jj_repo() then + _place_signs_in_buffer() + end + end, + }) end --- TODO: Implement core logic for Git signs - return M