Skip to content

fix: reject invalid and conflicting branch names#53

Merged
dwilding merged 8 commits intomainfrom
validate-branch
Dec 3, 2025
Merged

fix: reject invalid and conflicting branch names#53
dwilding merged 8 commits intomainfrom
validate-branch

Conversation

@dwilding
Copy link
Copy Markdown
Owner

@dwilding dwilding commented Dec 3, 2025

This PR fixes a couple of different bugs:

  • When cloning a repo and creating a branch, if the branch of the same name already existed, gimmegit would silently use the existing branch. Now, gimmegit outputs an error message.
  • When cloning a repo and creating a branch, if the branch name was invalid (according to Git's rules), gimmegit would crash. Now, gimmegit outputs an error message.

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.

@dwilding dwilding requested a review from Copilot December 3, 2025 12:19
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-format to 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.

Comment thread src/gimmegit/_cli.py Outdated
Comment thread src/gimmegit/_models.py
Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 3, 2025

@dwilding I've opened a new pull request, #54, to work on those changes. Once the pull request is ready, I'll request review from you.

@dwilding dwilding requested a review from Copilot December 3, 2025 12:44
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/gimmegit/_models.py
Comment thread src/gimmegit/_cli.py
@dwilding dwilding merged commit 5b1c6c1 into main Dec 3, 2025
2 checks passed
@dwilding dwilding deleted the validate-branch branch December 3, 2025 13:07
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.

3 participants