Skip to content

Commit 22eaa72

Browse files
committed
fix(git): handle shell escaping failure in release notes
- check for empty or failed shell escaping of tag range - return error messages if escaping fails before running git log - improve robustness of release notes generation with invalid tags
1 parent ee6fee1 commit 22eaa72

File tree

1 file changed

+9
-2
lines changed
  • lua/codecompanion/_extensions/gitcommit/tools

1 file changed

+9
-2
lines changed

lua/codecompanion/_extensions/gitcommit/tools/git.lua

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ end
692692
--- Generate release notes between two tags
693693
---@param from_tag string|nil Starting tag (if not provided, uses second latest tag)
694694
---@param to_tag string|nil Ending tag (if not provided, uses latest tag)
695-
---@param format string|nil Format for release notes (markdown, plain, json)
695+
---@param format string|nil Format (markdown, plain, json)
696696
---@return boolean success
697697
---@return string output
698698
---@return string user_msg
@@ -740,7 +740,14 @@ function GitTool.generate_release_notes(from_tag, to_tag, format)
740740

741741
-- Get commit range between tags
742742
local range = from_tag .. ".." .. to_tag
743-
local commit_cmd = "git log --pretty=format:'%h\x01%s\x01%an\x01%ad' --date=short " .. vim.fn.shellescape(range)
743+
local escaped_range = vim.fn.shellescape(range)
744+
if not escaped_range or escaped_range == "" then
745+
local msg = "Failed to escape tag range: " .. range
746+
local user_msg = msg
747+
local llm_msg = "<gitReleaseNotes>fail: " .. msg .. "</gitReleaseNotes>"
748+
return false, msg, user_msg, llm_msg
749+
end
750+
local commit_cmd = "git log --pretty=format:'%h\x01%s\x01%an\x01%ad' --date=short " .. escaped_range
744751
local success_commits, commits_output = pcall(vim.fn.system, commit_cmd)
745752

746753
if not success_commits or vim.v.shell_error ~= 0 then

0 commit comments

Comments
 (0)