gemini-cli icon indicating copy to clipboard operation
gemini-cli copied to clipboard

fix(ui): Improve reliability of git branch watcher in footer

Open yoichiro opened this issue 2 months ago • 8 comments

TLDR

This PR fixes a bug where the git branch name in the footer would not appear or update if the git repository was initialized after the CLI had already started. It also improves the test suite for this feature to ensure its reliability.

This change resolves issue #10402.

Dive Deeper

The core of the issue was that the application only checked for a git repository at startup. The existing file watcher wasn't set up to detect the creation of the .git directory itself.

This PR introduces a more robust, two-step watching strategy:

  1. If no .git directory is found on startup, it watches the current working directory for the .git directory to be created.
  2. Once the .git directory appears, it switches its focus to watching the .git/HEAD file for any changes (i.e., branch switches or new commits).

To keep the code clean and reusable, this watching logic has been extracted into a new custom hook, useGitWatcher.

Additionally, the associated test suite for the useGitBranchName hook has been significantly improved:

  • Corrected an incomplete mock for fs/promises.
  • Enabled and refactored previously skipped tests that were prone to timeouts. The new tests use spies to verify the watcher's behavior directly, making them faster and more reliable.

Reviewer Test Plan

To validate this change, you can manually reproduce the original bug and confirm it's now fixed:

  1. Pull down this branch.
  2. Run npm run build.
  3. Create a new, empty directory and cd into it (e.g., mkdir /tmp/test-dir && cd /tmp/test-dir).
  4. Run the Gemini CLI from that directory (e.g., node /path/to/your/gemini-cli/bundle/cli.js).
  5. Confirm that no branch name is visible in the footer.
  6. In a separate terminal, cd into the same directory (/tmp/test-dir) and run git init.
  7. Verification: Check the running CLI instance. The footer should now correctly display the main (or master) branch name.
  8. (Optional) In the second terminal, create and checkout a new branch (git checkout -b test-branch).
  9. Verification: The CLI footer should update to test-branch.

Testing Matrix

🍏 🪟 🐧
npm run
npx
Docker
Podman - -
Seatbelt - -

Linked issues / bugs

Fixes #10402

yoichiro avatar Oct 02 '25 11:10 yoichiro

Summary of Changes

Hello @yoichiro, I'm Gemini Code Assist[^1]! 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 delivers a crucial reliability improvement for the CLI's user interface by ensuring the Git branch name displayed in the footer is always accurate and responsive. It introduces a sophisticated file watching mechanism that intelligently monitors for the presence and changes within a Git repository, effectively resolving a bug where the UI failed to update when a repository was initialized post-application startup. The changes also include a comprehensive overhaul of the related test suite, bolstering the stability and maintainability of this feature.

Highlights

  • Enhanced Git Branch Watching: Implemented a new useGitWatcher hook that provides a robust two-step strategy to detect Git repository initialization and branch changes, even if the repository is created after the CLI starts.
  • Improved Test Suite Reliability: Significantly refactored and enhanced the test suite for useGitBranchName, addressing mock incompleteness, enabling previously skipped tests, and utilizing spies for faster and more reliable verification of watcher behavior.
  • Bug Fix for Dynamic Git Repositories: Resolved an issue where the Git branch name in the footer would not appear or update if the .git directory was initialized or created after the CLI application had already launched.
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 :thumbsup: and :thumbsdown: 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.

[^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.

gemini-code-assist[bot] avatar Oct 02 '25 11:10 gemini-code-assist[bot]

/gemini review

yoichiro avatar Oct 02 '25 13:10 yoichiro

/gemini review

yoichiro avatar Oct 02 '25 20:10 yoichiro

/gemini review

yoichiro avatar Oct 02 '25 22:10 yoichiro

Be aware that we're not reviewing big PRs from external contributors for the next couple weeks.

scidomino avatar Oct 02 '25 22:10 scidomino

@scidomino OK, I understand it. Well, will the reviewing from external contributors be restarted after releasing v1.0?

yoichiro avatar Oct 02 '25 23:10 yoichiro

@scidomino OK, I understand it. Well, will the reviewing from external contributors be restarted after releasing v1.0?

That'a the plan!

scidomino avatar Oct 02 '25 23:10 scidomino

This pull request has been automatically marked as stale due to 60 days of inactivity. It will be closed in 14 days if no further activity occurs.

github-actions[bot] avatar Dec 08 '25 02:12 github-actions[bot]