Skip to content

fix(core): remove invalid diff.external override - #29467

Merged
DavidAPierce merged 6 commits into
google-gemini:mainfrom
urielefrenvirtusa:b_561553835
Sep 25, 2026
Merged

DavidAPierce merged 6 commits into
google-gemini:mainfrom
urielefrenvirtusa:b_561553835

Conversation

@urielefrenvirtusa

Copy link
Copy Markdown
Contributor

Summary

Removes the invalid diff.external configuration override from ShellExecutionService and gitUtils.getSafeGitEnv(), resolving fatal cannot spawn : No such file or directory / error: cannot run : No such file or directory errors when executing Git diff commands in the execution sandbox.

Details

In PR #28792, environment overrides were added to isolate Git operations. Among these, diff.external was mapped to an empty string ("") under the assumption that an empty value would disable external diffing (similar to credential.helper = "" resetting helper lists).

However, in Git's internal diff engine (diff.c / run_external_diff), any non-NULL string configured for diff.external is treated as an executable command path. When differences are computed, Git attempts to invoke "", failing via execvp or CreateProcess with ENOENT.

Changes in this PR:

  • Removed ['diff.external', ''] from defaultGitOverrides in packages/core/src/services/shellExecutionService.ts.
  • Removed GIT_CONFIG_KEY_7: 'diff.external' and GIT_CONFIG_VALUE_7: '' from packages/core/src/utils/gitUtils.ts, adjusting GIT_CONFIG_COUNT from 8 to 7.
  • Updated test expectations in packages/core/src/services/shellExecutionService.test.ts.
  • Added comprehensive unit tests in packages/core/src/utils/gitUtils.test.ts covering safe environment variables, absence of diff.external, and end-to-end git diff operations on modified repositories and commits.

Related Issues

Fixes #28928

How to Validate

  1. Run the targeted unit test suite:
    npm test -w @google/gemini-cli-core -- src/utils/gitUtils.test.ts src/services/shellExecutionService.test.ts
  2. Verify all 91 tests in the suites pass.
  3. Manually test running git diff on a modified file with getSafeGitEnv:
    node -e "
    const { spawnSync } = require('child_process');
    const { getSafeGitEnv } = require('./packages/core/dist/src/utils/gitUtils.js');
    const res = spawnSync('git', ['diff'], { env: getSafeGitEnv() });
    console.log('Exit status:', res.status);
    "
    Confirm exit status is 0 without external diff spawn errors.

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

Configuring diff.external to an empty string ("") causes Git to attempt to
execute "" as an external diff tool, which fails with "cannot spawn : No such
file or directory" (Windows) or "error: cannot run : No such file or directory"
(POSIX) whenever differences exist between trees or in the working tree.

Removes diff.external from defaultGitOverrides in ShellExecutionService and
from getSafeGitEnv in gitUtils, restoring Git's built-in diff engine, and adds
comprehensive test coverage for gitUtils.

Fixes google-gemini#28928
@urielefrenvirtusa
urielefrenvirtusa requested a review from a team as a code owner September 23, 2026 19:10
@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 addresses a critical issue where Git operations failed due to an incorrectly configured 'diff.external' environment variable. By removing this invalid override, the system now correctly executes Git commands without attempting to invoke non-existent external diff tools. The changes include updates to core service configurations and the addition of robust unit tests to prevent future regressions in Git environment isolation.

Highlights

  • Removal of invalid Git configuration: Removed the 'diff.external' override from Git environment configurations, as setting it to an empty string causes Git to attempt to execute an invalid command.
  • Updated Git environment security settings: Adjusted 'GIT_CONFIG_COUNT' and removed the associated key-value pairs in 'gitUtils' and 'shellExecutionService' to reflect the removal of the external diff override.
  • Enhanced test coverage: Added comprehensive unit tests in 'gitUtils.test.ts' to verify safe environment variable handling and ensure 'git diff' operations function correctly in isolated environments.
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 the 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 counterproductive. 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. ↩

