Skip to content

fix: misleading error message when git is not installed - #190

Merged
404-Page-Found merged 1 commit into
404-PF:mainfrom
ZachDreamZ:fix/git-not-installed-error
Jul 4, 2026
Merged

fix: misleading error message when git is not installed#190
404-Page-Found merged 1 commit into
404-PF:mainfrom
ZachDreamZ:fix/git-not-installed-error

Conversation

@ZachDreamZ

@ZachDreamZ ZachDreamZ commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

The checkGitRepo() function was catching all execSync failures uniformly. When git is not installed, the error has code: 'ENOENT' with empty stderr, producing the misleading "Not a git repository" message instead of telling the user git is missing.

Added an ENOENT check so users see "git is not installed or not found on PATH" when git is missing. The existing fallback for non-git directories (stderr from git rev-parse --git-dir) is preserved.

Fixes #185

Summary by CodeRabbit

  • Bug Fixes
    • Improved git repository checks to return clearer error messages when Git is missing or unavailable on the system PATH.
    • Made repository validation errors more reliable by using the available error output when present, with a clearer fallback message for non-git directories.

The checkGitRepo() function was catching all execSync failures uniformly. When git is not installed, the error has code ENOENT with empty stderr, producing the misleading 'Not a git repository' message.

Added an ENOENT check so users see 'git is not installed or not found on PATH' instead. Non-git-directory errors still show the original stderr message from git rev-parse.

Fixes #185
@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 564e55c9-d4c8-4055-9476-78d388ada7ae

📥 Commits

Reviewing files that changed from the base of the PR and between c4a0195 and b95cd62.

📒 Files selected for processing (1)
  • src/git/diff.ts
📜 Recent review details
🧰 Additional context used
📓 Path-based instructions (2)
src/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

The project is ESM-only: use .js extensions in local imports and keep verbatimModuleSyntax-compatible TypeScript imports (for example, import type for type-only imports).

Files:

  • src/git/diff.ts
src/git/**/*.ts

📄 CodeRabbit inference engine (AGENTS.md)

Git operations should use execSync/spawnSync rather than simple-git; diff buffering must stay within the 100MB limit, and commits should use temp files via git commit -F.

Files:

  • src/git/diff.ts
🪛 ast-grep (0.44.0)
src/git/diff.ts

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execSync, spawnSync } from 'node:child_process';
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

🔇 Additional comments (1)
src/git/diff.ts (1)

20-31: LGTM!


📝 Walkthrough

Walkthrough

Updated the checkGitRepo function's error handling in src/git/diff.ts to detect when the git executable is missing (ENOENT) and throw a specific message, while retaining stderr-based error messages for other failures.

Changes

Error Handling Fix

Layer / File(s) Summary
Distinguish missing git from other repo errors
src/git/diff.ts
checkGitRepo now casts the caught error to NodeJS.ErrnoException, checks for err.code === 'ENOENT' to throw "git is not installed or not found on PATH", and otherwise derives stderr from the error for the existing fallback message.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A hop, a check, a git-dir quest,
No PATH found? I throw my best:
"Not installed!" I clearly say,
No more confusion leads astray.
🐇 Thump, thump — bug fixed today!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix for git-missing error handling and is concise.
Linked Issues check ✅ Passed The change matches issue #185 by handling ENOENT separately and preserving the not-a-repo fallback.
Out of Scope Changes check ✅ Passed The PR is narrowly scoped to checkGitRepo error handling and adds no unrelated changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@404-Page-Found 404-Page-Found 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.

Thanks, LGTM!

@404-Page-Found
404-Page-Found merged commit ca308c3 into 404-PF:main Jul 4, 2026
1 check passed
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.

[Bug] No graceful error handling when git is not installed

2 participants