-
Notifications
You must be signed in to change notification settings - Fork 5.4k
fix(error): error handling for Git repositories with no commits (Fixes #3544) #3566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
All contributors have signed the CLA ✍️ ✅ |
I have read the CLA Document and I hereby sign the CLA |
@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. |
To use Codex here, create a Codex account and connect to github. |
@codex review. |
Codex Review: Didn't find any major issues. Delightful! About Codex in GitHubYour 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". |
- 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
…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
c63a805
to
ef26c4e
Compare
- 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
…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
ef26c4e
to
d1135fb
Compare
- 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
05f3cb3
to
fc9b5cd
Compare
Codex Review: Didn't find any major issues. Chef's kiss. ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. |
Ready for ReviewHi @bolinfest and team! All feedback has been addressed: Ready for review! 🙏 |
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()
incodex-core
that checks if a Git repository has at least one commit. This function is then used in two key places:codex-exec
): Added an early check that provides a clear, actionable error message when the repository has no commitsChanges Made:
codex-rs/core/src/git_info.rs
:git_repo_has_commits()
function that usesgit rev-parse --verify HEAD
to detect repositories without commitscodex-rs/exec/src/lib.rs
:--skip-git-repo-check
flag to allow bypassing this checkcodex-rs/mcp-server/src/codex_message_processor.rs
:codex-rs/tui/src/app.rs
:Error Messages:
The new error messages are clear and actionable:
"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."
"This Git repository has no commits. Codex requires at least one commit. Run: git add -A && git commit -m 'Initial commit'"
Testing:
git_repo_has_commits()
functionThis change improves the user experience by providing immediate, clear feedback when attempting to use Codex in an uninitialized Git repository.