From f2a3c05ee74027d79b6465424d4c9ba79bd414bb Mon Sep 17 00:00:00 2001 From: Yoshiue <37270772+yoshi12u@users.noreply.github.com> Date: Sun, 27 Jul 2025 09:13:08 +0900 Subject: [PATCH] feat: suggest commit messages from diff --- README.md | 6 ++++++ doc/copilot.txt | 5 +++++ lua/copilot/util.lua | 7 +++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index 0f9ed9e4..2096509c 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,12 @@ require("copilot").setup { } ``` +### git commit messages + +When editing a commit message (`gitcommit` filetype), Copilot uses the staged +diff (`git diff --staged`) to generate commit message suggestions. Enable +`gitcommit` in the `filetypes` table to use this feature. + ### logger Logs will be written to the `file` for anything of `file_log_level` or higher. diff --git a/doc/copilot.txt b/doc/copilot.txt index 2d62d298..4a0d3979 100644 --- a/doc/copilot.txt +++ b/doc/copilot.txt @@ -299,6 +299,11 @@ won’t be used anymore. e.g. } < +GIT COMMIT MESSAGES~ + +When editing a commit message (`gitcommit` filetype), Copilot fetches the +staged diff (`git diff --staged`) to provide commit message suggestions. Enable +`gitcommit` in the |copilot-filetypes| table to use this feature. LOGGER ~ diff --git a/lua/copilot/util.lua b/lua/copilot/util.lua index 41b94e33..ab7b211c 100644 --- a/lua/copilot/util.lua +++ b/lua/copilot/util.lua @@ -74,6 +74,13 @@ function M.get_doc() position = params.position, } + if vim.bo.filetype == "gitcommit" then + local ok, diff = pcall(vim.fn.system, { "git", "diff", "--staged", "--no-color" }) + if ok and diff and diff ~= "" then + doc.gitDiff = diff + end + end + return doc end