From a4e10ee0d485b2035826168178e34328cf43f9cf Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Sat, 2 Aug 2025 23:05:08 +0800 Subject: [PATCH 1/2] refactor(gitcommit): Replace chat:add_reference with chat:add_context - Optimize context processing related to Slash commands - Fix context references during error handling --- lua/codecompanion/_extensions/gitcommit/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lua/codecompanion/_extensions/gitcommit/init.lua b/lua/codecompanion/_extensions/gitcommit/init.lua index 51d5ed0..9f379aa 100644 --- a/lua/codecompanion/_extensions/gitcommit/init.lua +++ b/lua/codecompanion/_extensions/gitcommit/init.lua @@ -161,12 +161,12 @@ local function setup_slash_commands(opts) stdout:close() stderr:close() if code == 0 then - chat:add_reference({ + chat:add_context({ role = "user", content = string.format("Selected commit (%s) full content:\n```\n%s\n```", choice.hash, output), }, "git", "") else - chat:add_reference( + chat:add_context( { role = "user", content = "Error: Failed to get commit content.\n" .. error_output }, "git", "" @@ -230,11 +230,11 @@ local function setup_slash_commands(opts) end end if #items == 0 then - return chat:add_reference({ role = "user", content = "No commits found." }, "git", "") + return chat:add_context({ role = "user", content = "No commits found." }, "git", "") end select_commit(chat, items) else - chat:add_reference( + chat:add_context( { role = "user", content = "Error: Failed to get git log\n" .. error_output }, "git", "" @@ -266,7 +266,7 @@ local function setup_slash_commands(opts) description = "Select a commit and insert its full content (message + diff)", callback = function(chat) if not Git.is_repository() then - return chat:add_reference({ role = "user", content = "Error: Not in a git repository" }, "git", "") + return chat:add_context({ role = "user", content = "Error: Not in a git repository" }, "git", "") end get_commit_list(chat, opts) end, From e0845e45ce555ff9a5a7c93c36cfbdf09a7f7112 Mon Sep 17 00:00:00 2001 From: jinzhongjia Date: Sat, 2 Aug 2025 23:16:01 +0800 Subject: [PATCH 2/2] fix(gitcommit): improve error message clarity for no commits found --- lua/codecompanion/_extensions/gitcommit/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/codecompanion/_extensions/gitcommit/init.lua b/lua/codecompanion/_extensions/gitcommit/init.lua index 9f379aa..01c0503 100644 --- a/lua/codecompanion/_extensions/gitcommit/init.lua +++ b/lua/codecompanion/_extensions/gitcommit/init.lua @@ -230,7 +230,7 @@ local function setup_slash_commands(opts) end end if #items == 0 then - return chat:add_context({ role = "user", content = "No commits found." }, "git", "") + return chat:add_context({ role = "user", content = "Error: No commits found." }, "git", "") end select_commit(chat, items) else