From 61f123f51808bd3cb7d0aca14f9b7e465734832b Mon Sep 17 00:00:00 2001 From: Nicolas GB Date: Tue, 17 Mar 2026 12:11:14 +0100 Subject: [PATCH] fix(utils): Now getting the commit_id of a revset forces it being unique (#98) This will raise an error, as expected, when trying to diff with a revset that has multiple commits associated --- lua/jj/utils.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lua/jj/utils.lua b/lua/jj/utils.lua index 545b29d..7137a17 100644 --- a/lua/jj/utils.lua +++ b/lua/jj/utils.lua @@ -542,22 +542,34 @@ function M.get_describe_text(revset) return text end --- ---- Get the commit id from a given revision +--- Get the commit id from a given revision. Returns nil and notifies an error if multiple commit_ids are found for a single revset --- @param revset string The revset to extract the commit id from --- @return string|nil function M.get_commit_id(revset) local output, success = runner.execute_command( - string.format("jj log --no-graph -r '%s' -T 'commit_id' --quiet", revset), + string.format([[jj log --no-graph -r '%s' -T 'commit_id ++ "\n"' --quiet]], revset), "Error extracting commit id", nil, true ) - -- Test quie if not success or not output then return nil end + local id = vim.split(output, "\n", { trimempty = true }) + if #id > 1 then + M.notify( + string.format( + "A unique `commit_id` for revision `%s` was expected, but it has multiple ones.\nThis is not currently supported.", + revset + ), + vim.log.levels.ERROR, + 5000 + ) + return + end + return vim.trim(output) end