fix: reject invalid and conflicting branch names#53
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances error handling for branch name validation in gimmegit by adding checks for invalid branch names and preventing silent reuse of existing branches. The changes catch invalid branch names earlier in the process and provide clearer error messages to users.
Key changes:
- Added validation using
git check-ref-formatto reject invalid branch names according to Git's rules - Added a check to prevent silently reusing existing branches when creating a new branch
- Improved cleanup by removing clone directory on errors
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/gimmegit/_models.py |
New file introducing is_valid_branch_name() validation function and Remote dataclass (relocated from _remote module) |
src/gimmegit/_cli.py |
Added branch name validation calls for new branches and base branches; improved error handling with directory cleanup on clone errors |
src/gimmegit/_status.py |
Updated imports to reference _models module instead of _remote |
tests/unit/test_context_no_token.py |
Added tests for invalid branch name validation scenarios |
tests/functional/test_git_errors.py |
Added functional test verifying error message when attempting to create an existing branch |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a couple of different bugs:
I've also made gimmegit output an error message if the base branch (specified with
-b <base-branch>is invalid according to Git's rules. This isn't strictly necessary, because gimmegit would already return an error when the branch couldn't be found. The new error is helpful because it's raised earlier in processing.For now, gimmegit doesn't directly check the validity of branch names specified using tree URLs. Invalid branch names won't be found, so will raise an error.