diff --git a/lua/gitblame/git.lua b/lua/gitblame/git.lua index f6a53d2..fca3fba 100644 --- a/lua/gitblame/git.lua +++ b/lua/gitblame/git.lua @@ -8,11 +8,13 @@ function M.check_is_ignored(callback) return true end - utils.start_job("git check-ignore " .. vim.fn.shellescape(filepath), { - on_exit = function(code) - callback(code ~= 1) - end, - }) + return true + + -- utils.start_job("git check-ignore " .. vim.fn.shellescape(filepath), { + -- on_exit = function(code) + -- callback(code ~= 1) + -- end, + -- }) end ---@param sha string @@ -139,7 +141,7 @@ local function get_current_branch(callback) if not utils.get_filepath() then return end - local command = utils.make_local_command("git branch --show-current") + local command = utils.make_local_command([[jj --config ui.color=never log -r 'latest(ancestors(@) & bookmarks())' --no-graph -T 'self.local_bookmarks().join("\n")']]) utils.start_job(command, { on_stdout = function(url) @@ -217,15 +219,18 @@ function M.get_remote_url(callback) if not utils.get_filepath() then return end - local remote_url_command = utils.make_local_command("git config --get remote.origin.url") + local remote_url_command = utils.make_local_command("jj git remote list") utils.start_job(remote_url_command, { - on_stdout = function(url) - if url and url[1] then - callback(url[1]) - else - callback("") + on_stdout = function(lines) + for _, line in ipairs(lines) do + if line:match("^origin ") then + local url = line:gsub("^origin ", "") + callback(url) + return + end end + callback("") end, }) end @@ -235,7 +240,7 @@ function M.get_repo_root(callback) if not utils.get_filepath() then return end - local command = utils.make_local_command("git rev-parse --show-toplevel") + local command = utils.make_local_command("jj root") utils.start_job(command, { on_stdout = function(data) diff --git a/lua/gitblame/init.lua b/lua/gitblame/init.lua index c93d495..89a5561 100644 --- a/lua/gitblame/init.lua +++ b/lua/gitblame/init.lua @@ -172,25 +172,19 @@ local function load_blames(callback) files_data_loading[filepath] = true - git.get_repo_root(function(git_root) - local command = "git --no-pager -C " - .. vim.fn.shellescape(git_root) - .. " blame -b -p -w --date relative --contents - " - .. vim.fn.shellescape(filepath) - - start_job(command, { - input = table.concat(lines, "\n") .. "\n", - on_stdout = function(data) - process_blame_output(blames, filepath, data) - if callback then - callback() - end - end, - on_exit = function() - files_data_loading[filepath] = nil - end, - }) - end) + local command = [[jj --config ui.color=never file annotate --config templates.file_annotate='"separate(\"\n\", separate(\" \", commit.commit_id(), 99999, line_number, 1), \"author \" ++ commit.author().name(), \"author-time \" ++ commit.author().timestamp().format(\"%s\"), \"committer \" ++ commit.committer().name(), \"committer-time \" ++ commit.committer().timestamp().format(\"%s\"), \"summary \" ++ commit.description().first_line(), \"\t\" ++ content)++ \"\n\""' ]] .. vim.fn.shellescape(filepath) + + start_job(command, { + on_stdout = function(data) + process_blame_output(blames, filepath, data) + if callback then + callback() + end + end, + on_exit = function() + files_data_loading[filepath] = nil + end, + }) end ---Checks if the date format contains a relative time placeholder. @@ -289,6 +283,9 @@ local function format_blame_text(info, template) text = text:gsub("", format_date(info.date)) local summary_escaped = info.summary and info.summary:gsub("%%", "%%%%") or "" + if info.summary == "" then + summary_escaped = "(empty)" + end text = text:gsub("", utils.truncate_description(summary_escaped, vim.g.gitblame_max_commit_summary_length)) text = text:gsub("", info.sha and string.sub(info.sha, 1, 7) or "") @@ -462,7 +459,7 @@ end ---@param callback fun(current_author: string) local function find_current_author(callback) - start_job("git config --get user.name", { + start_job("jj config get user.name", { ---@param data string[] on_stdout = function(data) current_author = data[1] @@ -517,7 +514,7 @@ end ---Returns SHA for the latest commit to the current branch. ---@param callback fun(sha: string) local function get_latest_sha(callback) - start_job("git rev-parse HEAD", { + start_job("jj log -T 'commit_id' --no-graph -r @-", { on_stdout = function(data) callback(data[1]) end,