Skip to content

Conversation

SkinnnyJay
Copy link

What?

This PR fixes issue #3544 by adding proper error handling for Git repositories that have been initialized but contain no commits yet.

Why?

Previously, when users tried to use Codex in a Git repository with no commits, they would encounter vague error messages later in the process. This created a poor user experience and made it difficult to understand what was wrong.

How?

The fix introduces a new helper function git_repo_has_commits() in codex-core that checks if a Git repository has at least one commit. This function is then used in two key places:

  1. CLI (codex-exec): Added an early check that provides a clear, actionable error message when the repository has no commits
  2. MCP Server: Added the same validation during conversation creation to prevent task failures

Changes Made:

  • codex-rs/core/src/git_info.rs:

    • Added git_repo_has_commits() function that uses git rev-parse --verify HEAD to detect repositories without commits
    • Added comprehensive tests for both empty repositories and repositories with commits
  • codex-rs/exec/src/lib.rs:

    • Added validation check that shows clear error message: "This Git repository has no commits. Initialize it first: git add -A && git commit -m 'Initial commit'"
    • Respects the existing --skip-git-repo-check flag to allow bypassing this check
  • codex-rs/mcp-server/src/codex_message_processor.rs:

    • Added the same validation during conversation creation
    • Returns proper JSON-RPC error with actionable message
  • codex-rs/tui/src/app.rs:

    • Added test configuration to handle macOS seatbelt restrictions

Error Messages:

The new error messages are clear and actionable:

  • CLI: "This Git repository has no commits. Initialize it first:\n git add -A && git commit -m 'Initial commit'\nOr pass --skip-git-repo-check to bypass."
  • MCP: "This Git repository has no commits. Codex requires at least one commit. Run: git add -A && git commit -m 'Initial commit'"

Testing:

  • Added unit tests for the new git_repo_has_commits() function
  • Tests cover both empty repositories and repositories with commits
  • All existing tests continue to pass

This change improves the user experience by providing immediate, clear feedback when attempting to use Codex in an uninitialized Git repository.

Copy link

github-actions bot commented Sep 14, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@SkinnnyJay
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Sep 14, 2025
@SkinnnyJay SkinnnyJay changed the title Fix error handling for Git repositories with no commits (Fixes #3544) fix(error): error handling for Git repositories with no commits (Fixes #3544) Sep 14, 2025
@SkinnnyJay
Copy link
Author

SkinnnyJay commented Sep 18, 2025

@willwang-openai I notice you closed #3544. Does that mean I should close this PR to address the issue? Would you like to make sure I am following PR etiquette?

Happy to resolve any issues and address the feedback.

Copy link
Contributor

To use Codex here, create a Codex account and connect to github.

@SkinnnyJay
Copy link
Author

@codex review.

Copy link
Contributor

Codex Review: Didn't find any major issues. Delightful!

About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".

SkinnnyJay pushed a commit to SkinnnyJay/codex that referenced this pull request Sep 26, 2025
- Add git_repo_has_commits() function to check if git repo has commits
- Simplified implementation without redundant git repo check
- git rev-parse --verify HEAD handles both repo detection and commit verification
- Added comprehensive tests for empty repos, repos with commits, and non-git directories
- Addresses reviewer feedback to remove unnecessary validation code

Addresses: PR openai#3566 Comment 3 - Unnecessary git repo validation code
SkinnnyJay pushed a commit to SkinnnyJay/codex that referenced this pull request Sep 26, 2025
…calls

- Consolidate duplicate get_git_repo_root() calls into single call with reused result
- Add validation for git repositories with no commits in exec workflow
- Provide clear, actionable error message for empty git repositories
- Respects existing --skip-git-repo-check flag to bypass validation
- More efficient code structure with single git operation

Addresses: PR openai#3566 Comment 2 - Code consolidation request
Fixes: openai#3544 - Git repositories with no commits error handling
SkinnnyJay pushed a commit to SkinnnyJay/codex that referenced this pull request Sep 26, 2025
- Add git_repo_has_commits() function to check if git repo has commits
- Simplified implementation without redundant git repo check
- git rev-parse --verify HEAD handles both repo detection and commit verification
- Added comprehensive tests for empty repos, repos with commits, and non-git directories
- Addresses reviewer feedback to remove unnecessary validation code

Addresses: PR openai#3566 Comment 3 - Unnecessary git repo validation code
SkinnnyJay pushed a commit to SkinnnyJay/codex that referenced this pull request Sep 26, 2025
…calls

- Consolidate duplicate get_git_repo_root() calls into single call with reused result
- Add validation for git repositories with no commits in exec workflow
- Provide clear, actionable error message for empty git repositories
- Respects existing --skip-git-repo-check flag to bypass validation
- More efficient code structure with single git operation

Addresses: PR openai#3566 Comment 2 - Code consolidation request
Fixes: openai#3544 - Git repositories with no commits error handling
- Add git_repo_has_commits() function to detect repositories without commits
- Uses git rev-parse --verify HEAD to check for commits after confirming git repo
- Returns false for non-git directories and empty repositories
- Returns true for repositories with at least one commit
- Add comprehensive tests covering all scenarios:
  - Empty git repositories (no commits)
  - Repositories with commits
  - Non-git directories

Addresses: Issue openai#3544 - Need clear error for empty git repositories
- Add import for git_repo_has_commits function
- Add validation check after existing git repo check
- Provide clear, actionable error message for empty repositories
- Respects existing --skip-git-repo-check flag to bypass validation
- Error message guides users to initialize repository or bypass check

Addresses: Issue openai#3544 - CLI should show clear error for empty git repos
- Add imports for get_git_repo_root and git_repo_has_commits functions
- Add validation check during new conversation creation
- Provide clear JSON-RPC error message for empty git repositories
- Returns INVALID_REQUEST error code with actionable message
- Prevents vague task creation failures by catching issue early

Addresses: Issue openai#3544 - MCP server should show clear error for empty git repos
@SkinnnyJay SkinnnyJay force-pushed the bug-3544 branch 3 times, most recently from 05f3cb3 to fc9b5cd Compare September 26, 2025 07:06
Copy link
Contributor

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

@SkinnnyJay
Copy link
Author

Ready for Review

Hi @bolinfest and team! All feedback has been addressed:

Ready for review! 🙏

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