-
Notifications
You must be signed in to change notification settings - Fork 1
feat(gitcommit): improve diff filtering and notification flow #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
- add tracking of all and excluded files in diff filtering - return original diff if all files are excluded - move commit message notification to after language selection - trim whitespace in contextual diff checks for accuracy - enable auto submit on git tool success in config - refactor generate_commit_message for clearer notification order
- 为 status、log、diff、branch、remotes、show、blame、stash_list、diff_commits、contributors、search_commits、tags 等函数增加 user_msg 和 llm_msg 字段 - 便于工具链和 LLM 处理更丰富的上下文信息 - 保持原有接口兼容
- 增强 .gitignore 相关函数的错误提示和返回结构 - git_read 工具输出增加 user_msg/llm_msg,提升交互体验 - 修复部分判断和消息提示逻辑
- wrap all git operations in pcall for safer execution - ensure consistent error messages and output formatting - enhance commit, stage, unstage, and read tool reliability - update user and LLM messages for clearer feedback - refactor contextual diff and commit logic for edge cases - add utility trim function and remove redundant code
- 增加参数校验辅助函数,提升健壮性 - 统一各工具响应格式,便于维护和扩展 - 修复部分注释与边界条件判断 - 优化错误处理,确保一致性
- restructure response processing for clarity - handle error status with specific error messages - ensure callback is called for all response cases - add missing handler comment for LLM response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @jinzhongjia, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly refines the gitcommit
extension by enhancing its core functionalities. It improves the accuracy and behavior of diff filtering, optimizes the user notification experience during commit message generation, and boosts the reliability of Git command execution through robust error handling. Additionally, it standardizes the output of Git tools for better integration with AI models and strengthens input validation for these tools.
Highlights
- Diff Filtering Enhancements: The diff filtering logic now tracks all files and excluded files, ensuring the original diff is returned if all changes are filtered out, preventing empty diffs.
- Improved Notification Flow: The 'Generating commit message...' notification is now displayed after language selection, providing a more logical user experience.
- Default Auto-Submission for Git Tools: The
git_tool_auto_submit_success
configuration option now defaults totrue
, streamlining the workflow for successful Git tool operations. - Robust Git Operation Handling: Critical Git functions (
is_amending
,get_staged_diff
,get_contextual_diff
,commit_changes
) are now wrapped inpcall
for safer execution and improved error handling, preventing crashes from unexpected Git command failures. - Standardized Git Tool Output for LLMs: All Git read tool functions (
get_gitignore
,is_ignored
,get_status
, etc.) now return structureduser_msg
andllm_msg
fields, providing clearer and more consistent output for AI models. - Enhanced Git Tool Input Validation: New helper functions and
pcall
wrappers are introduced in bothgit_edit.lua
andgit_read.lua
to validate required parameters and handle errors more gracefully for Git tool commands.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This PR introduces improvements to the gitcommit extension, focusing on robustness through pcall
error handling. I've identified a bug in how pcall
results are handled in Git.commit_changes
which could prevent proper error reporting, and some medium-severity issues related to code consistency. Addressing these points will enhance the reliability and maintainability of the extension.
@@ -210,101 +218,140 @@ Available write-access Git operations: | |||
) | |||
end | |||
|
|||
local success, output | |||
-- 通过 pcall 安全执行操作,确保始终有响应 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return { status = "error", data = "No file specified for .gitignore check" } | ||
local success, output, user_msg, llm_msg | ||
|
||
-- 通过 pcall 安全执行操作,确保始终有响应 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This pull request introduces several improvements and refactors across multiple files in the
codecompanion
extension for Git commit functionality. The changes focus on enhancing error handling, improving code readability, and adding new utility functions. Below is a categorized summary of the most important changes:Error Handling Improvements:
Git.get_contextual_diff()
andGit.commit_changes()
by usingpcall
to safely execute Git operations, preventing unexpected crashes and providing fallback error messages. [1] [2] [3]Code Refactoring:
Generator._handle_response()
and related methods to replace_adapter
withadapter
for improved clarity and consistency. [1] [2]Utility Enhancements:
trim()
utility function to clean up whitespace in strings, used in several Git-related methods such asGit.get_contextual_diff()
andGit.get_staged_diff()
. [1] [2] [3]Configuration Updates:
gitcommit/config.lua
to enable automatic submission of successful Git operations (git_tool_auto_submit_success = true
).Enhanced GitIgnore Tool:
GitTool.get_gitignore()
to return additional structured messages for user and LLM tools, improving the feedback mechanism for.gitignore
operations.