Skip to content

fix(commands): ignore empty GEMINI.md to allow re-initialization#25010

Open
student-ankitpandit wants to merge 2 commits intogoogle-gemini:mainfrom
student-ankitpandit:fix/init-ignore-empty-gemini-md-v2
Open

fix(commands): ignore empty GEMINI.md to allow re-initialization#25010
student-ankitpandit wants to merge 2 commits intogoogle-gemini:mainfrom
student-ankitpandit:fix/init-ignore-empty-gemini-md-v2

Conversation

@student-ankitpandit
Copy link
Copy Markdown
Contributor

Summary

The /init command was blocked from re-running if a GEMINI.md file existed but was empty — a common state left behind when a previous /init was cancelled mid-way. This fix changes the check from file existence to file content, so an empty GEMINI.md is treated the same as no file at all.

Details

Previously, /init created an empty GEMINI.md before starting the LLM analysis. If the process was cancelled or failed mid-way, this empty file was left behind — permanently blocking re-initialization since the check only tested for file existence, not content.

The fix changes the check from fs.existsSync() to also read the file content, so /init only blocks if GEMINI.md exists AND has non-whitespace content. An empty file is now treated the same as no file.

A new test case was added to cover the empty file scenario.

Related Issues

Fixes #22757

How to Validate

  1. Create a dummy project directory: mkdir /tmp/g-cli-test && cd /tmp/g-cli-test
  2. Simulate a failed /init: touch GEMINI.md
  3. Run gemini and type /init
  4. Expected: init proceeds with analysis (not blocked)
  5. Also verify: a non-empty GEMINI.md still blocks re-initialization

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

@student-ankitpandit student-ankitpandit requested a review from a team as a code owner April 9, 2026 08:15
@student-ankitpandit
Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 improves the robustness of the /init command by refining how it detects existing configuration files. By shifting from a simple existence check to a content-based validation, the system now correctly handles scenarios where a previous initialization attempt left behind an empty file, preventing users from being permanently blocked from re-running the command.

Highlights

  • Re-initialization Logic: Updated the /init command to check for non-whitespace content in GEMINI.md instead of relying solely on file existence, allowing re-initialization if the file is empty.
  • Error Handling: Added robust error handling for file reading operations, ensuring that unexpected file system errors are reported correctly while treating missing files as a valid state for initialization.
  • Test Coverage: Included new test cases to verify behavior for existing content, empty files, and potential file system access errors.
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.

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 updates the initCommand to check for existing content in GEMINI.md using fs.promises.readFile instead of just checking for file existence. It also adds robust error handling for file reading and includes comprehensive unit tests to cover various scenarios, such as existing content, empty files, and read errors. I have identified an improvement opportunity regarding the error handling implementation to ensure better type safety and avoid unnecessary lint suppression.

Comment on lines +41 to +49
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const error = e as NodeJS.ErrnoException;
if (error.code !== 'ENOENT') {
return {
type: 'message',
messageType: 'error',
content: `Failed to read GEMINI.md: ${error.message}`,
};
}
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 readFile uses an unsafe type assertion and suppresses a lint warning. This approach is fragile as it assumes e will always be an object with a code property. If e is not an object (which can happen in JavaScript), accessing error.code will throw, causing the command to crash. A more robust approach using an instanceof Error check is preferred to ensure safety and remove the need for lint suppression.

      if (e instanceof Error && (e as NodeJS.ErrnoException).code !== 'ENOENT') {
        return {
          type: 'message',
          messageType: 'error',
          content: `Failed to read GEMINI.md: ${e.message}`,
        };
      }

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 refactors the initCommand to use fs.promises.readFile instead of fs.existsSync for checking the presence and content of GEMINI.md. This change allows for more robust error handling, distinguishing between a non-existent file and an empty file, and handling other file read errors. Corresponding test cases in initCommand.test.ts have been updated and expanded to cover these new scenarios, including tests for existing content, empty files, and various read errors. No feedback is provided as there were no review comments to assess.

@gemini-cli gemini-cli bot added area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support! labels Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core Issues related to User Interface, OS Support, Core Functionality help wanted We will accept PRs from all issues marked as "help wanted". Thanks for your support!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A GEMINI.md file already exists but empty and never commited

1 participant