@github-actions github-actions Bot added the size/m A medium sized PR label Sep 23, 2026
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

📊 PR Size: size/L

  • Lines changed: 254
  • Additions: +246
  • Deletions: -8
  • Files changed: 4

@urielefrenvirtusa

Copy link
Copy Markdown
Contributor Author

/Gemini review

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

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.

Code Review

This pull request removes the diff.external override from the default Git security configuration across ShellExecutionService and gitUtils. This change prevents Git from attempting to execute an empty string as an external diff tool, which would otherwise fail. Additionally, a comprehensive test suite has been introduced in packages/core/src/utils/gitUtils.test.ts to validate the behavior of Git utility functions, including environment sanitization and repository detection. There are no review comments, and I have no feedback to provide.

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

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.

Code Review

This pull request removes the diff.external security override from the default Git environment configuration in both ShellExecutionService and gitUtils to prevent Git from failing when attempting to execute an empty string as an external diff tool. Additionally, the PR updates the associated unit tests to reflect the reduced count of security overrides and introduces a comprehensive new test suite for gitUtils.ts. There are no review comments to address.

@gemini-cli gemini-cli Bot added priority/p1 Important and should be addressed in the near term. area/core Issues related to User Interface, OS Support, Core Functionality labels Sep 23, 2026
…s CI

Use fs.realpath to resolve macOS symlinked /var paths and Windows 8.3 short
filename aliases in absolute git dir assertions.
@urielefrenvirtusa

Copy link
Copy Markdown
Contributor Author

/gemini review

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

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.

Code Review

This pull request removes the 'diff.external' security override from the default Git configuration environment variables in both shellExecutionService.ts and gitUtils.ts, updating the respective configuration counts. It also introduces a comprehensive test suite for gitUtils.ts. The review feedback suggests improving the test for filesystem errors by asserting that the existsSync spy was actually called, ensuring the error-handling path is correctly exercised.

Comment thread packages/core/src/utils/gitUtils.test.ts Outdated
Assert existsSyncSpy was called to ensure the error-handling path in
isGitRepository and findGitRoot is exercised.
@github-actions github-actions Bot added the size/l A large sized PR label Sep 24, 2026
@urielefrenvirtusa

Copy link
Copy Markdown
Contributor Author

/Gemini review

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

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.

Code Review

This pull request removes the diff.external override from the default Git security configurations to prevent execution failures during git diff operations, updating the environment configuration count from 8 to 7. It also introduces a new test suite for Git utilities. The reviewer feedback suggests replacing git init -b main with git init in the tests to ensure compatibility with Git versions older than 2.28.0.

Comment thread packages/core/src/utils/gitUtils.test.ts Outdated
Comment thread packages/core/src/utils/gitUtils.test.ts Outdated
Comment thread packages/core/src/utils/gitUtils.test.ts Outdated
Comment thread packages/core/src/utils/gitUtils.test.ts Outdated
…tibility

Avoid -b option in git init calls within gitUtils tests to ensure
compatibility with Git versions pre-2.28.0.
@urielefrenvirtusa

Copy link
Copy Markdown
Contributor Author

/Gemini review

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

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.

Code Review

This pull request removes the diff.external override from the default Git environment configuration in both ShellExecutionService and gitUtils to prevent Git execution failures. It also introduces a new comprehensive test suite in gitUtils.test.ts and updates existing tests to reflect the updated configuration count. I have no feedback to provide as there are no review comments.

@DavidAPierce
DavidAPierce added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
@DavidAPierce
DavidAPierce added this pull request to the merge queue Sep 25, 2026
Merged via the queue into google-gemini:main with commit 562f036 Sep 25, 2026
50 of 53 checks passed
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 priority/p1 Important and should be addressed in the near term. size/l A large sized PR size/m A medium sized PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Git command execution fails with cannot spawn : No such file or directory due to empty diff.external configuration

2 participants