Skip to content

Skip pre-commit hooks for shadow repo (#13331)#13488

Merged
scidomino merged 1 commit intogoogle-gemini:mainfrom
vishvananda:no-verify
Nov 20, 2025
Merged

Skip pre-commit hooks for shadow repo (#13331)#13488
scidomino merged 1 commit intogoogle-gemini:mainfrom
vishvananda:no-verify

Conversation

@vishvananda
Copy link
Copy Markdown
Contributor

Summary

When there is a globally configured pre-commit hook installed in the system it can cause commits to the shadow repository to fail. The easiest way to work around this is to run the commit with --no-verify.

Details

It is possible that we want to note his issue with documentation instead of running with --no-verify, but I don't know that there is an easy way to fix this in corporate settings where the system administrator globally enforces pre-commit hooks.

Related Issues

Partial for #13331.

How to Validate

Turn on checkpointing and make changes. Note that failures happen silently unless you also include #13486. You can go into the shadow git directory in .gemini/history// and manually add a failing pre-commit hook:

printf "#!/bin/sh\nexit 1" > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

Pre-Merge Checklist

  • Updated relevant documentation and README (if needed)
  • Added/updated tests (if needed)
  • Noted breaking changes (if any)
  • Validated on required platforms/methods:
    • MacOS
      • npm run
      • npx
      • Docker
      • Podman
      • Seatbelt
    • Windows
      • npm run
      • npx
      • Docker
    • Linux
      • npm run
      • npx
      • Docker

@vishvananda vishvananda requested a review from a team as a code owner November 20, 2025 07:09
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @vishvananda, 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 resolves an issue where system-wide Git pre-commit hooks could disrupt the application's internal Git operations by adding the --no-verify flag to all git commit commands executed by the GitService. Concurrently, it significantly enhances the application's checkpointing mechanism by integrating file snapshotting directly into the useGeminiStream hook. This ensures that critical changes made by tools are reliably saved, providing a robust recovery point and clear error feedback if snapshot creation fails.

Highlights

  • Bypass Git Pre-commit Hooks: The git commit command executed by the application's GitService now includes the --no-verify flag. This change addresses issues where globally configured Git pre-commit hooks could cause internal Git operations, particularly commits to the shadow repository, to fail.
  • Enhanced File Snapshotting for Checkpointing: Introduced robust file snapshotting capabilities within the useGeminiStream hook. When checkpointing is enabled and specific tool calls (like 'replace') are received, the system now creates a Git snapshot of the current project state. This provides a recovery mechanism and better error handling for snapshot failures.
  • Improved Error Handling for Snapshot Failures: Added comprehensive error handling for scenarios where file snapshotting fails. If createFileSnapshot encounters an error, an error message is displayed to the user, and the tool call operation is aborted, preventing further issues.
  • Refactored Stream Processing and State Management: The useGeminiStream hook was refactored to use useRef for submitQuery, handleCompletedTools, and processGeminiStreamEvents callbacks. This ensures stable references for these functions, improving the reliability of stream processing and tool call handling. A new snapshottingMessage state was also added to provide UI feedback during snapshot creation.
  • Updated Test Coverage: Extensive updates to useGeminiStream.test.tsx include mocking node:fs/promises and GitService, adding vi.useFakeTimers() for time-sensitive tests, and introducing a new test suite specifically for snapshotting functionality, covering both successful snapshot creation and error scenarios.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

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

  1. 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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the --no-verify flag when creating git snapshots for checkpointing, which prevents failures caused by global pre-commit hooks. The implementation also includes a significant and beneficial refactoring of the snapshotting logic within the useGeminiStream hook, moving it from a useEffect to the processGeminiStreamEvents callback for more timely and robust execution.

My review focuses on the new error handling paths. I've identified one area for improvement in useGeminiStream.ts where the error handling for a falsy commit hash can be made more consistent with other failure cases to ensure the model is always informed of a failed operation, leading to a better conversational experience.

Comment on lines +902 to +913
if (!commitHash) {
addItem(
{
type: MessageType.ERROR,
text: 'Failed to get a commit hash for the file snapshot. Aborting operation.',
},
Date.now(),
);
setSnapshottingMessage(null);
cancelOngoingRequest();
return StreamProcessingStatus.Completed;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The error handling for a falsy commitHash is inconsistent with the error handling in the catch block. Currently, if createFileSnapshot returns a falsy hash without throwing, cancelOngoingRequest() is called. This aborts the operation but does not inform the model of the failure, which can lead to the conversation abruptly ending.

To improve robustness and conversational flow, this case should be handled similarly to a thrown error: by creating an explicit error response and sending it to the model. This allows the model to be aware of the failure and potentially recover or respond appropriately.

I suggest replacing the current implementation with logic that constructs and sends an error response for the failed tool calls.

            if (!commitHash) {
              const errorMessage =
                'Failed to get a commit hash for the file snapshot. Aborting operation.';
              addItem(
                {
                  type: MessageType.ERROR,
                  text: errorMessage,
                },
                Date.now(),
              );

              // Inform the model that the tool calls failed.
              const erroredToolCalls: TrackedToolCall[] = toolCallRequests.map(
                (request) => ({
                  request,
                  status: 'error',
                  response: {
                    callId: request.callId,
                    resultDisplay: '',
                    error: new Error(errorMessage),
                    errorType: ToolErrorType.UNKNOWN,
                    responseParts: [
                      {
                        functionResponse: {
                          name: request.name,
                          response: {
                            error: errorMessage,
                          },
                        },
                      },
                    ],
                  },
                  responseSubmittedToGemini: false,
                }),
              );

              void handleCompletedToolsRef.current!(erroredToolCalls);
              setSnapshottingMessage(null);
              return StreamProcessingStatus.Completed;
            }

@vishvananda vishvananda changed the title No verify Skip pre-commit hooks for shadow repo (#13331) Nov 20, 2025
@vishvananda
Copy link
Copy Markdown
Contributor Author

Note the first version of the pr accidentally included #13486 and the comment by the code assist tool was addressed in that PR.

@scidomino scidomino enabled auto-merge November 20, 2025 22:41
@scidomino scidomino added this pull request to the merge queue Nov 20, 2025
Merged via the queue into google-gemini:main with commit 78b10dc Nov 20, 2025
27 checks passed
werdnum pushed a commit to werdnum/gemini-cli that referenced this pull request Nov 24, 2025
mboshernitsan pushed a commit that referenced this pull request Nov 25, 2025
Co-authored-by: Vishvananda Abrams <vabrams@google.com>
danpalmer pushed a commit to danpalmer/gemini-cli that referenced this pull request Nov 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants