Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 1d288b6

Browse files
committed
docs(gitcommit): document commit history context and API
- add commit history context feature to README and configuration docs - introduce programmatic API section with usage examples in README and help file - update documentation structure and configuration options for clarity
1 parent 40af794 commit 1d288b6

2 files changed

Lines changed: 104 additions & 2 deletions

File tree

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ A Neovim plugin extension for CodeCompanion that generates AI-powered Git commit
1010
- 🌍 **Multi-language Support** - Generate commit messages in multiple languages
1111
- 📝 **Smart Buffer Integration** - Auto-generate commit messages in gitcommit buffers with configurable keymaps
1212
- 📋 **File Filtering** - Support glob patterns to exclude files from diff analysis
13+
- 📚 **Commit History Context** - Use recent commit history to maintain consistent styling and patterns
14+
- 🔌 **Programmatic API** - Full API for external integrations and custom workflows
1315
-**Async Operations** - Non-blocking Git operations with proper error handling
1416

1517
## 📦 Installation
@@ -53,6 +55,10 @@ require("codecompanion").setup({
5355
git_tool_auto_submit_errors = false, -- Auto-submit errors to LLM
5456
git_tool_auto_submit_success = true, -- Auto-submit success to LLM
5557
gitcommit_select_count = 100, -- Number of commits shown in /gitcommit
58+
59+
-- Commit history context (optional)
60+
use_commit_history = true, -- Enable commit history context
61+
commit_history_count = 10, -- Number of recent commits for context
5662
}
5763
}
5864
}
@@ -170,6 +176,8 @@ opts = {
170176
gitcommit_select_count = 100, -- Commits shown in /gitcommit
171177
git_tool_auto_submit_errors = false, -- Auto-submit errors to LLM
172178
git_tool_auto_submit_success = true, -- Auto-submit success to LLM
179+
use_commit_history = true, -- Enable commit history context
180+
commit_history_count = 10, -- Number of recent commits for context
173181
buffer = {
174182
enabled = true, -- Enable buffer integration
175183
keymap = "<leader>gc", -- Keymap
@@ -182,6 +190,38 @@ opts = {
182190

183191
</details>
184192

193+
## 🔌 Programmatic API
194+
195+
The extension provides a comprehensive API for external integrations:
196+
197+
```lua
198+
local gitcommit = require("codecompanion._extensions.gitcommit")
199+
200+
-- Generate commit message programmatically
201+
gitcommit.exports.generate("English", function(result, error)
202+
if result then
203+
print("Generated:", result)
204+
else
205+
print("Error:", error)
206+
end
207+
end)
208+
209+
-- Check if in git repository
210+
if gitcommit.exports.is_git_repo() then
211+
print("In git repository")
212+
end
213+
214+
-- Get git status
215+
local status = gitcommit.exports.git_tool.status()
216+
print("Git status:", status)
217+
218+
-- Stage files
219+
gitcommit.exports.git_tool.stage({"file1.txt", "file2.txt"})
220+
221+
-- Create and checkout branch
222+
gitcommit.exports.git_tool.create_branch("feature/new-feature", true)
223+
```
224+
185225
## 📚 Documentation
186226

187227
For detailed documentation, see: `:help codecompanion-gitcommit`

doc/codecompanion-gitcommit.txt

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ CONTENTS *codecompanion-gitcommit-contents*
1616
5. Commands |codecompanion-gitcommit-commands|
1717
6. Git Tools |codecompanion-gitcommit-git-tools|
1818
7. Configuration |codecompanion-gitcommit-config|
19-
8. License |codecompanion-gitcommit-license|
19+
8. Programmatic API |codecompanion-gitcommit-api|
20+
9. License |codecompanion-gitcommit-license|
2021

2122
==============================================================================
2223
1. INTRODUCTION *codecompanion-gitcommit-intro*
@@ -41,6 +42,7 @@ chat buffers.
4142
• Multi-language support for commit messages
4243
• Support for regular commits and amend commits
4344
• Smart diff analysis with file filtering capabilities
45+
• Commit history context for consistent styling and patterns
4446

4547
🛠️ Git Tool Integration
4648
• @git_read tool - 15 read-only Git operations (status, log, diff, etc.)
@@ -271,8 +273,68 @@ Buffer configuration:
271273
*buffer.skip_auto_generate_on_amend* Type: boolean, Default: true
272274
Skip auto-generation during git commit --amend operations.
273275

276+
*use_commit_history* Type: boolean, Default: true
277+
When enabled, includes recent commit messages as context for the AI
278+
to maintain consistency in commit style and patterns.
279+
280+
*commit_history_count* Type: number, Default: 10
281+
Number of recent commits to include as context when use_commit_history
282+
is enabled.
283+
284+
==============================================================================
285+
8. PROGRAMMATIC API *codecompanion-gitcommit-api*
286+
287+
The extension provides a programmatic API for external integrations:
288+
289+
*gitcommit.exports.generate(lang, callback)*
290+
Generate commit message programmatically
291+
Parameters:
292+
• lang (string|nil): Language to generate commit message in (optional)
293+
• callback (function): Callback function with signature (result, error)
294+
295+
*gitcommit.exports.is_git_repo()*
296+
Check if current directory is in a git repository
297+
Returns: boolean
298+
299+
*gitcommit.exports.get_staged_diff()*
300+
Get staged changes diff
301+
Returns: string|nil
302+
303+
*gitcommit.exports.commit_changes(message)*
304+
Commit changes with provided message
305+
Parameters:
306+
• message (string): Commit message
307+
Returns: boolean
308+
309+
*gitcommit.exports.git_tool*
310+
Access to git tool functions including status, log, diff, branches,
311+
stage, unstage, create_branch, checkout, stash operations, reset,
312+
contributors, search_commits, merge, and more.
313+
314+
Example usage: >
315+
local gitcommit = require("codecompanion._extensions.gitcommit")
316+
317+
-- Generate commit message
318+
gitcommit.exports.generate("English", function(result, error)
319+
if result then
320+
print("Generated:", result)
321+
else
322+
print("Error:", error)
323+
end
324+
end)
325+
326+
-- Check if in git repo
327+
if gitcommit.exports.is_git_repo() then
328+
print("In git repository")
329+
end
330+
331+
-- Get git status
332+
local status = gitcommit.exports.git_tool.status()
333+
print("Git status:", status)
334+
<
335+
274336
==============================================================================
275-
8. LICENSE *codecompanion-gitcommit-license*
337+
9. LICENSE *codecompanion-gitcommit-license*
276338

277339
MIT License
278340

0 commit comments

Comments
 (0)